Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Teknikk Gen5 V2 Elevator Controller Starting...")
- print("Script Version V3.1")
- BtnULit = "http://www.roblox.com/asset/?id=156949987"
- BtnLit = "http://www.roblox.com/asset/?id=156949992"
- IndDirUp = "http://www.roblox.com/asset/?id=66704336"
- IndDirDown = "http://www.roblox.com/asset/?id=66704345"
- IndDirULit = "http://www.roblox.com/asset/?id=66704228"
- DirIndLit = "http://www.roblox.com/asset/?id=130007738"
- DirIndULit = "http://www.roblox.com/asset/?id=130007740"
- Stop = false
- Debug = false -- ENABLE DEBUG MODE
- PreDoor = false
- DoorTimer = 7 -- Set's how long doors should be open
- NudgeTimer = 30 -- Set's how long until doors have to force close if held too long
- ChimeAfterDoor = true -- Ring the Door Chime after door has opened
- ChimeBeforeDoor = false-- Ring the Door Chime before door has opened
- FloorPassChime = true -- Beep on floor pass
- DoorSensors = true -- Door sensors, reopens if touched
- DoorSensorHold = true
- IgnoreSensor = false
- CardLock = false -- Enable floor locking, DOES NOT WORK IN MIC10 MODE
- LockedFloors = {} -- Floors that is locked
- CardNumber = {} -- Keys that are authorized, Example [301]=3 would Only unlock 3, while [101]=0 Will unlock all floors
- -- Motor Speed and Level Offset
- SmoothLevel = true -- Try the new leveling method :D
- MotorSpeed = 100
- MotorStartSpeed = 0.05
- MotorStopSpeed = 0.05
- StopOffset = 0.5
- SmoothOffset = 1
- LevelOffset = 5
- IndicatorOffset = 5
- DoorState = "Closed"
- DoorStateRear = "Closed"
- DoorSpeed = 0
- -- Open
- DoorL = 47 -- Length of door to CFrame
- DoorC = 0.05
- -- Close
- DoorCL = 47
- DoorCC = 0.05 -- How much per CFrame
- --
- DoorP = 0
- DoorPR = 0
- DoorOpenTime = 0
- DoorHold = false
- SlowClose = false
- DoorNudge = false
- ResetDoorTimer = false
- ConfigMode = false
- FireLock = false
- Alarm = false
- Moving = false
- Busy = false
- Locked = false
- Fire = false
- DoorTimerReset = false
- MoveDirection = "Up"
- UnlockedFloor = 9001
- TargetFloor = 0
- TotalFloors = 0
- CallQuene = {}
- DCalls = {}
- MoveTimeout = 15
- MoveTime = 0
- MoveFloor = 1
- MoveErrors = 0
- MoveDB = false
- Floor = script.Parent.Floor
- Motor = script.Parent.Motor
- Car = script.Parent.Car
- BP = Car.Platform.BodyPosition
- BV = Car.Platform.BodyVelocity
- TCar = script.Parent.Car
- TFloors = script.Parent.Floors
- TFloorsG = script.Parent.Floors:GetChildren()
- TCarG = script.Parent.Car:GetChildren()
- SFloor = Floor.Value
- BP.position = Car.Platform.Position
- BP.P = 10000
- BP.D = 1000
- script.Parent.CardReader.Changed:connect(function()
- if script.Parent.CardReader.Value == true then
- UnlockedFloor = 0
- else
- UnlockedFloor = 9001
- end
- end)
- -- NEW WELD SCRIPT --
- function DoWeld(a, b)
- local w = Instance.new("ManualWeld")
- w.Part0 = a
- w.Part1 = b
- w.C0 = CFrame.new()
- w.C1 = b.CFrame:inverse() * a.CFrame
- b.Anchored = false
- print(b.Name)
- return w;
- end
- function DecodeData(String)
- local Data = String
- local Values = {}
- while Data:find("#") do
- local TempData,_ = Data:find("#")
- table.insert(Values,Data:sub(1,TempData-1))
- Data = Data:sub(TempData+1)
- end
- table.insert(Values,Data)
- return Values
- end
- -- DESTINATION DISPATCH --
- script.Parent.Motor.Changed:connect(function()
- if not MoveDB then
- MoveDB = true
- repeat
- wait(1)
- if Floor.Value ~= MoveFloor then
- MoveFloor = Floor.Value
- MoveTime = 0
- else
- MoveTime = MoveTime + 1
- end
- print("Error Checker: "..MoveTime)
- until not Moving or MoveTime == MoveTimeout or Stop == true
- if Stop == true then MoveDB = false return end
- if MoveTime ~= MoveTimeout then MoveTime = 0 MoveDB = false print("Succeeded to arrive at floor!") end
- if MoveErrors == 3 then
- coroutine.resume(coroutine.create(function() Stop(Floor.Value, true) end))
- script.Parent["Floor Indicator OUTSIDE"].Disabled = true
- script.Parent["Floor Indicator"].Disabled = true
- TCar.Screen.SurfaceGui.Frame.Indicator.Text = "X"
- script.Parent.Floors.Floor1.FloorIndicator.SurfaceGui.Frame.Indicator.Text = "X"
- script.Parent.Disabled.Value = true
- TCar.BTDIS.Texture.Texture = BtnLit
- MoveTime = 0
- MoveDB = false
- return
- end
- if MoveTime == MoveTimeout then
- MoveErrors = MoveErrors + 1
- MoveTime = 0
- MoveDB = false
- coroutine.resume(coroutine.create(function() Stop(Floor.Value, true) end))
- end
- end
- end)
- script.Parent.DestCall.Changed:connect(function()
- if script.Parent.DestCall.Value ~= "READY" then
- local CallData = DecodeData(script.Parent.DestCall.Value)
- table.insert(DCalls,CallData[1])
- Quene(tonumber(CallData[1]),"Add","Call")
- if not Moving and Floor.Value == tonumber(CallData[1]) then
- Quene(tonumber(CallData[2]),"Add","Call") -- let's call this after Quene
- end
- end
- script.Parent.DestCall.Value = "READY"
- end)
- function ProcessCall(xFloor, xDest)
- if xDest > xFloor then
- ElevatorRun("U")
- end
- if xDest < xFloor then
- ElevatorRun("D")
- end
- end
- -- NEW SYSTEM ... ---
- ERRun = false
- ERStop = false
- ERFloor = Floor.Value
- function ElevatorRun(Direction)
- if not ERRun then
- ERRun = true
- repeat wait() until DoorState == "Closed"
- Moving = true
- BP.P = 0
- BP.D = 0
- BV.P = 10000
- if Debug then print("Doors closed, start moving :)") end
- if Direction == "U" then
- script.Parent.Direction.Value = "U"
- MoveDirection = "Up"
- CallDirection = "Up"
- Motor.Value = 0.000001
- wait(0.8)
- for i = 0, MotorSpeed, 1 do
- Motor.Value = i
- wait(MotorStartSpeed)
- end
- end
- if Direction == "D" then
- script.Parent.Direction.Value = "D"
- MoveDirection = "Down"
- CallDirection = "Down"
- wait(0.8)
- for i = 0, MotorSpeed, 1 do
- Motor.Value = -i
- wait(MotorStartSpeed)
- end
- end
- local StopElevator = false
- while StopElevator == false and Stop == false do
- for i = 1, #TFloorsG do
- local CF = tonumber(TFloorsG[i].Name:sub(6,7))
- if math.abs(TFloorsG[i].Level.Position.Y - Car.Platform.Position.Y) < IndicatorOffset then
- if Floor.Value ~= CF then
- Floor.Value = CF
- end
- end
- if math.abs(TFloorsG[i].Level.Position.Y - Car.Platform.Position.Y) < LevelOffset then
- if ERFloor ~= CF then
- ERFloor = CF
- if Floor.Value == 1 or Floor.Value == TotalFloors then StopFloor = CF StopElevator = true end
- for i,l in pairs(CallQuene) do if CF == l then StopFloor = CF StopElevator = true end end
- end
- end
- end
- wait()
- end
- -- STOP --
- script.Parent.Direction.Value = "N"
- Moving = false
- if Stop == true then
- if MoveDirection == "Up" then
- Floor.Value = Floor.Value + 0.5
- end
- if MoveDirection == "Down" then
- Floor.Value = Floor.Value - 0.5
- end
- BV.velocity = Vector3.new(0,0,0)
- end
- if not Stop == true then
- Btn(StopFloor,0)
- for i,l in pairs(DCalls) do
- if StopFloor == l[1] then
- Quene(tonumber(l[2]),"Add","Call")
- end
- if StopFloor == l[2] then
- print("Removed "..l[1].." , "..l[2].." call from DestCall")
- table.remove(DCalls,i)
- end
- end
- for i, l in pairs(CallQuene) do
- if l == StopFloor then
- print("Removed: "..l)
- table.remove(CallQuene,i)
- end
- end
- coroutine.resume(coroutine.create(function()
- for i=1, 0.1, -0.05 do
- Car.Platform.Motor.Pitch = i
- wait(0.1)
- end
- end))
- BP.position = Vector3.new(Car.Platform.BodyPosition.position.X,TFloors["Floor"..StopFloor].Level.Position.Y,Car.Platform.BodyPosition.position.Z)
- if not SmoothLevel then
- BP.P = 10000
- BP.D = 1000
- BV.P = 0
- BV.velocity = Vector3.new(0,0,0)
- end
- local Dir = MoveDirection
- Quene(StopFloor,"Remove")
- if Floor.Value == TotalFloors then
- MoveDirection = "Down"
- end
- if Floor.Value == 1 then
- MoveDirection = "Up"
- end
- if ChimeBeforeDoor then coroutine.resume(coroutine.create(function() DoChime() end)) end
- if SmoothLevel then
- for i=MotorSpeed, 0.5, -4 do
- if Dir == "Up" then
- BV.velocity = Vector3.new(0,i,0)
- elseif Dir == "Down" then
- BV.velocity = Vector3.new(0,-i,0)
- end
- wait()
- end
- repeat
- wait()
- until math.abs(TFloors["Floor"..StopFloor].Level.Position.Y - Car.Platform.Position.Y) < SmoothOffset
- BP.P = 8000
- BP.D = 2500
- BV.P = 0
- BV.velocity = Vector3.new(0,0,0)
- end
- if PreDoor then
- coroutine.resume(coroutine.create(function() DoorRun(1) end))
- end
- repeat
- wait()
- until math.abs(TFloors["Floor"..StopFloor].Level.Position.Y - Car.Platform.Position.Y) < StopOffset
- Car.Platform.Motor:Stop()
- wait(0.5)
- Motor.Value = 0
- TargetFloor = 0
- script.Parent.TargetFloor.Value = 0
- if not PreDoor then
- coroutine.resume(coroutine.create(function() DoorRun(1) end))
- end
- end
- Busy = false
- ERRun = false
- if Stop == false then
- print("Waiting 5 seconds until checking for calls")
- wait(5)
- Quene(0,"Check")
- end
- -- END STOP --
- end
- end
- function DoorRun(xm)
- if Debug then print("DoorRun("..xm..") executed") end
- if xm == 1 then
- coroutine.resume(coroutine.create(function() DoorOpen(Floor.Value,false) end))
- -- coroutine.resume(coroutine.create(function() RearDoorOpen(Floor.Value,false) end)) -- REAR DOOR
- end
- if xm == 2 then
- coroutine.resume(coroutine.create(function() DoorClose(Floor.Value) end))-- MAIN DOOR
- -- coroutine.resume(coroutine.create(function() RearDoorClose(Floor.Value) end)) -- REAR DOOR
- end
- if xm == 3 then
- if DoorState == "Closing" then
- coroutine.resume(coroutine.create(function() DoorReOpen(Floor.Value,true) end))-- MAIN DOOR
- -- coroutine.resume(coroutine.create(function() RearDoorOpen(Floor.Value,true) end))-- MAIN DOOR
- end
- end
- end
- function DoorOpen(F,ReOpen)
- if F ~= Floor.Value and Moving == true then return end -- IF NOT OF FLOOR DO NOT Open
- if DoorNudge == true then return end -- NO OPEN ON NUDGE
- if DoorState == "Closed" then -- open when closed and reopen if closing
- DoorState = "Opening"
- local DOFL = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorLeft"):GetChildren()
- local DOFR = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorRight"):GetChildren()
- wait(0.1)
- DoChime()
- wait(0.8)
- for i=DoorP, DoorL do
- if DoorState == "CancelReopen" then DoorState = "OkReopen" print("Grr, need to reopen...") return end
- DoorP = DoorP + 1
- for R=1, #DOFR do
- DOFR[R].CFrame = DOFR[R].CFrame * CFrame.new(DoorC, 0, 0)
- end
- for L=1, #DOFL do
- DOFL[L].CFrame = DOFL[L].CFrame * CFrame.new(-DoorC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorRight:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(-DoorCC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorLeft:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(DoorCC, 0, 0)
- end
- wait(DoorSpeed)
- end
- if DoorState == "CancelReopen" then DoorState = "OkReopen" return end
- DoorState = "Open"
- SetCarDirInd(1)
- SetFloorDirInd(1)
- if ChimeBeforeDoor then coroutine.resume(coroutine.create(function() DoChime() end)) end
- -- CREATE DOOR TIMER
- coroutine.resume(coroutine.create(function()
- local CTime = 0
- repeat
- wait(1)
- CTime = CTime + 1
- if DoorTimerReset == true then
- print("Timer reset due to sensor touched or Open clicked")
- CTime = 0
- DoorTimerReset = false
- end
- until CTime > DoorTimer or DoorState ~= "Open"
- if CTime > DoorTimer then
- DoorRun(2)
- elseif DoorState ~= "Open" then
- print("Door was closed before timer ended :)")
- end
- end))
- DoorCheck() -- NUDGE TIMER
- end
- end
- function DoorReOpen(F)
- if F ~= Floor.Value and Moving == true then return end -- IF NOT OF FLOOR DO NOT Open
- if DoorNudge == true then return end -- NO OPEN ON NUDGE
- if DoorState == "Closing" and DoorNudge == false then -- open when closed and reopen if closing
- DoorState = "CancelReopen"
- repeat wait() until DoorState == "OkReopen"
- wait(0.2)
- DoorState = "Opening"
- local DOFL = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorLeft"):GetChildren()
- local DOFR = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorRight"):GetChildren()
- wait(0.1)
- DoChime()
- wait(0.8)
- for i=DoorP, DoorL do
- if DoorState == "CancelReopen" then DoorState = "OkReopen" print("Grr, need to reopen...") return end
- DoorP = DoorP + 1
- for R=1, #DOFR do
- DOFR[R].CFrame = DOFR[R].CFrame * CFrame.new(DoorC, 0, 0)
- end
- for L=1, #DOFL do
- DOFL[L].CFrame = DOFL[L].CFrame * CFrame.new(-DoorC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorRight:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(-DoorCC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorLeft:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(DoorCC, 0, 0)
- end
- wait(DoorSpeed)
- end
- if DoorState == "CancelReopen" then DoorState = "OkReopen" print("Grr, need to reopen...") return end
- DoorState = "Open"
- SetCarDirInd(1)
- SetFloorDirInd(1)
- --if ChimeAfterDoor then coroutine.resume(coroutine.create(function() DoChime() end)) end
- -- CREATE DOOR TIMER
- coroutine.resume(coroutine.create(function()
- local CTime = 0
- repeat
- wait(1)
- CTime = CTime + 1
- if DoorTimerReset == true or DoorHold == true then
- print("Timer reset due to sensor touched or Open clicked")
- CTime = 0
- DoorTimerReset = false
- end
- until CTime > DoorTimer or DoorState ~= "Open"
- if CTime > DoorTimer then
- DoorRun(2)
- elseif DoorState ~= "Open" then
- print("Door was closed before timer ended :)")
- end
- end))
- DoorCheck() -- NUDGE TIMER
- end
- end
- function DoorClose(F,Nudge)
- if DoorHold == true then return end
- if F ~= Floor.Value and Moving == true then return end -- IF NOT OF FLOOR DO NOT Open
- if Floor.Value == 1 and FireLock then return end
- if DoorState == "Open" or DoorState ~= "Closed" and DoorState == "Opening" and Nudge == true then
- if Nudge == true then
- DoorNudge = true
- coroutine.resume(coroutine.create(function()
- while DoorState ~= "Closed" do
- Car.Platform.Nudge:Play()
- wait(2)
- end
- end))
- end
- repeat wait() until DoorState == "Open"
- SetCarDirInd(0)
- SetFloorDirInd(0)
- DoorState = "Closing"
- local DoorFloorLeft = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorLeft"):GetChildren()
- local DoorFloorRight = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorRight"):GetChildren()
- script.Parent.Doors.Value = "Closed"
- wait(0.4)
- local DOFL = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorLeft"):GetChildren()
- local DOFR = TFloors:FindFirstChild("Floor"..F):FindFirstChild("DoorRight"):GetChildren()
- for i=0, DoorCL do
- if DoorState == "CancelReopen" then DoorState = "OkReopen" return end
- DoorP = DoorP - 1
- for R=1, #DOFR do
- DOFR[R].CFrame = DOFR[R].CFrame * CFrame.new(-DoorC, 0, 0)
- end
- for L=1, #DOFL do
- DOFL[L].CFrame = DOFL[L].CFrame * CFrame.new(DoorC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorRight:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(DoorCC, 0, 0)
- end
- for i,l in pairs(Car.Level.DoorLeft:GetChildren()) do
- l.C1 = l.C1 * CFrame.new(-DoorCC, 0, 0)
- end
- if Nudge or SlowClose or DoorP < 7 then wait(0.066) else wait(DoorSpeed) end
- end
- if DoorState == "CancelReopen" then DoorState = "OkReopen" return end
- if DoorState == "Closing" then
- if Nudge == true then DoorNudge = false end
- DoorState = "Closed"
- Quene(0,"Check")
- end
- end
- Car.Platform.Nudge:Stop()
- end
- function RearDoorOpen(F,ReOpen)
- print("FUNCTION NOT AVAILABLE")
- end
- function RearDoorClose(F,Nudge)
- print("FUNCTION NOT AVAILABLE")
- end
- Running = false
- function DoorCheck()
- if Running then return end
- if FireLock then return end
- if DoorOpenTime == 0 then
- coroutine.resume(coroutine.create (function()
- Running = true
- while DoorOpenTime ~= NudgeTimer do
- if DoorState == "Closed" or FireLock or DoorHold then break end
- DoorOpenTime = DoorOpenTime + 1
- print("Nudge timer: "..DoorOpenTime)
- wait(1)
- end
- if DoorState ~= "Closed" or DoorStateRear ~= "Closed" then
- coroutine.resume(coroutine.create(function()
- repeat wait() until DoorState == "Open" or DoorState == "Closed"
- if DoorState == "Closed" then
- return -- No takk
- elseif DoorState == "Open" then
- DoorClose(Floor.Value,true)
- end
- end))
- DoorOpenTime = 0
- Running = false
- end
- DoorOpenTime = 0
- Running = false
- end))
- end
- end
- function DoorTimerX(Rear)
- for i=0,DoorTimer do
- if Rear == true then
- if DoorStateRear ~= "Open" then return end
- else
- if DoorState ~= "Open" then return end
- end
- wait(0.1)
- end
- if Rear == true then
- if DoorStateRear ~= "Open" then return end
- else
- if DoorState ~= "Open" then return end
- end
- if Rear == true then
- RearDoorClose(Floor.Value)
- else
- DoorClose(Floor.Value)
- end
- end
- if DoorSensors then
- Car.DoorSensor.Touched:connect(function (Player)
- if Player == nil then return end
- if Player.Parent == nil then return end
- if Player.Parent:FindFirstChild("Humanoid") then
- DoorTimerReset = true
- coroutine.resume(coroutine.create(function() if not Moving and DoorState == "Closing" then DoorReOpen(Floor.Value,true) end end))
- end
- end)
- if Car:FindFirstChild("DoorSensorRear") then
- Car.DoorSensorRear.Touched:connect(function (Player)
- if Player == nil then return end
- if Player.Parent == nil then return end
- if Player.Parent:FindFirstChild("Humanoid") then
- coroutine.resume(coroutine.create(function() if not Moving and DoorStateRear == "Closing" then RearDoorOpen(Floor.Value,true) end end))
- end
- end)
- end
- end
- function Btn(xFloor,xMode,Type)
- local xCar = TCar:FindFirstChild("BTF"..xFloor)
- local xCall = TFloors:FindFirstChild("Floor"..xFloor):FindFirstChild("CallButton")
- -- local xCall2 = TFloors:FindFirstChild("Floor"..xFloor):FindFirstChild("CallButton2")
- if xMode == 1 then
- for _,l in pairs(TCarG) do if l.Name == "BTF"..xFloor then wait(0.08) l.Button.BrickColor = BrickColor.new("New Yeller") end end
- if xCall ~= nil and Type == "Call" then
- xCall.BrickColor = BrickColor.new("New Yeller")
- end
- if xCall2 ~= nil and Type == "Call" then
- xCall2.BrickColor = BrickColor.new("New Yeller")
- end
- if TCar:FindFirstChild("FloorCall") then
- if TCar.FloorCall.SurfaceGui:FindFirstChild("F"..xFloor) then
- TCar.FloorCall.SurfaceGui:FindFirstChild("F"..xFloor).TextTransparency = 0
- end
- end
- end
- if xMode == 0 then
- for _,l in pairs(TCarG) do if l.Name == "BTF"..xFloor then l.Button.BrickColor = BrickColor.new("Institutional white") end end
- if xCall ~= nil then
- xCall.BrickColor = BrickColor.new("Institutional white")
- end
- if xCall2 ~= nil then
- xCall2.BrickColor = BrickColor.new("Institutional white")
- end
- if xDual ~= nil then
- --xDual.Button.BrickColor = BrickColor.new("Institutional white")
- end
- if TCar:FindFirstChild("FloorCall") then
- if TCar.FloorCall.SurfaceGui:FindFirstChild("F"..xFloor) then
- TCar.FloorCall.SurfaceGui:FindFirstChild("F"..xFloor).TextTransparency = 1
- end
- end
- end
- end
- function SetCarDirInd(F,Dir)
- if F == 1 then
- if MoveDirection == "Up" then
- for _,l in pairs(TCarG) do if l.Name == "BDirUp" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(TCarG) do if l.Name == "BDirMid" then l.BrickColor = BrickColor.new("Forest green") end end
- end
- if MoveDirection == "Down" then
- for _,l in pairs(TCarG) do if l.Name == "BDirDown" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(TCarG) do if l.Name == "BDirMid" then l.BrickColor = BrickColor.new("Forest green") end end
- end
- end
- if F == 0 then
- for _,l in pairs(TCarG) do if l.Name == "BDirUp" then l.BrickColor = BrickColor.new("Really black") end end
- for _,l in pairs(TCarG) do if l.Name == "BDirMid" then l.BrickColor = BrickColor.new("Really black") end end
- for _,l in pairs(TCarG) do if l.Name == "BDirDown" then l.BrickColor = BrickColor.new("Really black") end end
- end
- end
- function DoChime()
- local Chime = TCar.Platform.Chime
- if MoveDirection == "Up" then
- Chime.Pitch = 1
- Chime:Play()
- elseif MoveDirection == "Down" then
- Chime.Pitch = 1
- Chime:Play()
- wait(0.7)
- Chime.Pitch = 1
- Chime:Play()
- elseif Floor.Value == TotalFloors then
- Chime.Pitch = 1
- Chime:Play()
- wait(0.7)
- Chime.Pitch = 1
- elseif Floor.Value == 1 then
- Chime.Pitch = 1
- Chime:Play()
- else
- Chime.Pitch = 1
- Chime:Play()
- end
- end
- function SetFloorDirInd(F)
- if F == 1 then
- if MoveDirection == "Up" or Floor.Value == 1 then
- script.Parent.UD.Value = "U"
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirUp" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirUp" then l.Material = "Neon" end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.Material = "Neon" end end
- script.DoChime.Value = true
- elseif MoveDirection == "Down" or Floor.Value == TotalFloors then
- --script.Parent.UD.Value = "D"
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirDown" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirDown" then l.Material = "Neon" end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.BrickColor = BrickColor.new("Forest green") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.Material = "Neon" end end
- script.DoChime.Value = true
- else
- end
- end
- if F == 0 then
- script.Parent.UD.Value = "N"
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirUp" then l.BrickColor = BrickColor.new("Really black") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirDown" then l.BrickColor = BrickColor.new("Really black") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirUp" then l.Material = "SmoothPlastic" end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "BDirDown" then l.Material = "SmoothPlastic" end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.BrickColor = BrickColor.new("Really black") end end
- for _,l in pairs(script.Parent.Floors["Floor"..Floor.Value]:GetChildren()) do if l.Name == "M1" then l.Material = "SmoothPlastic" end end
- script.DoChime.Value = false
- end
- end
- function Quene(TF,MO,CC)
- if Debug then print("Quene start..., Type: "..MO.." Target: "..TF) end
- if MO == "Check" then
- if Debug then print("Checking..") end
- -- Check Regular Quene
- for i = 1, #CallQuene do
- if CallQuene[i] ~= nil then
- ProcessCall(Floor.Value, CallQuene[i])
- end
- end
- return
- end
- if MO == "Add" then
- if Debug then print("Running Add quene") end
- if Fire then return end
- Btn(TF,1,CC)
- if Debug then print("Checking if it is at floor idle") end
- -- If Elevator is at Floor and Idle
- if TF == Floor.Value and not Busy and not Moving then
- if DoorState == "Closed" then
- DoorRun(1)
- elseif DoorState == "Closing" then
- DoorRun(3)
- end
- Btn(TF,0,CC)
- return
- end
- if Debug then print("Checking if locked") end
- -- If not Then check if floor is locked
- if CC == "Car" then
- if CardLock then
- for i = 1, #LockedFloors do
- if LockedFloors[i] == TF then
- if UnlockedFloor == LockedFloors[i] or UnlockedFloor == 0 then
- print("Ignoring lock")
- else
- print("Floor Locked...")
- Btn(TF,0,CC)
- return
- end
- end
- end
- end
- end
- if Debug then print("Checking if it exist") end
- for i = 1, #CallQuene do
- if CallQuene[i] == TF then
- print("Call exist, Not adding floor: "..CallQuene[i])
- return
- end
- end
- if Debug then print("Inserting call") end
- -- Nope, Then we can add a call to it
- table.insert(CallQuene,TF)
- if not Busy then Quene(0,"Check") end
- return
- end
- -- NEXT
- if MO == "Remove" then
- for i = 1, #CallQuene do
- if CallQuene[i] == TF then
- print("Removed: "..CallQuene[i])
- CallQuene[i] = nil
- end
- end
- for i,l in pairs(DCalls) do
- if TF == l[2] then
- print("Removed call from DestCall")
- table.remove(DCalls,i)
- end
- end
- return
- end
- end
- function DoAlarm(Player)
- if not Alarm then
- Alarm = true
- local g = Instance.new("Hint",Workspace)
- g.Text = "Attention, Elevator "..script.Parent.Elevator.Value.."'s Alarm was pressed by "..Player.Name
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=143969690"
- TCar.Platform.Alarm.Looped = true
- TCar.Platform.Alarm.Pitch = 1
- wait(0.5)
- TCar.Platform.Alarm:Play()
- wait(5)
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm:Stop()
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=12721064"
- TCar.Platform.Alarm.Looped = false
- wait(1)
- TCar.Platform.Alarm:Play()
- TCar.Platform.Alarm.Pitch = 1
- wait(3)
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=12721071"
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm.Pitch = 1
- for i=1,3 do
- TCar.Platform.Alarm:Play()
- wait(2)
- end
- --[[
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=142628192"
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm.Pitch = 1
- wait(0.5)
- TCar.Platform.Alarm:Play()
- wait(25)
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=130772180"
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm.Pitch = 1
- wait(0.5)
- TCar.Platform.Alarm:Play()
- wait(1)
- ]]--
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=138254180"
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm.Pitch = 1
- wait(0.5)
- TCar.Platform.Alarm:Play()
- wait(3)
- TCar.Platform.Alarm.SoundId = "http://www.roblox.com/asset/?id=138187085"
- TCar.Platform.Alarm.Looped = false
- TCar.Platform.Alarm.Pitch = 1
- wait(0.5)
- TCar.Platform.Alarm:Play()
- wait(1)
- g:Destroy()
- Alarm = false
- end
- end
- x = script.Parent.Floors:GetChildren()
- cs = Car:GetChildren()
- for i,l in pairs(x) do
- TotalFloors = TotalFloors + 1
- if TFloorsG[i]:FindFirstChild("CallButton") then
- TFloorsG[i].CallButton.ClickDetector.MouseClick:connect(function() if not ConfigMode then Quene(tonumber(TFloorsG[i].Name:sub(6)),"Add","Call") end end)
- --TFloorsG[i].CallButton.Texture.Texture = BtnULit
- end
- if TFloorsG[i]:FindFirstChild("CallButton2") then
- TFloorsG[i].CallButton2.ClickDetector.MouseClick:connect(function() if not ConfigMode then Quene(tonumber(TFloorsG[i].Name:sub(6)),"Add","Call") end end)
- --TFloorsG[i].CallButton2.Texture.Texture = BtnULit
- end
- end
- if TCar:FindFirstChild("CardReader") ~= nil then
- TCar:FindFirstChild("CardReader").Touched:connect(function (Card)
- local Accepted = false
- if Card.Parent.Name ~= "ConfigKey" and Card.Parent:FindFirstChild("CardNumber") ~= nil and CardLock then
- for i,l in pairs(CardNumber) do
- if Card.Parent.CardNumber.Value == i then
- TCar.CardReader.BrickColor = BrickColor.new("Bright green")
- UnlockedFloor = l
- --CardLock = false
- wait(5)
- UnlockedFloor = 99999
- --CardLock = true
- TCar.CardReader.BrickColor = BrickColor.new("New Yeller")
- Accepted = true
- end
- wait()
- end
- if not Accepted then
- TCar.CardReader.BrickColor = BrickColor.new("Really red")
- wait(1)
- TCar.CardReader.BrickColor = BrickColor.new("New Yeller")
- end
- end
- end)
- end
- for i = 1, #TCarG do
- if TCarG[i].Name:sub(1,2) == "BT" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function() TCar.Platform.Beep:Play() end)
- end
- if TCarG[i].Name:sub(1,5) == "BTRST" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if DoorState == "Closed" then
- --TCarG[i].Texture.Texture = BtnLit
- script.Reset.Disabled = false
- end
- end)
- end
- if TCarG[i].Name:sub(1,5) == "BTSTP" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if Stop == false then
- Stop = true
- for i=1,#CallQuene do CallQuene[i] = nil end
- --for i=1,TotalFloors do TCar["BTF"..i].Texture.Texture = BtnULit end
- --TCarG[i].Texture.Texture = BtnLit
- else
- Stop = false
- --TCarG[i].Texture.Texture = BtnULit
- end
- end)
- end
- if TCarG[i].Name:sub(1,5) == "BTSLC" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if SlowClose == false then
- SlowClose = true
- --TCarG[i].Texture.Texture = BtnLit
- else
- SlowClose = false
- --TCarG[i].Texture.Texture = BtnULit
- end
- end)
- end
- if TCarG[i].Name:sub(1,5) == "BTDIS" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if script.Parent.Disabled.Value == false then
- script.Parent.Disabled.Value = true
- --TCarG[i].Texture.Texture = BtnLit
- else
- script.Parent.Disabled.Value = false
- --TCarG[i].Texture.Texture = BtnULit
- end
- end)
- end
- if TCarG[i].Name:sub(1,5) == "BTDHO" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if DoorHold == false then
- DoorHold = true
- --TCarG[i].Texture.Texture = BtnLit
- else
- DoorHold = false
- --TCarG[i].Texture.Texture = BtnULit
- end
- end)
- end
- if TCarG[i].Name:sub(1,5) == "BTEFA" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if script.Parent.FireMode.Value == false then
- script.Parent.FireMode.Value = true
- --TCarG[i].Texture.Texture = BtnLit
- else
- script.Parent.FireMode.Value = false
- --TCarG[i].Texture.Texture = BtnULit
- end
- end)
- end
- if TCarG[i].Name:sub(1,4) == "BTDO" then
- local BO = false
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if not FireLock and not Stop then
- if not BO then
- Bo = true
- --TCarG[i].Texture.Texture = BtnLit
- if not Moving and DoorState == "Closed" then DoorRun(1)
- elseif DoorState == "Closing" then DoorRun(3) end
- wait(0.2)
- --TCarG[i].Texture.Texture = BtnULit
- Bo = false
- end
- end
- end)
- end
- if TCarG[i].Name:sub(1,4) == "BTDC" then
- local BC = false
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if not FireLock and not Stop then
- if not BC then
- BC = true
- --TCarG[i].Texture.Texture = BtnLit
- DoorRun(2)
- wait(0.2)
- --TCarG[i].Texture.Texture = BtnULit
- BC = false
- end
- end
- end)
- end
- if TCarG[i].Name:sub(1,3) == "BTF" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(function()
- if not FireLock and not Stop then
- Quene(tonumber(TCarG[i].Name:sub(4)),"Add","Car")
- end end)
- end
- if TCarG[i].Name:sub(1,4) == "BTAL" then
- TCarG[i].Button.ClickDetector.MouseClick:connect(DoAlarm)
- end
- end
- script.Parent.ScriptCall.Changed:connect(function ()
- if script.Parent.ScriptCall.Value ~= -100 then
- Quene(script.Parent.ScriptCall.Value,"Add",true)
- script.Parent.ScriptCall.Value = -100
- end
- end)
- script.Parent.FireMode.Changed:connect(function ()
- if script.Parent.FireMode.Value == true then
- FireLock = true
- Locked = true
- TCar.BTEFA.Texture.Texture = BtnLit
- TCar.Platform.Fire:Play()
- for i=1, TotalFloors do
- TCar["BTF"..i].Texture.Texture = BtnULit
- end
- for i=1,#CallQuene do
- CallQuene[i] = nil
- end
- TCar.BTDHO.Texture.Texture = BtnULit
- DoorHold = false
- wait(1)
- Quene(1,"Add","Car")
- coroutine.resume(coroutine.create(function()
- repeat
- if DoorState ~= "Closed" and Floor.Value ~= 1 then
- repeat wait() until DoorState == "Open" or DoorState == "Closed"
- if DoorState == "Open" then
- coroutine.resume(coroutine.create(function() DoorClose(Floor.Value,true) end))
- while DoorState ~= "Closed" and not DoorState == "Closed" do
- Car.Platform.Chime:Play()
- wait(0.3)
- end
- else return end
- end
- wait()
- Quene(1,"Add","Car")
- until Floor.Value == 1
- end))
- repeat wait() until Floor.Value == 1
- TCar.Platform.Fire:Stop()
- else
- TCar.Platform.Fire:Stop()
- TCar.BTEFA.Texture.Texture = BtnULit
- Fire = false
- FireLock = false
- Locked = false
- coroutine.resume(coroutine.create(function() DoorClose(Floor.Value,false) end))
- end
- end)
- Floor.Changed:connect(function()
- if FloorPassChime then
- Car.Platform.FloorPassChime:Play()
- end
- end)
- print("Total floors for this elevator: "..TotalFloors)
- Motor.Changed:connect(function()
- BV.velocity = Vector3.new(0,Motor.Value,0)
- end)
- for i,l in pairs(Car.DR:GetChildren()) do
- DoWeld(Car.Level,l).Parent = Car.Level.DoorRight
- end
- for i,l in pairs(Car.DL:GetChildren()) do
- DoWeld(Car.Level,l).Parent = Car.Level.DoorLeft
- end
- function StartWeld(ChildAbuse)
- for _,l in pairs(ChildAbuse) do
- if l:IsA("Part") or l:IsA("WedgePart") or l:IsA("CornerWedgePart") or l:IsA("Seat")then
- local w = DoWeld(Car.Level,l)
- w.Parent = Car.Welds
- w.Name = l.Name.."WELD"
- end
- if l:IsA("Model") and l.Name ~= "DL" and l.Name ~= "DR" and l.Name ~= "Welds" then
- StartWeld(l:GetChildren())
- end
- end
- end
- StartWeld(Car:GetChildren())
- --[[
- ButtonTextures = {
- ["DDDIS"]=158175576,["EFA"]=158175560,["DHO"]=158229138,["SLC"]=158230637,["STP"]=158231350,["RST"]=158233241,
- ["DO"]=144878365,["DC"]=144878349,["AL"]=144878970,["S0"]=144877405,["S1"]=144877410,["S2"]=144877413,["S3"]=144877418,["S4"]=144877421,["S5"]=144877426,
- ["S6"]=144877430,["S7"]=144877436,["S8"]=144877442,["S9"]=144877449,["L1"]=146946090,["L2"]=146946097,["L3"]=146946110,["L4"]=146946116,["L5"]=146946126,
- ["L6"]=146946135,["L7"]=146946148,["L8"]=146946189,["L9"]=146946196,["R0"]=146947263,["R1"]=146947269,["R2"]=146947282,["R3"]=146947294,["R4"]=146947304,
- ["R5"]=146947310,["R6"]=146947315,["R7"]=146947323,["R8"]=146947333,["R9"]=146947343
- }
- for i = 1, #TCarG do
- if TCarG[i].Name:sub(1,5) == "BTRST" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["RST"]
- end
- if TCarG[i].Name:sub(1,5) == "BTSTP" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["STP"]
- end
- if TCarG[i].Name:sub(1,5) == "BTDHO" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["DHO"]
- end
- if TCarG[i].Name:sub(1,5) == "BTSLC" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["SLC"]
- end
- if TCarG[i].Name:sub(1,5) == "BTDIS" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["DDDIS"]
- end
- if TCarG[i].Name:sub(1,5) == "BTEFA" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["EFA"]
- end
- if TCarG[i].Name:sub(1,4) == "BTAL" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["AL"]
- end
- if TCarG[i].Name:sub(1,4) == "BTDO" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["DO"]
- end
- if TCarG[i].Name:sub(1,4) == "BTDC" then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["DC"]
- end
- if TCarG[i].Name:sub(1,3) == "BTF" then
- if tonumber(TCarG[i].Name:sub(4)) < 10 then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=0"
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["S"..TCarG[i].Name:sub(4)]
- end
- if tonumber(TCarG[i].Name:sub(4)) > 9 then
- TCarG[i].FloorNumberL.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["L"..TCarG[i].Name:sub(4,4)]
- TCarG[i].FloorNumberR.Texture = "http://www.roblox.com/asset/?id=" .. ButtonTextures["R"..TCarG[i].Name:sub(5,5)]
- end
- end
- if TCarG[i].Name:sub(1,2) == "BT" then
- if TCarG[i]:FindFirstChild("Texture") then
- TCarG[i].Texture.Texture = BtnULit
- end
- end
- end
- ]]
- print("Execution of elevator controller done...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement