Proximity prompt and work on elevator

This commit is contained in:
2024-03-10 21:41:10 -04:00
parent 3e28667b13
commit df86e6efb6
15 changed files with 327 additions and 177 deletions

View File

@@ -0,0 +1,87 @@
--!optimize 2
--!native
--!strict
local Elevators = script.Parent
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
local TagsModule = require(RS:WaitForChild("Tags"))
local Leveling = require(script:WaitForChild("Leveling"))
local Doors = require(script:WaitForChild("Doors"))
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
type Tags = TagsModule.ExportedTags
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
MoveFloors: (self: ClassConstructor, Level: number) -> (),
GoToLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
}
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,
BoxAlignOrientation: AlignOrientation,
ElevatorDoors: BasePart,
}
local Otis1960 = {} :: Impl_Constructor
Otis1960.__index = Otis1960
local function PromptButtons(self: Constructor_Return_Props)
for i: number = 1, #self.ProximityButtons do
local Button = self.ProximityButtons[i]
local Attachment = Instance.new("Attachment") :: Attachment
Attachment.Parent = Button
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
Prompt.MaxActivationDistance = 3
Prompt.Parent = Attachment
print(`Created a ProximityPrompt @ "{Button:GetFullName()}"`)
end
end
function Otis1960.constructor(Tags)
local self = {} :: Constructor_Return_Props
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: BasePart
self.ElevatorBox = Tags.ElevatorMover_1960 :: BasePart
self.ElevatorDoor1 = Tags.ElevatorDoor_1960_1 :: BasePart
self.ElevatorDoor2 = Tags.ElevatorDoor_1960_2 :: BasePart
self.ElevatorDoorSensor = Tags.ElevatorDoor_Sensor_1960 :: Folder
self.ProximityButtons = Tags.ProximityElevatorButton :: {Instance}
self.BoxAttachment, self.BoxAlignPosition, self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position)
self.ElevatorDoors = Doors.constructor(self.ElevatorBox, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
PromptButtons(self)
print("Otis1960 initialized and ready")
return setmetatable(self, Otis1960)
end
function Otis1960:MoveFloors(Level)
local ElevatorBoxCurrentPos = self.ElevatorBox.Position
--Its gonna use raycasting inside of the shaft to detect when its near and when to stop
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)
end
end
return Otis1960