Advertisement
gribbleshnibit8

Elevator Script

Aug 31st, 2019
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. scn ElevatorScript
  2.  
  3. ;======================================================================================================================
  4. ; This is the quest script that moves the elevator. It will figure out which way to move automatically.
  5. ; It is passed a list of objects that make up the elevator car and its contents, it will move those items
  6. ; up or down at the interval defined in the ElevatorSpeed global.
  7. ;
  8. ; The initial location is set by linking the elevator car floor to the location ref closest to it.
  9. ;
  10. ; For the doors, the elevator floor is linked to the interior door, and the location marker is linked to the exterior.
  11. ;======================================================================================================================
  12.  
  13. ; List Vars
  14. int iIdx
  15. int iCnt
  16. ref rObj
  17. ref rBas
  18.  
  19. ; Movement Vars
  20. int bStart
  21. int bMoveUp
  22. int bMoveDown
  23. int bTravel
  24. float fPosZ
  25. float fNewPosZ
  26.  
  27. ; Misc Vars
  28. float fTimer
  29. ref rLinked
  30.  
  31.  
  32. ; Set Externally
  33. ref rObjLst
  34. ref rLvlLst
  35. ref rCurLoc
  36. ref rNewLoc
  37.  
  38.  
  39. BEGIN GameMode
  40.  
  41. if (bStart == 0)
  42. Return
  43. endif
  44.  
  45. if (bStart == 1) ; Find current location
  46. set rBas to ListGetNthForm rObjLst 0
  47. set rObj to GetFirstRef 32 0 0
  48. Label 5
  49. if (IsFormValid rObj)
  50. if (rObj.GetDistance rBas <= 16)
  51. if (ListGetFormIndex rLvlLst rObj > -1)
  52. if (rObj == rNewLoc)
  53. set bStart to 5
  54. Return
  55. endif
  56. set rCurLoc to rObj
  57. set bStart to 2
  58. Return
  59. endif
  60. endif
  61. set rObj to Caps001
  62. set rObj to GetNextRef
  63. Goto 5
  64. endif
  65. set bStart to 0
  66. MessageBoxEx "Something bad happened"
  67. Return
  68. endif
  69.  
  70. if (bStart == 2) ; Handle door closing
  71. set rLinked to rBas.GetLinkedRef ; Inside door
  72. rLinked.SetOpenState 0
  73. set rLinked to rCurLoc.GetLinkedRef
  74. rLinked.SetOpenState 0 ; Outside door
  75. set bStart to 3
  76. set fTimer to 1.2
  77. Return
  78. endif
  79.  
  80. if (bStart == 3) ; Wait for doors to close
  81. if (fTimer > 0)
  82. set fTimer to fTimer - GetSecondsPassed
  83. Return
  84. else
  85. set rObj to ListGetNthForm rObjLst 1 ; play sound
  86. rObj.Enable
  87. set bStart to 4
  88. Return
  89. endif
  90. endif
  91.  
  92. if (bStart == 4) ; Move the elevator
  93. if (rCurLoc.GetPos Z > rNewLoc.GetPos Z) && (bMoveDown == 0)
  94. set bMoveDown to 1
  95. elseif (rCurLoc.GetPos Z < rNewLoc.GetPos Z) && (bMoveUp == 0)
  96. set bMoveUp to 1
  97. endif
  98.  
  99. set iIdx to 0
  100. set iCnt to ListGetCount rObjLst
  101.  
  102. if (bMoveDown == 1) ; Moving Down
  103. if (rNewLoc.GetPos Z >= rBas.GetPos Z)
  104. set bMoveDown to 2
  105. endif
  106. Label 10
  107. if iIdx < iCnt
  108. set rObj to ListGetNthForm rObjLst iIdx
  109. set fNewPosZ to (rObj.GetPos Z - ElevatorSpeed)
  110. rObj.SetPos Z fNewPosZ
  111. set iIdx to iIdx + 1
  112. goto 10
  113. endif
  114. if (bTravel)
  115. set fNewPosZ to (Player.GetPos Z - ElevatorSpeed)
  116. Player.SetPos Z fNewPosZ
  117. endif
  118. Return
  119. elseif (bMoveDown == 2)
  120. set bMoveDown to 0
  121. set bTravel to 0
  122. set bStart to 5
  123. Return
  124. endif
  125.  
  126. if (bMoveUp == 1) ; Moving Up
  127. if (rBas.GetPos Z >= rNewLoc.GetPos Z)
  128. set bMoveUp to 2
  129. endif
  130. Label 20
  131. if iIdx < iCnt
  132. set rObj to ListGetNthForm rObjLst iIdx
  133. set fNewPosZ to (rObj.GetPos Z + ElevatorSpeed)
  134. rObj.SetPos Z fNewPosZ
  135. set iIdx to iIdx + 1
  136. goto 20
  137. endif
  138. if (bTravel)
  139. set fNewPosZ to (Player.GetPos Z + ElevatorSpeed)
  140. Player.SetPos Z fNewPosZ
  141. endif
  142. Return
  143. elseif (bMoveUp == 2)
  144. set bMoveUp to 0
  145. set bTravel to 0
  146. set bStart to 5
  147. Return
  148. endif
  149. endif
  150.  
  151. if (bStart == 5) ; Handle door opening
  152. set rObj to ListGetNthForm rObjLst 1 ; stop sound
  153. rObj.Disable
  154. set rLinked to rBas.GetLinkedRef ; Inside door
  155. rLinked.SetOpenState 1
  156. set rLinked to rNewLoc.GetLinkedRef ; Outside door
  157. rLinked.SetOpenState 1
  158. set bStart to 0
  159. Return
  160. endif
  161.  
  162. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement