mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-18 03:21:54 +00:00
work on rope math
This commit is contained in:
@@ -7,31 +7,23 @@ local Elevators = script.Parent
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type HumanoidRootPart = BasePart
|
||||
type PromptCallback = (Player: Player) -> ()
|
||||
|
||||
type GetButtons = {[string]: Instance}
|
||||
type ButtonProperties = {
|
||||
Inst: Instance?,
|
||||
Prompt: ProximityPrompt?
|
||||
}
|
||||
type ButtonsTree = {
|
||||
Landing: ButtonProperties,
|
||||
Car: ButtonProperties,
|
||||
Special: ButtonProperties,
|
||||
Relays: ButtonProperties,
|
||||
Unknown: ButtonProperties
|
||||
}
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Get: (self: ClassConstructor) -> GetButtons,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> ButtonsTree,
|
||||
HookPromptButtonsGroup: (self: ClassConstructor) -> ()
|
||||
DecodeCarTag: (self: ClassConstructor, FloorTag: string) -> number?,
|
||||
Get: (self: ClassConstructor) -> GetButtons,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> ButtonsTree,
|
||||
HookPromptButtonsGroup: (self: ClassConstructor, Prompt: ProximityPrompt, Inst: BasePart, PromptCallback: PromptCallback) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
@@ -45,6 +37,19 @@ type Constructor_Return_Props = {
|
||||
Buttons: ButtonsTree
|
||||
}
|
||||
|
||||
export type ButtonsTree = {
|
||||
Landing: ButtonProperties,
|
||||
Car: ButtonProperties,
|
||||
Special: ButtonProperties,
|
||||
Relays: ButtonProperties
|
||||
}
|
||||
export type ButtonProperties = {
|
||||
Inst: Instance?,
|
||||
Prompt: ProximityPrompt?,
|
||||
Attachment: Attachment?
|
||||
}
|
||||
export type ButtonsConstructor = ClassConstructor
|
||||
|
||||
local ButtonsModule = {} :: Impl_Constructor
|
||||
ButtonsModule.__index = ButtonsModule
|
||||
|
||||
@@ -56,14 +61,18 @@ function ButtonsModule.constructor(Tags, Model)
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Relays = {},
|
||||
Unknown = {}
|
||||
Relays = {}
|
||||
}
|
||||
}, ButtonsModule)
|
||||
end
|
||||
|
||||
--Button parsing
|
||||
|
||||
function ButtonsModule:DecodeCarTag(FloorTag)
|
||||
local Match = FloorTag:match('%d+$')
|
||||
return Match and tonumber(Match)
|
||||
end
|
||||
|
||||
function ButtonsModule:Get()
|
||||
local Buttons: GetButtons = {}
|
||||
|
||||
@@ -94,59 +103,74 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Attachment.Parent = Inst
|
||||
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
|
||||
Prompt.MaxActivationDistance = 3
|
||||
Prompt.HoldDuration = .30
|
||||
Prompt.Parent = Attachment
|
||||
|
||||
local Split = TagName:split('_')
|
||||
local ButtonType = if tonumber(Split[3]) then
|
||||
Enums.Buttons.Car
|
||||
Enums.Button.Car
|
||||
elseif Split[3] == "Floor" and Split[4]:match('%d') then
|
||||
Enums.Buttons.Landing
|
||||
Enums.Button.Landing
|
||||
elseif Split[2] == "ElevatorButton" then
|
||||
Enums.Buttons.Special
|
||||
Enums.Button.Special
|
||||
elseif Split[2] == "RelayButton" then
|
||||
Enums.Buttons.Relay
|
||||
Enums.Button.Relay
|
||||
else
|
||||
nil
|
||||
|
||||
if ButtonType == Enums.Buttons.Car then
|
||||
if ButtonType == Enums.Button.Car then
|
||||
--ElevatorButton_1
|
||||
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
|
||||
self.Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == Enums.Buttons.Landing then
|
||||
elseif ButtonType == Enums.Button.Landing then
|
||||
--ElevatorButton_Floor_1_Up
|
||||
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
|
||||
self.Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
elseif ButtonType == Enums.Buttons.Special then
|
||||
elseif ButtonType == Enums.Button.Special then
|
||||
--ElevatorButton_Open
|
||||
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
|
||||
self.Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == Enums.Buttons.Relay then
|
||||
elseif ButtonType == Enums.Button.Relay then
|
||||
--RelayButton_F1
|
||||
|
||||
Attachment.Position-=Vector3.new(.1,.3,0)
|
||||
if self.Model == Enums.Elevator.Otis1960 then --This is bad...
|
||||
Attachment.Position-=Vector3.new(.1,.3,0)
|
||||
end
|
||||
|
||||
Prompt.MaxActivationDistance = 4
|
||||
Prompt.Exclusivity = Enum.ProximityPromptExclusivity.OneGlobally --why does this not work...
|
||||
Prompt.ActionText = `Relay {tostring(Split[3])}`
|
||||
Prompt.ObjectText = "Activate"
|
||||
|
||||
self.Buttons.Relays[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment
|
||||
}
|
||||
Prompt.ActionText = `Relay {tostring(Split[3])}`
|
||||
Prompt.ObjectText = "Activate"
|
||||
else
|
||||
Attachment:Destroy()
|
||||
Prompt:Destroy()
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
|
||||
@@ -156,8 +180,19 @@ function ButtonsModule:CreatePromptButtons()
|
||||
return self.Buttons
|
||||
end
|
||||
|
||||
function ButtonsModule:HookPromptButtonsGroup()
|
||||
function ButtonsModule:HookPromptButtonsGroup(Prompt, Inst, PromptCallback)
|
||||
Prompt.Triggered:Connect(function(Player)
|
||||
local PlayerCharacter = Player.Character
|
||||
local Root = PlayerCharacter and PlayerCharacter:FindFirstChild("HumanoidRootPart") :: HumanoidRootPart?
|
||||
|
||||
if Root then
|
||||
if (Root.Position-Inst.Position).Magnitude<=Prompt.MaxActivationDistance+1 then
|
||||
PromptCallback(Player)
|
||||
else
|
||||
warn(`{Player.Name}, {Player.UserId} activated a prompt without being in range of MaxActivationDistance.`)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return ButtonsModule
|
||||
Reference in New Issue
Block a user