Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BlastDoor mod for PrisonArchitect by SHOT(by)GUN 1.1.2015
- -- Indendation looks great in Notepad++ but not in here :( sorry!
- -- variables what are visible for whole script
- local doorSpeedMultiplier = 0.2
- local currentServo = "None"
- local doorOpenStatus = this.Open
- local doOpen = true
- local currentlyMoving = true
- -- runtime variables
- local timer = 0
- local nextTimeout = 1
- function Create()
- -- this will throw an error = opens debug console! (remember to comment out on release)
- -- print()
- end
- function Update(timePassed)
- timer = timer + timePassed;
- if timer > nextTimeout then
- IntervalUpdate(timer)
- timer = 0
- end
- if currentServo == "None" then
- -- no servo detected, force door to open
- doOpen = true
- else
- -- we have servo
- local servoIsTriggered = (tonumber(currentServo.Triggered) > 0)
- if servoIsTriggered then
- doOpen = true
- else
- doOpen = false
- end
- -- if openOnTrigger is specified to false, then reverse functionality
- if not currentServo.OpenOnTrigger then
- doOpen = not doOpen
- end
- end
- moveDoor(timePassed)
- end
- function IntervalUpdate(timer)
- -- Check if we have servo
- -- following will find the closest servo (if available)
- local nearbyDoorServos = Object.GetNearbyObjects("Servo", 2.0)
- local findClosestDistance = 9999
- local findClosest = "None"
- for name, distance in pairs( nearbyDoorServos ) do
- if tonumber(distance) < findClosestDistance then
- findClosest = name
- findClosestDistance = tonumber(distance)
- end
- end
- if findClosest == "None" then
- -- could not find servo
- this.Tooltip = "tooltip_blastdoor_servomissing"
- else
- -- we found servo
- this.Tooltip = ""
- end
- -- finally update currentServo
- currentServo = findClosest
- -- make cling cling sound when door is moving
- if currentlyMoving then
- Object.Sound( "SolitaryDoor", "EndOpen" )
- end
- end
- -- in this function we force the door to be in our wanted status
- function moveDoor(timePassed)
- -- try to fix runtime error doorOpenStatus (a nil value)
- if type(doorOpenStatus) ~= "number" then
- doorOpenStatus = 0
- end
- -- increase/decrease doorOpenStatus
- if doOpen then
- doorOpenStatus = doorOpenStatus + (timePassed * doorSpeedMultiplier)
- else
- doorOpenStatus = doorOpenStatus - (timePassed * doorSpeedMultiplier)
- end
- -- do not open too much
- if doorOpenStatus > 1 then
- doorOpenStatus = 1
- end
- -- do not close too much
- if doorOpenStatus < 0 then
- doorOpenStatus = 0
- end
- -- funfact: getting this.Mode returns LockedOpen, LockedShut or Normal, but you cannot set the value with string, it has to be integer 0, 1 or 2
- if doorOpenStatus == 0 then
- -- door is shut
- if currentlyMoving then
- Object.Sound( "SolitaryDoor", "EndClose" )
- currentlyMoving = false
- end
- elseif doorOpenStatus == 1 then
- -- door is open
- if currentlyMoving then
- Object.Sound( "SolitaryDoor", "EndClose" )
- currentlyMoving = false
- end
- else
- -- door is not open or closed
- if not currentlyMoving then
- currentlyMoving = true
- end
- end
- -- finally set door "openess" to the specified value
- this.Open = doorOpenStatus
- end
Advertisement
Add Comment
Please, Sign In to add comment