mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-18 03:21:54 +00:00
buttons
This commit is contained in:
82
src/server/main/Elevators/Buttons.lua
Normal file
82
src/server/main/Elevators/Buttons.lua
Normal file
@@ -0,0 +1,82 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type GetButtons = {[string]: Instance}
|
||||
type ButtonTypes = {
|
||||
Landing: GetButtons,
|
||||
Car: GetButtons,
|
||||
Special: GetButtons,
|
||||
Unknown: GetButtons
|
||||
}
|
||||
|
||||
local ButtonTags = {}
|
||||
ButtonTags.__index = ButtonTags
|
||||
|
||||
function ButtonTags.constructor(Tags, Model)
|
||||
return setmetatable({
|
||||
Tags = Tags,
|
||||
Model = Model
|
||||
}, ButtonTags)
|
||||
end
|
||||
|
||||
function ButtonTags:Get()
|
||||
local Buttons: GetButtons = {}
|
||||
|
||||
for TagName: string, Inst: Instance in self.Tags do
|
||||
local Split = TagName:split('_')
|
||||
if Split[1] == self.Model and Split[2] == "ElevatorButton" then
|
||||
Buttons[TagName] = Inst
|
||||
end
|
||||
end
|
||||
return Buttons
|
||||
end
|
||||
|
||||
function ButtonTags:CreatePromptButtons()
|
||||
local ModelButtons = self:Get()
|
||||
local Buttons: ButtonTypes = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Unknown = {}
|
||||
}
|
||||
|
||||
for TagName: string, Inst: Instance in ModelButtons do
|
||||
local Attachment = Instance.new("Attachment") :: Attachment
|
||||
Attachment.Parent = Inst
|
||||
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
|
||||
Prompt.MaxActivationDistance = 3
|
||||
Prompt.Parent = Attachment
|
||||
|
||||
local Split = TagName:split('_')
|
||||
--CarButton = Model_ElevatorButton_1
|
||||
--LandingButton = Model_ElevatorButton_Floor_1_Up
|
||||
--SpecialButton = Model_ElevatorButton_Open
|
||||
local ButtonType = tonumber(Split[3]) and "CarButton" or (Split[3] == "Floor" and Split[4]:match('%d')) and "LandingButton" or Split[3] and "SpecialButton"
|
||||
|
||||
if ButtonType == "CarButton" then
|
||||
--ElevatorButton_1
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = Inst
|
||||
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == "LandingButton" then
|
||||
--ElevatorButton_Floor_1_Up
|
||||
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = Inst
|
||||
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
elseif ButtonType == "SpecialButton" then
|
||||
--ElevatorButton_Open
|
||||
|
||||
else
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
|
||||
print(`{self.Model}: created a ProximityPrompt @ "{Inst:GetFullName()}"`)
|
||||
end
|
||||
|
||||
return Buttons
|
||||
end
|
||||
|
||||
return ButtonTags
|
||||
Reference in New Issue
Block a user