AFRLme

Elevator Mechanics [VS]

Jan 26th, 2013
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. --[[
  2. Elevator Mechanics Script
  3. Written & Annotated by AFRLme
  4. --*--
  5. [email protected] | Aim,Skype,Trillian: AFRLme
  6. --]]
  7.  
  8. -- * let's create our local global variables for this script * --
  9. local eMinPos = -300 -- the minimum position value for elevator going up
  10. local eMaxPos = 717 -- the maxium position value for elevator going down
  11. local eGetStatus = getObject('Values[val_eStatus]') -- stores value to eGetStatus variable
  12. local eGetCond = getObject('Conditions[cond_eMove]') -- stores condition to eGetCond variable
  13. local eOBJ = getObject('ActiveAnimations[anim_elevator]') -- stores location of active animation to eOBJ variable
  14. local ePause = getObject('Actions[act_ePause]') -- stores location of pause action to ePause variable
  15. local eReset = getObject('Actions[act_eReset]') -- stores location of scene reset action to eReset variable
  16. local protagonist = getObject('Characters[Protagonist]') -- stores character to charPos variable
  17.  
  18. -- * let's create the function to get current elevator position * --
  19. function getElevatorPos()
  20.  eCurrentPos = eOBJ:getPoint(VAnimationCurrentPosition) -- get the current elevator position (top left)
  21.  eCharPos = protagonist:getPoint(VCharacterPosition) -- get the current character position (object center)
  22.  anim_protagonist = getObject('ActiveAnimations[anim_protagonist]') -- stores the location of active animation to anim_protagonist variable
  23.  eAnimCharPos = anim_protagonist:getPoint(VAnimationCurrentPosition) -- get the current location of the anim character (top left)
  24.  --print('Elevator Current Y Pos = ' .. eCurrentPos.y .. '!') -- prints current elevator y position
  25. end
  26.  
  27. -- * let's create a function to move the elevator up or down * --
  28. function moveElevator()
  29.  if eStatus == 1 and eCond then -- if elevator status = moving up & elevator is allowed to move then ...
  30.   eOBJ:setValue(VAnimationCurrentPosition, {x = eCurrentPos.x, y = eCurrentPos.y - 1}) -- move elevator up by 1
  31.   protagonist:setValue(VCharacterPosition, {x = eCharPos.x, y = eCharPos.y - 1}) -- move character up by 1
  32.   anim_protagonist:setValue(VAnimationCurrentPosition, {x = eAnimCharPos.x, y = eAnimCharPos.y - 1}) -- move anim character up by 1
  33.   eGetCond:setValue(VConditionValue, false) -- set elevator move to false
  34.   startAction(ePause) -- reset the loop & control the elevator ascent/descent speed
  35.  end
  36.  if eStatus == 2 and eCond then -- if elevator status = moving down & elevator is allowed to move then ...
  37.   eOBJ:setValue(VAnimationCurrentPosition, {x = eCurrentPos.x, y = eCurrentPos.y + 1}) -- move elevator down by 1
  38.   protagonist:setValue(VCharacterDestination, {x = eCharPos.x, y = eCharPos.y + 1}) -- move character down by 1
  39.   anim_protagonist:setValue(VAnimationCurrentPosition, {x = eAnimCharPos.x, y = eAnimCharPos.y + 1}) -- move anim character down by 1
  40.   eGetCond:setValue(VConditionValue, false) -- set elevator moving to false
  41.   startAction(ePause) -- reset the loop & control the elevator ascent/descent speed
  42.  end
  43. end
  44.  
  45. -- * let's create the main elevator loop which determines if elevator should be stationary, moving up or down * --
  46. function loopElevator()
  47.  eCond = eGetCond:getBool(VConditionValue) -- check eCond condition value to determine if elevator should be moving or stationary
  48.  eStatus = eGetStatus:getInt(VValueInt) -- check eStatus value to determine if elevator should be stationary or moving up or down
  49.  scnBrightness = getObject('Scenes[scene_001]')
  50.  scnGetBrightness = scnBrightness:getInt(VSceneBrightness)
  51.  -- * check if elevator should be going up * --
  52.  if eStatus == 1 and eCond then
  53.   getElevatorPos() -- check the current elevator position
  54.   if eCurrentPos.y > eMinPos then moveElevator() end -- move elevator up by 1
  55.   if eCurrentPos.y <= eMinPos + 100 and eCurrentPos.y > eMinPos then scnBrightness:setValue(VSceneBrightness, scnGetBrightness - 1) end -- fade out the scene
  56.   if eCurrentPos.y <= eMinPos then eGetStatus:setValue(VValueInt, 0) startAction(eReset) end -- kill the loop
  57.  end
  58.  -- * check if elevator should be going down * --
  59.  if eStatus == 2 and eCond then
  60.   getElevatorPos() -- check current elevator position
  61.   if eCurrentPos.y < eMaxPos then moveElevator() end -- move elevator down by 1
  62.   if eCurrentPos.y >= eMaxPos - 100 and eCurrentPos.y < eMaxPos then scnBrightness:setValue(VSceneBrightness, scnGetBrightness - 1) end -- fade out the scene
  63.   if eCurrentPos.y >= eMaxPos then eGetStatus:setValue(VValueInt, 0) startAction(eReset) end -- kill the loop
  64.  end
  65. end
  66.  
  67.  
  68. -- * let's create the loop function * --
  69. registerEventHandler('mainLoop', 'loopElevator')
Advertisement
Add Comment
Please, Sign In to add comment