mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
Call button fallback
This commit is contained in:
@@ -14,6 +14,7 @@ local PromptModule = require(Main:WaitForChild("Map"):WaitForChild("Prompts"))
|
|||||||
local Tags = require(Load:WaitForChild("Tags"))
|
local Tags = require(Load:WaitForChild("Tags"))
|
||||||
|
|
||||||
type FloorButtonActivatedCallback = (ButtonFloor: number) -> ()
|
type FloorButtonActivatedCallback = (ButtonFloor: number) -> ()
|
||||||
|
type FloorButtonActivatedFallback = FloorButtonActivatedCallback
|
||||||
type StopButtonActivatedCallback = (Toggled: SpecialButtonToggle) -> ()
|
type StopButtonActivatedCallback = (Toggled: SpecialButtonToggle) -> ()
|
||||||
|
|
||||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||||
@@ -21,8 +22,8 @@ type Impl_Constructor = {
|
|||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
CarButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback) -> (),
|
CarButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedFallback) -> (),
|
||||||
LandingButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback) -> (),
|
LandingButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedFallback) -> (),
|
||||||
SpecialButton: (self: ClassConstructor, ButtonName: Enums.SpecialButtonValues, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: StopButtonActivatedCallback) -> (),
|
SpecialButton: (self: ClassConstructor, ButtonName: Enums.SpecialButtonValues, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: StopButtonActivatedCallback) -> (),
|
||||||
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
|
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
|
||||||
__DeactivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
|
__DeactivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
|
||||||
@@ -76,7 +77,7 @@ function ButtonFunctions.constructor(ElevatorAttributes, ElevatorEvents, Elevato
|
|||||||
}, ButtonFunctions)
|
}, ButtonFunctions)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
|
function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback, Fallback)
|
||||||
local DecodedCarFloorTag = Tags.Decoders.CarTag(ButtonID)
|
local DecodedCarFloorTag = Tags.Decoders.CarTag(ButtonID)
|
||||||
|
|
||||||
if DecodedCarFloorTag then
|
if DecodedCarFloorTag then
|
||||||
@@ -87,6 +88,8 @@ function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
|
|||||||
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
|
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
|
||||||
|
|
||||||
if DecodedCarFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
|
if DecodedCarFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
|
||||||
|
Fallback(DecodedCarFloorTag)
|
||||||
|
|
||||||
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
|
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
|
||||||
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
|
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
|
||||||
end)
|
end)
|
||||||
@@ -97,7 +100,7 @@ function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback)
|
function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback, Fallback)
|
||||||
local DecodedHallFloorTag = Tags.Decoders.HallTag(ButtonID)
|
local DecodedHallFloorTag = Tags.Decoders.HallTag(ButtonID)
|
||||||
|
|
||||||
if DecodedHallFloorTag then
|
if DecodedHallFloorTag then
|
||||||
@@ -108,6 +111,8 @@ function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback)
|
|||||||
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
|
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
|
||||||
|
|
||||||
if DecodedHallFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
|
if DecodedHallFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
|
||||||
|
Fallback(DecodedHallFloorTag)
|
||||||
|
|
||||||
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
|
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
|
||||||
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
|
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type Impl_Static_Props = {
|
|||||||
Door2Stopped_X: Vector3,
|
Door2Stopped_X: Vector3,
|
||||||
ElevatorDoorTime: number,
|
ElevatorDoorTime: number,
|
||||||
ElevatorDoorStyle: Enum.EasingStyle,
|
ElevatorDoorStyle: Enum.EasingStyle,
|
||||||
__DontLeakMemory: RBXScriptConnection?,
|
__DoorSensors: RBXScriptConnection?,
|
||||||
|
|
||||||
Attributes: {} & RelayAttributes
|
Attributes: {} & RelayAttributes
|
||||||
}
|
}
|
||||||
@@ -112,9 +112,8 @@ local init_floors_closed: FloorDoors = {}
|
|||||||
local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
|
local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
|
||||||
local Door2Tween_Floor: Tween?
|
local Door2Tween_Floor: Tween?
|
||||||
local Door1Tween_Floor: Tween?
|
local Door1Tween_Floor: Tween?
|
||||||
local FloorDoor1 = FloorDoors[1] :: BasePart?
|
local FloorDoor1 = FloorDoors[1] :: BasePart?
|
||||||
local FloorDoor2 = FloorDoors[2] :: BasePart?
|
local FloorDoor2 = FloorDoors[2] :: BasePart?
|
||||||
|
|
||||||
local FloorDoor1_P = FloorDoor1 and FloorDoor1.Position
|
local FloorDoor1_P = FloorDoor1 and FloorDoor1.Position
|
||||||
local FloorDoor2_P = FloorDoor2 and FloorDoor2.Position
|
local FloorDoor2_P = FloorDoor2 and FloorDoor2.Position
|
||||||
|
|
||||||
@@ -173,7 +172,7 @@ local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, openi
|
|||||||
return Door1Tween_Floor, Door2Tween_Floor
|
return Door1Tween_Floor, Door2Tween_Floor
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
|
local function ElevatorDoorsAnimationAsync(self: ClassConstructor, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
|
||||||
--Roblox physics will freak out
|
--Roblox physics will freak out
|
||||||
self.ElevatorDoor1.CanCollide = false
|
self.ElevatorDoor1.CanCollide = false
|
||||||
self.ElevatorDoor2.CanCollide = false
|
self.ElevatorDoor2.CanCollide = false
|
||||||
@@ -217,10 +216,10 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
|||||||
Enum.EasingDirection.Out
|
Enum.EasingDirection.Out
|
||||||
))
|
))
|
||||||
|
|
||||||
if Doors.__DontLeakMemory and Doors.__DontLeakMemory.Connected then
|
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
|
||||||
Doors.__DontLeakMemory:Disconnect()
|
Doors.__DoorSensors:Disconnect()
|
||||||
end
|
end
|
||||||
Doors.__DontLeakMemory = self:__DetectSensorHit(Door1Tween, Door2Tween)
|
Doors.__DoorSensors = self:__DetectSensorHit(Door1Tween, Door2Tween)
|
||||||
|
|
||||||
--Door clicking noise
|
--Door clicking noise
|
||||||
task.delay(Doors.ElevatorDoorTime-.90, function()
|
task.delay(Doors.ElevatorDoorTime-.90, function()
|
||||||
@@ -230,6 +229,12 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
if Door2Tween then
|
||||||
|
Door2Tween.Completed:Wait()
|
||||||
|
elseif Door1Tween then
|
||||||
|
Door1Tween.Completed:Wait()
|
||||||
|
end
|
||||||
|
|
||||||
return Door1Tween, Door2Tween
|
return Door1Tween, Door2Tween
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -263,7 +268,7 @@ function Doors:__DetectSensorHit(DoorTween1, DoorTween2)
|
|||||||
DoorTween1:Pause()
|
DoorTween1:Pause()
|
||||||
DoorTween2:Pause()
|
DoorTween2:Pause()
|
||||||
task.wait(1) --elevators irl have this delay
|
task.wait(1) --elevators irl have this delay
|
||||||
ElevatorDoorsAnimation(self, true, true)
|
ElevatorDoorsAnimationAsync(self, true, true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -290,21 +295,15 @@ function Doors:ToggleElevatorDoorsAsync(opening, floor)
|
|||||||
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
||||||
end
|
end
|
||||||
|
|
||||||
local Door2Tween, Door1Tween = ElevatorDoorsAnimation(self, opening)
|
local _Door2Tween, _Door1Tween = ElevatorDoorsAnimationAsync(self, opening)
|
||||||
|
|
||||||
if Door2Tween then
|
Attributes.Relay.Open.Value = opening ~= nil and opening
|
||||||
Door2Tween.Completed:Wait()
|
|
||||||
Attributes.Relay.Open.Value = opening ~= nil and opening or false
|
|
||||||
elseif Door1Tween then
|
|
||||||
Door1Tween.Completed:Wait()
|
|
||||||
Attributes.Relay.Open.Value = opening ~= nil and opening or false
|
|
||||||
end
|
|
||||||
|
|
||||||
self.ElevatorDoor1.CanCollide = true
|
self.ElevatorDoor1.CanCollide = true
|
||||||
self.ElevatorDoor2.CanCollide = true
|
self.ElevatorDoor2.CanCollide = true
|
||||||
|
|
||||||
if Doors.__DontLeakMemory and Doors.__DontLeakMemory.Connected then
|
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
|
||||||
Doors.__DontLeakMemory:Disconnect()
|
Doors.__DoorSensors:Disconnect()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function Relay:__Ready()
|
|||||||
if self.ElevatorAttributes.Relay.Ready.Value then
|
if self.ElevatorAttributes.Relay.Ready.Value then
|
||||||
self.BoxAlignPosition.Position = Vector3.new(
|
self.BoxAlignPosition.Position = Vector3.new(
|
||||||
self.ElevatorBox.Position.X,
|
self.ElevatorBox.Position.X,
|
||||||
self.LevelingModule.Leveling[self.RelayAlgorthm.__FloorQueue[1]],
|
self.ElevatorAttributes.Relay.GoalYLevel.Value,
|
||||||
self.ElevatorBox.Position.Z
|
self.ElevatorBox.Position.Z
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -172,8 +172,9 @@ Elevator.Attributes.CurrentFloor.Value = 1
|
|||||||
Elevator.Attributes.Moving.Value = false
|
Elevator.Attributes.Moving.Value = false
|
||||||
Elevator.Attributes.GoingUp.Value = false
|
Elevator.Attributes.GoingUp.Value = false
|
||||||
|
|
||||||
Elevator.Attributes.Relay.Goal.Value = 1
|
Elevator.Attributes.Relay.Goal.Value = 1
|
||||||
Elevator.Attributes.Relay.Ready.Value = false
|
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
|
||||||
|
Elevator.Attributes.Relay.Ready.Value = false
|
||||||
|
|
||||||
local Attributes = Elevator.Attributes
|
local Attributes = Elevator.Attributes
|
||||||
|
|
||||||
@@ -183,16 +184,6 @@ local function ElevatorGoingUpDirection(Floor: number, RequestedFloor: number):
|
|||||||
return -Floor+RequestedFloor>0 --Simplified equation for less computation
|
return -Floor+RequestedFloor>0 --Simplified equation for less computation
|
||||||
end
|
end
|
||||||
|
|
||||||
local function OpenElevatorDoorsSafe(self: ClassConstructor)
|
|
||||||
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.Ready=",Attributes.Relay.Ready.Value)
|
|
||||||
|
|
||||||
if not Doors.Attributes.Relay.Open.Value and not Attributes.Relay.Ready.Value then
|
|
||||||
task.spawn(function()
|
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonTree: Tags.ButtonPropertiesSafe)
|
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonTree: Tags.ButtonPropertiesSafe)
|
||||||
ButtonTree.Prompt.Enabled = false
|
ButtonTree.Prompt.Enabled = false
|
||||||
local Some = self:RequestLevel(ButtonFloor)
|
local Some = self:RequestLevel(ButtonFloor)
|
||||||
@@ -204,10 +195,6 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
|
|||||||
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Relay.Goal.Value == ButtonFloor then
|
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Relay.Goal.Value == ButtonFloor then
|
||||||
FloorTracker:Disconnect()
|
FloorTracker:Disconnect()
|
||||||
|
|
||||||
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
|
|
||||||
--then open the doors
|
|
||||||
OpenElevatorDoorsSafe(self)
|
|
||||||
|
|
||||||
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
||||||
ButtonTree.Prompt.Enabled = true
|
ButtonTree.Prompt.Enabled = true
|
||||||
end
|
end
|
||||||
@@ -218,15 +205,31 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
|
||||||
|
--then open the doors
|
||||||
|
local function OpenElevatorDoorsSafe(self: ClassConstructor)
|
||||||
|
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.Ready=",Attributes.Relay.Ready.Value)
|
||||||
|
|
||||||
|
if not Doors.Attributes.Relay.Open.Value and not Attributes.Relay.Ready.Value then
|
||||||
|
task.spawn(function()
|
||||||
|
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--Special cases inbound
|
--Special cases inbound
|
||||||
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonID: string, ButtonTree: Tags.ButtonPropertiesSafe)
|
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonID: string, ButtonTree: Tags.ButtonPropertiesSafe)
|
||||||
if ButtonNameType == Enums.ButtonTree.Car then
|
if ButtonNameType == Enums.ButtonTree.Car then
|
||||||
self.ButtonsConstructor:CarButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
self.ButtonsConstructor:CarButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
||||||
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
||||||
|
end, function(_ButtonFloor: number)
|
||||||
|
OpenElevatorDoorsSafe(self)
|
||||||
end)
|
end)
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Landing then
|
elseif ButtonNameType == Enums.ButtonTree.Landing then
|
||||||
self.ButtonsConstructor:LandingButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
self.ButtonsConstructor:LandingButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
||||||
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
||||||
|
end, function(_ButtonFloor: number)
|
||||||
|
OpenElevatorDoorsSafe(self)
|
||||||
end)
|
end)
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Special then
|
elseif ButtonNameType == Enums.ButtonTree.Special then
|
||||||
if Elevator.Name == Enums.Elevator.Otis1960 then
|
if Elevator.Name == Enums.Elevator.Otis1960 then
|
||||||
@@ -250,7 +253,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
|||||||
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
||||||
|
|
||||||
self.LanternsConstructor:Reset()
|
self.LanternsConstructor:Reset()
|
||||||
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
|
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), Attributes.Relay.GoalYLevel.Value)
|
||||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -284,10 +287,8 @@ local function ElevatorInit(self: ClassConstructor)
|
|||||||
|
|
||||||
--Open the elevator doors on server start
|
--Open the elevator doors on server start
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||||
|
|
||||||
--Some hacks
|
--Some hacks
|
||||||
Doors.Attributes.Relay.Open.Value = true
|
Doors.Attributes.Relay.Open.Value = true
|
||||||
self:RequestLevel(1)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -333,11 +334,11 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|||||||
self.BoxAlignPosition,
|
self.BoxAlignPosition,
|
||||||
self.BoxAlignOrientation = ElevatorMover(
|
self.BoxAlignOrientation = ElevatorMover(
|
||||||
self.ElevatorBox_1960,
|
self.ElevatorBox_1960,
|
||||||
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
|
Vector3.new(self.ElevatorBox_1960.Position.X, Elevator.Attributes.Relay.GoalYLevel.Value, self.ElevatorBox_1960.Position.Z),
|
||||||
Elevator.Responsiveness,
|
Elevator.Responsiveness,
|
||||||
Elevator.MaxVelocity
|
Elevator.MaxVelocity
|
||||||
)
|
)
|
||||||
|
|
||||||
self.RelayAlgorithmConstructor = RelayAlgorithm.constructor(self.BoxAlignPosition, Attributes, Doors.Attributes)
|
self.RelayAlgorithmConstructor = RelayAlgorithm.constructor(self.BoxAlignPosition, Attributes, Doors.Attributes)
|
||||||
self.RelayConstructor = Relay.constructor(
|
self.RelayConstructor = Relay.constructor(
|
||||||
self.RelayAlgorithmConstructor,
|
self.RelayAlgorithmConstructor,
|
||||||
@@ -364,8 +365,8 @@ function Elevator:Leveled(RequestedLevel)
|
|||||||
Attributes.Moving.Value = false
|
Attributes.Moving.Value = false
|
||||||
Attributes.CurrentFloor.Value = RequestedLevel
|
Attributes.CurrentFloor.Value = RequestedLevel
|
||||||
self.BoxAlignPosition.MaxVelocity = 0
|
self.BoxAlignPosition.MaxVelocity = 0
|
||||||
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
|
||||||
|
|
||||||
|
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
||||||
task.wait(Elevator.QueueWaitTime)
|
task.wait(Elevator.QueueWaitTime)
|
||||||
|
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||||
@@ -393,7 +394,9 @@ function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
||||||
if ElevatorPositionY<=LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value-1] then
|
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value-1]
|
||||||
|
|
||||||
|
if NextLevelBetweenFloors and ElevatorPositionY<=NextLevelBetweenFloors then
|
||||||
Attributes.CurrentFloor.Value-=1
|
Attributes.CurrentFloor.Value-=1
|
||||||
|
|
||||||
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
||||||
@@ -411,14 +414,14 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
|||||||
self.MOConstructor:UpdateCFrame()
|
self.MOConstructor:UpdateCFrame()
|
||||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||||
|
|
||||||
local Delta = 0
|
local Delta = 0
|
||||||
local DoorsOpeningEvent = false
|
local DoorsOpeningDebounce = false
|
||||||
|
|
||||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
|
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
|
||||||
Delta+=1
|
Delta+=1
|
||||||
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||||
|
|
||||||
Attributes.Moving.Value = true
|
Attributes.Moving.Value = true
|
||||||
Attributes.Relay.Goal.Value = FloorGoal
|
Attributes.Relay.Goal.Value = FloorGoal
|
||||||
|
|
||||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||||
@@ -430,14 +433,14 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
|||||||
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
||||||
|
|
||||||
--Kill the connection
|
--Kill the connection
|
||||||
if GoingUp then
|
if Attributes.GoingUp.Value then
|
||||||
self:FloorPassingUp(ElevatorPositionY, FloorGoal)
|
self:FloorPassingUp(ElevatorPositionY, FloorGoal)
|
||||||
|
|
||||||
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
|
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
|
||||||
self:Leveling(FloorGoal)
|
self:Leveling(FloorGoal)
|
||||||
|
|
||||||
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||||
DoorsOpeningEvent = true
|
DoorsOpeningDebounce = true
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
|
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -451,8 +454,8 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
|||||||
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
|
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
|
||||||
self:Leveling(FloorGoal)
|
self:Leveling(FloorGoal)
|
||||||
|
|
||||||
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||||
DoorsOpeningEvent = true
|
DoorsOpeningDebounce = true
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
|
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -480,18 +483,18 @@ end
|
|||||||
function Elevator:RequestLevel(RequestedLevel)
|
function Elevator:RequestLevel(RequestedLevel)
|
||||||
local GoalFloor_Y: number? = LevelingModule.Leveling[RequestedLevel]
|
local GoalFloor_Y: number? = LevelingModule.Leveling[RequestedLevel]
|
||||||
|
|
||||||
if GoalFloor_Y --[[and RequestedLevel ~= Attributes.CurrentFloor.Value]] then
|
if GoalFloor_Y and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||||
|
|
||||||
if Proceeding then
|
if Proceeding then
|
||||||
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
|
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
else
|
else
|
||||||
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return Elevator
|
return Elevator
|
||||||
Reference in New Issue
Block a user