Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Elevator Mechanics Script
- Written & Annotated by AFRLme
- --*--
- [email protected] | Aim,Skype,Trillian: AFRLme
- --]]
- -- * let's create our local global variables for this script * --
- local eMinPos = -300 -- the minimum position value for elevator going up
- local eMaxPos = 717 -- the maxium position value for elevator going down
- local eGetStatus = getObject('Values[val_eStatus]') -- stores value to eGetStatus variable
- local eGetCond = getObject('Conditions[cond_eMove]') -- stores condition to eGetCond variable
- local eOBJ = getObject('ActiveAnimations[anim_elevator]') -- stores location of active animation to eOBJ variable
- local ePause = getObject('Actions[act_ePause]') -- stores location of pause action to ePause variable
- local eReset = getObject('Actions[act_eReset]') -- stores location of scene reset action to eReset variable
- local protagonist = getObject('Characters[Protagonist]') -- stores character to charPos variable
- -- * let's create the function to get current elevator position * --
- function getElevatorPos()
- eCurrentPos = eOBJ:getPoint(VAnimationCurrentPosition) -- get the current elevator position (top left)
- eCharPos = protagonist:getPoint(VCharacterPosition) -- get the current character position (object center)
- anim_protagonist = getObject('ActiveAnimations[anim_protagonist]') -- stores the location of active animation to anim_protagonist variable
- eAnimCharPos = anim_protagonist:getPoint(VAnimationCurrentPosition) -- get the current location of the anim character (top left)
- --print('Elevator Current Y Pos = ' .. eCurrentPos.y .. '!') -- prints current elevator y position
- end
- -- * let's create a function to move the elevator up or down * --
- function moveElevator()
- if eStatus == 1 and eCond then -- if elevator status = moving up & elevator is allowed to move then ...
- eOBJ:setValue(VAnimationCurrentPosition, {x = eCurrentPos.x, y = eCurrentPos.y - 1}) -- move elevator up by 1
- protagonist:setValue(VCharacterPosition, {x = eCharPos.x, y = eCharPos.y - 1}) -- move character up by 1
- anim_protagonist:setValue(VAnimationCurrentPosition, {x = eAnimCharPos.x, y = eAnimCharPos.y - 1}) -- move anim character up by 1
- eGetCond:setValue(VConditionValue, false) -- set elevator move to false
- startAction(ePause) -- reset the loop & control the elevator ascent/descent speed
- end
- if eStatus == 2 and eCond then -- if elevator status = moving down & elevator is allowed to move then ...
- eOBJ:setValue(VAnimationCurrentPosition, {x = eCurrentPos.x, y = eCurrentPos.y + 1}) -- move elevator down by 1
- protagonist:setValue(VCharacterDestination, {x = eCharPos.x, y = eCharPos.y + 1}) -- move character down by 1
- anim_protagonist:setValue(VAnimationCurrentPosition, {x = eAnimCharPos.x, y = eAnimCharPos.y + 1}) -- move anim character down by 1
- eGetCond:setValue(VConditionValue, false) -- set elevator moving to false
- startAction(ePause) -- reset the loop & control the elevator ascent/descent speed
- end
- end
- -- * let's create the main elevator loop which determines if elevator should be stationary, moving up or down * --
- function loopElevator()
- eCond = eGetCond:getBool(VConditionValue) -- check eCond condition value to determine if elevator should be moving or stationary
- eStatus = eGetStatus:getInt(VValueInt) -- check eStatus value to determine if elevator should be stationary or moving up or down
- scnBrightness = getObject('Scenes[scene_001]')
- scnGetBrightness = scnBrightness:getInt(VSceneBrightness)
- -- * check if elevator should be going up * --
- if eStatus == 1 and eCond then
- getElevatorPos() -- check the current elevator position
- if eCurrentPos.y > eMinPos then moveElevator() end -- move elevator up by 1
- if eCurrentPos.y <= eMinPos + 100 and eCurrentPos.y > eMinPos then scnBrightness:setValue(VSceneBrightness, scnGetBrightness - 1) end -- fade out the scene
- if eCurrentPos.y <= eMinPos then eGetStatus:setValue(VValueInt, 0) startAction(eReset) end -- kill the loop
- end
- -- * check if elevator should be going down * --
- if eStatus == 2 and eCond then
- getElevatorPos() -- check current elevator position
- if eCurrentPos.y < eMaxPos then moveElevator() end -- move elevator down by 1
- if eCurrentPos.y >= eMaxPos - 100 and eCurrentPos.y < eMaxPos then scnBrightness:setValue(VSceneBrightness, scnGetBrightness - 1) end -- fade out the scene
- if eCurrentPos.y >= eMaxPos then eGetStatus:setValue(VValueInt, 0) startAction(eReset) end -- kill the loop
- end
- end
- -- * let's create the loop function * --
- registerEventHandler('mainLoop', 'loopElevator')
Advertisement
Add Comment
Please, Sign In to add comment