work on rope math

This commit is contained in:
2024-03-26 01:05:37 -04:00
parent 727f296a60
commit f0f80407a3
5 changed files with 203 additions and 70 deletions

View File

@@ -4,8 +4,10 @@
local Elevators = script.Parent
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
local TagsModule = require(RS:WaitForChild("Tags"))
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
local RS: RunService = game:GetService("RunService")
local TagsModule = require(Storage:WaitForChild("Tags"))
local Leveling = require(script:WaitForChild("Leveling"))
local Doors = require(script:WaitForChild("Doors"))
@@ -21,29 +23,95 @@ type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
MoveFloors: (self: ClassConstructor, Level: number) -> (),
GoToLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
__MoveFloors: (self: ClassConstructor, Level: number) -> (),
GoToLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
} & Impl_Static_Props
type Impl_Static_Props = {
Moving: boolean
}
type Constructor_Fun = (Tags: Tags) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorBox_1960: BasePart,
ElevatorBox: BasePart,
ElevatorDoor1: BasePart,
ElevatorDoor2: BasePart,
ElevatorDoorSensor: Folder,
ProximityButtons: {Instance},
BoxAttachment: Attachment,
BoxAlignPosition: AlignPosition,
Tags: Tags,
ElevatorBox_1960: BasePart,
ElevatorBox: BasePart,
ElevatorDoor1: BasePart,
ElevatorDoor2: BasePart,
ElevatorDoorSensor: Folder,
ProximityButtons: {Instance},
BoxAttachment: Attachment,
BoxAlignPosition: AlignPosition,
BoxAlignOrientation: AlignOrientation,
ElevatorDoors: Doors.DoorConstructor,
ElevatorDoors: Doors.DoorConstructor,
}
local Otis1960 = {} :: Impl_Constructor
Otis1960.__index = Otis1960
Otis1960.Moving = false
local function ButtonPress(Button: BasePart, Activated: boolean)
task.spawn(function()
local Glass = Button:FindFirstChild("Glass") :: BasePart
if Glass then
Glass.Position+=Glass.CFrame.LookVector/50
if not Activated then
Glass.Material = Enum.Material.Neon
Glass.Color = Color3.fromRGB(180,0,0)
Glass.Transparency = 0
end
end
Button.Position+=Glass.CFrame.LookVector/50
task.wait(.30)
if Glass then
Glass.Position-=Glass.CFrame.LookVector/50
end
Button.Position-=Glass.CFrame.LookVector/50
end)
end
local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonType: Enums.EnumValue)
for ButtonNameType, ButtonList in ButtonsConstructor.Buttons do
for ButtonName, ButtonTree in ButtonList do
if ButtonTree.Prompt then
if ButtonTree.Inst then
if ButtonNameType == Enums.ButtonTree.Car then
local DecodedFloor = ButtonsConstructor:DecodeCarTag(ButtonName)
ButtonsConstructor:HookPromptButtonsGroup(ButtonTree.Prompt, ButtonTree.Inst, function(_Player: Player)
if DecodedFloor then
ButtonTree.Prompt.Enabled = false
ButtonPress(ButtonTree.Inst, false)
self:GoToLevel(DecodedFloor)
end
end)
elseif ButtonNameType == Enums.ButtonTree.Special then
elseif ButtonNameType == Enums.ButtonTree.Landing then
ButtonsConstructor:HookPromptButtonsGroup(ButtonTree.Prompt, ButtonTree.Inst, function(_Player: Player)
ButtonTree.Prompt.Enabled = false
ButtonPress(ButtonTree.Inst, false)
end)
end
else
warn(`{ButtonTree} is missing the field "Inst"`)
end
else
warn(`{ButtonTree} is missing the field "Prompt"`)
end
end
end
end
function Otis1960.constructor(Tags)
local self = {} :: Constructor_Return_Props
self.Tags = Tags
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: BasePart
self.ElevatorBox = Tags.ElevatorMover_1960 :: BasePart
self.ElevatorDoor1 = Tags.ElevatorDoor_1960_1 :: BasePart
@@ -55,23 +123,40 @@ function Otis1960.constructor(Tags)
self.ElevatorDoors = Doors.constructor(self.ElevatorBox, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
--Buttons
local Buttons = ButtonTags.constructor(Tags, Enums.Elevators.Otis1960)
local Otis1960_Buttons = Buttons:CreatePromptButtons()
local ButtonsConstructor = ButtonTags.constructor(Tags, Enums.Elevator.Otis1960)
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
local ClassConstructor = setmetatable(self, Otis1960)
HookButtons(ClassConstructor, ButtonsConstructor, Enums.ButtonTree.Car)
print("[DEBUG] Otis1960 Buttons=", Otis1960_Buttons)
print("🔝 Otis1960 initialized and ready")
return setmetatable(self, Otis1960)
return ClassConstructor
end
function Otis1960:MoveFloors(Level)
local BiggestRopeLength = Leveling[#Leveling]-2
function Otis1960:__MoveFloors(Level)
local ElevatorBoxCurrentPos = self.ElevatorBox.Position
local RopeConnection = RS.Heartbeat:Connect(function(_dt)
local Ropes = self.Tags["1960_ElevatorPulleyRope"] :: {Instance}
for i: number = 1, #Ropes do
(Ropes[i] :: RopeConstraint).Length = (BiggestRopeLength-self.ElevatorBox.Position.Y)*10
print((Ropes[i] :: RopeConstraint).Length)
end
end)
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, Level, ElevatorBoxCurrentPos.Z)
end
function Otis1960:GoToLevel(RequestedLevel)
local level: number = Leveling[RequestedLevel]
if level then
self:MoveFloors(level)
if level and level ~= 0 then
self:__MoveFloors(level)
else
warn(`[{Enums.Elevator.Otis1960}]: landing out of range! requested landing: {tostring(RequestedLevel)}`)
end
end