AndreiAndre777

Untitled

May 18th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.56 KB | None | 0 0
  1. // -----------------------------------------------------------------------------
  2. // -----------------------------------------------------------------------------
  3. // Example Filterscript for the new LS BeachSide Building with Elevator
  4. // --------------------------------------------------------------------
  5. // Original elevator code by Zamaroht in 2010
  6. //
  7. // Updated by Kye in 2011
  8. // * Added a sound effect for the elevator starting/stopping
  9. //
  10. // Edited by Matite in January 2015
  11. // * Adapted the elevator code so it works in this new building and removed the
  12. // light pole at the underground car park entrance
  13. //
  14. // Updated to v1.03 by Matite in April 2015
  15. // * Removed the code that removes the existing building map object and the lines
  16. // that create the new objects as the original building is now replaced with
  17. // the new one by SAMP instead (same as the LS Office building)
  18. //
  19. // Updated to v1.02 by Matite in February 2015
  20. // * Added code for the new car park object and edited the elevator to
  21. // include the car park
  22. //
  23. // This script creates the new LS BeachSide building object, removes the
  24. // existing GTASA building object, adds the new car park object and creates
  25. // an elevator that can be used to travel between all levels.
  26. //
  27. // You can un-comment the OnPlayerCommandText callback below to enable a simple
  28. // teleport command (/lsb) that teleports you to the LS BeachSide building.
  29. //
  30. // Warning...
  31. // This script uses a total of:
  32. // * 31 objects = 1 for the elevator, 2 for the elevator doors and 28 for the
  33. // elevator floor doors
  34. // * 15 3D Text Labels = 14 on the floors and 1 in the elevator
  35. // * 1 dialog (for the elevator - dialog ID 877)
  36. // -----------------------------------------------------------------------------
  37. // -----------------------------------------------------------------------------
  38.  
  39.  
  40. // -----------------------------------------------------------------------------
  41. // Includes
  42. // --------
  43.  
  44. // SA-MP include
  45. #include <a_samp>
  46.  
  47. // For PlaySoundForPlayersInRange()
  48. #include "../include/gl_common.inc"
  49.  
  50. // -----------------------------------------------------------------------------
  51. // Defines
  52. // -------
  53.  
  54. // Movement speed of the elevator
  55. #define ELEVATOR_SPEED (5.0)
  56.  
  57. // Movement speed of the doors
  58. #define DOORS_SPEED (5.0)
  59.  
  60. // Time in ms that the elevator will wait in each floor before continuing with the queue...
  61. // be sure to give enough time for doors to open
  62. #define ELEVATOR_WAIT_TIME (5000)
  63.  
  64. // Dialog ID for the LS BeachSide elevator dialog
  65. #define DIALOG_ID (877)
  66.  
  67. // Position defines
  68. #define X_DOOR_R_OPENED (289.542419)
  69. #define X_DOOR_L_OPENED (286.342407)
  70. #define Y_DOOR_R_OPENED (-1609.640991)
  71. #define Y_DOOR_L_OPENED (-1609.076049)
  72.  
  73. #define X_FDOOR_R_OPENED (289.492431)
  74. #define X_FDOOR_L_OPENED (286.292419)
  75. #define Y_FDOOR_R_OPENED (-1609.870971)
  76. #define Y_FDOOR_L_OPENED (-1609.306030)
  77.  
  78. #define GROUND_Z_COORD (18.755348) // (33.825077)
  79. #define X_ELEVATOR_POS (287.942413)
  80. #define Y_ELEVATOR_POS (-1609.341064)
  81.  
  82. // Elevator state defines
  83. #define ELEVATOR_STATE_IDLE (0)
  84. #define ELEVATOR_STATE_WAITING (1)
  85. #define ELEVATOR_STATE_MOVING (2)
  86.  
  87. // Invalid floor define
  88. #define INVALID_FLOOR (-1)
  89.  
  90. // Used for chat text messages
  91. #define COLOR_MESSAGE_YELLOW 0xFFDD00AA
  92.  
  93. // -----------------------------------------------------------------------------
  94. // Constants
  95. // ---------
  96.  
  97. // Elevator floor names for the 3D text labels
  98. static FloorNames[14][] =
  99. {
  100. "Car Park",
  101. "Ground Floor",
  102. "First Floor",
  103. "Second Floor",
  104. "Third Floor",
  105. "Fourth Floor",
  106. "Fifth Floor",
  107. "Sixth Floor",
  108. "Seventh Floor",
  109. "Eighth Floor",
  110. "Ninth Floor",
  111. "Tenth Floor",
  112. "Eleventh Floor",
  113. "Twelfth Floor"
  114. };
  115.  
  116. // Elevator floor Z heights
  117. static Float:FloorZOffsets[14] =
  118. {
  119. 0.0, // Car Park
  120. 15.069729, // Ground Floor
  121. 29.130733, // First Floor
  122. 33.630733, // Second Floor = 29.130733 + 4.5
  123. 38.130733, // Third Floor = 33.630733 + 4.5
  124. 42.630733, // Fourth Floor = 38.130733 + 4.5
  125. 47.130733, // Fifth Floor = 42.630733 + 4.5
  126. 51.630733, // Sixth Floor = 47.130733 + 4.5
  127. 56.130733, // Seventh Floor = 51.630733 + 4.5
  128. 60.630733, // Eighth Floor = 56.130733 + 4.5
  129. 65.130733, // Ninth Floor = 60.630733 + 4.5
  130. 69.630733, // Tenth Floor = 65.130733 + 4.5
  131. 74.130733, // Eleventh Floor = 69.630733 + 4.5
  132. 78.630733, // Twelfth Floor = 74.130733 + 4.5
  133. };
  134.  
  135. // -----------------------------------------------------------------------------
  136. // Variables
  137. // ---------
  138.  
  139. // Stores the created object numbers of the elevator, the elevator doors and
  140. // the elevator floor doors so they can be destroyed when the filterscript
  141. // is unloaded
  142. new Obj_Elevator, Obj_ElevatorDoors[2], Obj_FloorDoors[14][2];
  143.  
  144. // Stores a reference to the 3D text labels used on each floor and inside the
  145. // elevator itself so they can be detroyed when the filterscript is unloaded
  146. new Text3D:Label_Elevator, Text3D:Label_Floors[14];
  147.  
  148. // Stores the current state of the elevator (ie ELEVATOR_STATE_IDLE,
  149. // ELEVATOR_STATE_WAITING or ELEVATOR_STATE_MOVING)
  150. new ElevatorState;
  151.  
  152. // Stores the current floor the elevator is on or heading to... if the value is
  153. // ELEVATOR_STATE_IDLE or ELEVATOR_STATE_WAITING this is the current floor. If
  154. // the value is ELEVATOR_STATE_MOVING then it is the floor it's moving to
  155. new ElevatorFloor;
  156.  
  157. // Stores the elevator queue for each floor
  158. new ElevatorQueue[14];
  159.  
  160. // Stores who requested the floor for the elevator queue...
  161. // FloorRequestedBy[floor_id] = playerid; (stores who requested which floor)
  162. new FloorRequestedBy[14];
  163.  
  164. // Used for a timer that makes the elevator move faster after players start
  165. // surfing the object
  166. new ElevatorBoostTimer;
  167.  
  168. // -----------------------------------------------------------------------------
  169. // Function Forwards
  170. // -----------------
  171.  
  172. // Public:
  173. forward CallElevator(playerid, floorid); // You can use INVALID_PLAYER_ID too.
  174. forward ShowElevatorDialog(playerid);
  175.  
  176. // Private:
  177. forward Elevator_Initialize();
  178. forward Elevator_Destroy();
  179.  
  180. forward Elevator_OpenDoors();
  181. forward Elevator_CloseDoors();
  182. forward Floor_OpenDoors(floorid);
  183. forward Floor_CloseDoors(floorid);
  184.  
  185. forward Elevator_MoveToFloor(floorid);
  186. forward Elevator_Boost(floorid); // Increases the elevator speed until it reaches 'floorid'.
  187. forward Elevator_TurnToIdle();
  188.  
  189. forward ReadNextFloorInQueue();
  190. forward RemoveFirstQueueFloor();
  191. forward AddFloorToQueue(floorid);
  192. forward IsFloorInQueue(floorid);
  193. forward ResetElevatorQueue();
  194.  
  195. forward DidPlayerRequestElevator(playerid);
  196.  
  197. forward Float:GetElevatorZCoordForFloor(floorid);
  198. forward Float:GetDoorsZCoordForFloor(floorid);
  199.  
  200. // -----------------------------------------------------------------------------
  201. // Callbacks
  202. // ---------
  203.  
  204. // Un-comment the OnPlayerCommandText callback below (remove the "/*" and the "*/")
  205. // to enable a simple teleport command (/lsb) which teleports the player to
  206. // outside the LS BeachSide building.
  207.  
  208. /*
  209. public OnPlayerCommandText(playerid, cmdtext[])
  210. {
  211. // Check command text
  212. if (strcmp("/lsb", cmdtext, true, 4) == 0)
  213. {
  214. // Set the interior
  215. SetPlayerInterior(playerid, 0);
  216.  
  217. // Set player position and facing angle
  218. SetPlayerPos(playerid, 289.81 + random(2), -1630.65 + random(2), 34.32);
  219. SetPlayerFacingAngle(playerid, 10);
  220.  
  221. // Fix camera position after teleporting
  222. SetCameraBehindPlayer(playerid);
  223.  
  224. // Send a gametext message to the player
  225. GameTextForPlayer(playerid, "~b~~h~LS BeachSide!", 3000, 3);
  226.  
  227. // Exit here
  228. return 1;
  229. }
  230.  
  231. // Exit here (return 0 as the command was not handled in this filterscript)
  232. return 0;
  233. }
  234. */
  235.  
  236. public OnFilterScriptInit()
  237. {
  238. // Display information in the Server Console
  239. print("\n");
  240. print(" |---------------------------------------------------");
  241. print(" |--- LS BeachSide Filterscript");
  242. print(" |-- Script v1.03");
  243. print(" |-- 19th April 2015");
  244. print(" |---------------------------------------------------");
  245.  
  246. // Reset the elevator queue
  247. ResetElevatorQueue();
  248.  
  249. // Create the elevator object, the elevator doors and the floor doors
  250. Elevator_Initialize();
  251.  
  252. // Display information in the Server Console
  253. print(" |-- LS BeachSide Building Elevator created");
  254. print(" |---------------------------------------------------");
  255.  
  256. // Loop
  257. for (new i = 0; i < MAX_PLAYERS; i++)
  258. {
  259. // Check if the player is connected and not a NPC
  260. if (IsPlayerConnected(i) && !IsPlayerNPC(i))
  261. {
  262. // Remove the lamp post at the underground car park entrance
  263. RemoveBuildingForPlayer(i, 1226, 265.481, -1581.1, 32.9311, 5.0);
  264.  
  265. // Remove the night lights object (must be removed to also remove any
  266. // occulsion zones inside the building)
  267. RemoveBuildingForPlayer(i, 6518, 280.297, -1606.2, 72.3984, 250.0);
  268. }
  269. }
  270.  
  271. // Exit here
  272. return 1;
  273. }
  274.  
  275. public OnFilterScriptExit()
  276. {
  277. // Destroy the elevator, the elevator doors and the elevator floor doors
  278. Elevator_Destroy();
  279.  
  280. // Display information in the Server Console
  281. print(" |-- LS BeachSide Building Elevator destroyed");
  282. print(" |---------------------------------------------------");
  283.  
  284. // Exit here
  285. return 1;
  286. }
  287.  
  288. public OnPlayerConnect(playerid)
  289. {
  290. // Remove the lamp post at the underground car park entrance
  291. RemoveBuildingForPlayer(playerid, 1226, 265.481, -1581.1, 32.9311, 5.0);
  292.  
  293. // Remove the night lights object (must be removed to also remove any
  294. // occulsion zones inside the building)
  295. RemoveBuildingForPlayer(playerid, 6518, 280.297, -1606.2, 72.3984, 250.0);
  296.  
  297. // Exit here (return 1 so this callback is processed in other scripts)
  298. return 1;
  299. }
  300.  
  301. public OnObjectMoved(objectid)
  302. {
  303. // Create variables
  304. new Float:x, Float:y, Float:z;
  305.  
  306. // Loop
  307. for(new i; i < sizeof(Obj_FloorDoors); i ++)
  308. {
  309. // Check if the object that moved was one of the elevator floor doors
  310. if(objectid == Obj_FloorDoors[i][0])
  311. {
  312. GetObjectPos(Obj_FloorDoors[i][0], x, y, z);
  313.  
  314. // Some floor doors have shut, move the elevator to next floor in queue:
  315. if (y < Y_DOOR_L_OPENED - 0.5)
  316. {
  317. Elevator_MoveToFloor(ElevatorQueue[0]);
  318. RemoveFirstQueueFloor();
  319. }
  320. }
  321. }
  322.  
  323. if(objectid == Obj_Elevator) // The elevator reached the specified floor.
  324. {
  325. KillTimer(ElevatorBoostTimer); // Kills the timer, in case the elevator reached the floor before boost.
  326.  
  327. FloorRequestedBy[ElevatorFloor] = INVALID_PLAYER_ID;
  328.  
  329. Elevator_OpenDoors();
  330. Floor_OpenDoors(ElevatorFloor);
  331.  
  332. GetObjectPos(Obj_Elevator, x, y, z);
  333. Label_Elevator = Create3DTextLabel("{CCCCCC}Press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}' to use elevator", 0xCCCCCCAA, X_ELEVATOR_POS + 1.6, Y_ELEVATOR_POS - 1.85, z - 0.4, 4.0, 0, 1);
  334.  
  335. ElevatorState = ELEVATOR_STATE_WAITING;
  336. SetTimer("Elevator_TurnToIdle", ELEVATOR_WAIT_TIME, 0);
  337. }
  338.  
  339. return 1;
  340. }
  341.  
  342. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  343. {
  344. if(dialogid == DIALOG_ID)
  345. {
  346. if(!response)
  347. return 0;
  348.  
  349. if(FloorRequestedBy[listitem] != INVALID_PLAYER_ID || IsFloorInQueue(listitem))
  350. GameTextForPlayer(playerid, "~r~The floor is already in the queue", 3500, 4);
  351. else if(DidPlayerRequestElevator(playerid))
  352. GameTextForPlayer(playerid, "~r~You already requested the elevator", 3500, 4);
  353. else
  354. CallElevator(playerid, listitem);
  355.  
  356. return 1;
  357. }
  358.  
  359. return 0;
  360. }
  361.  
  362. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  363. {
  364. // Check if the player is not in a vehicle and pressed the conversation yes key (Y by default)
  365. if (!IsPlayerInAnyVehicle(playerid) && (newkeys & KEY_YES))
  366. {
  367. // Create variables and get the players current position
  368. new Float:pos[3];
  369. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  370.  
  371. // For debug
  372. //printf("X = %0.2f | Y = %0.2f | Z = %0.2f", pos[0], pos[1], pos[2]);
  373.  
  374. // Check if the player is using the button inside the elevator
  375. if (pos[1] > (Y_ELEVATOR_POS - 1.8) && pos[1] < (Y_ELEVATOR_POS + 1.8) && pos[0] < (X_ELEVATOR_POS + 1.8) && pos[0] > (X_ELEVATOR_POS - 1.8))
  376. {
  377. // The player is using the button inside the elevator
  378. // --------------------------------------------------
  379.  
  380. // Show the elevator dialog to the player
  381. ShowElevatorDialog(playerid);
  382. }
  383. else
  384. {
  385. // Check if the player is using the button on one of the floors
  386. if(pos[1] < (Y_ELEVATOR_POS - 1.81) && pos[1] > (Y_ELEVATOR_POS - 3.8) && pos[0] > (X_ELEVATOR_POS + 1.21) && pos[0] < (X_ELEVATOR_POS + 3.8))
  387. {
  388. // The player is most likely using an elevator floor button... check which floor
  389. // -----------------------------------------------------------------------------
  390.  
  391. // Create variable with the number of floors to check (total floors minus 1)
  392. new i = 13;
  393.  
  394. // Loop
  395. while(pos[2] < GetDoorsZCoordForFloor(i) + 3.5 && i > 0)
  396. i --;
  397.  
  398. if(i == 0 && pos[2] < GetDoorsZCoordForFloor(0) + 2.0)
  399. i = -1;
  400.  
  401. if (i <= 12)
  402. {
  403. // Check if the elevator is not moving (idle or waiting)
  404. if (ElevatorState != ELEVATOR_STATE_MOVING)
  405. {
  406. // Check if the elevator is already on the floor it was called from
  407. if (ElevatorFloor == i + 1)
  408. {
  409. // Display gametext message to the player
  410. GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~y~~h~LS BeachSide Elevator Is~n~~y~~h~Already On This Floor...~n~~w~Walk Inside It~n~~w~And Press '~k~~CONVERSATION_YES~'", 3500, 3);
  411.  
  412. // Display chat text message to the player
  413. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* The LS BeachSide elevator is already on this floor... walk inside it and press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}'");
  414.  
  415. // Exit here (return 1 so this callback is processed in other scripts)
  416. return 1;
  417. }
  418. }
  419.  
  420. // Call function to call the elevator to the floor
  421. CallElevator(playerid, i + 1);
  422.  
  423. // Display gametext message to the player
  424. GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~g~~h~LS BeachSide Elevator~n~~g~~h~Has Been Called...~n~~w~Please Wait", 3000, 3);
  425.  
  426. // Create variable for formatted message
  427. new strTempString[100];
  428.  
  429. // Check if the elevator is moving
  430. if (ElevatorState == ELEVATOR_STATE_MOVING)
  431. {
  432. // Format chat text message
  433. format(strTempString, sizeof(strTempString), "* The LS BeachSide elevator has been called... it is currently moving towards the %s.", FloorNames[ElevatorFloor]);
  434. }
  435. else
  436. {
  437. // Check if the floor is the car park
  438. if (ElevatorFloor == 0)
  439. {
  440. // Format chat text message
  441. format(strTempString, sizeof(strTempString), "* The LS BeachSide elevator has been called... it is currently at the %s.", FloorNames[ElevatorFloor]);
  442. }
  443. else
  444. {
  445. // Format chat text message
  446. format(strTempString, sizeof(strTempString), "* The LS BeachSide elevator has been called... it is currently on the %s.", FloorNames[ElevatorFloor]);
  447. }
  448. }
  449.  
  450. // Display formatted chat text message to the player
  451. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, strTempString);
  452.  
  453. // Exit here (return 1 so this callback is processed in other scripts)
  454. return 1;
  455. }
  456. }
  457. }
  458. }
  459.  
  460. // Exit here (return 1 so this callback is processed in other scripts)
  461. return 1;
  462. }
  463.  
  464. // ------------------------ Functions ------------------------
  465. stock Elevator_Initialize()
  466. {
  467. // Create the elevator and elevator door objects
  468. Obj_Elevator = CreateObject(18755, X_ELEVATOR_POS, Y_ELEVATOR_POS, GROUND_Z_COORD, 0.000000, 0.000000, 80.000000);
  469. Obj_ElevatorDoors[0] = CreateObject(18757, X_ELEVATOR_POS, Y_ELEVATOR_POS, GROUND_Z_COORD, 0.000000, 0.000000, 80.000000);
  470. Obj_ElevatorDoors[1] = CreateObject(18756, X_ELEVATOR_POS, Y_ELEVATOR_POS, GROUND_Z_COORD, 0.000000, 0.000000, 80.000000);
  471.  
  472. // Create the 3D text label for inside the elevator
  473. Label_Elevator = Create3DTextLabel("{CCCCCC}Press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}' to use elevator", 0xCCCCCCAA, X_ELEVATOR_POS + 1.6, Y_ELEVATOR_POS - 1.85, GROUND_Z_COORD - 0.4, 4.0, 0, 1);
  474.  
  475. // Create variables
  476. new string[128], Float:z;
  477.  
  478. // Loop
  479. for (new i; i < sizeof(Obj_FloorDoors); i ++)
  480. {
  481. // Create elevator floor door objects
  482. Obj_FloorDoors[i][0] = CreateObject(18757, X_ELEVATOR_POS, Y_ELEVATOR_POS - 0.245, GetDoorsZCoordForFloor(i) + 0.05, 0.000000, 0.000000, 80.000000);
  483. Obj_FloorDoors[i][1] = CreateObject(18756, X_ELEVATOR_POS, Y_ELEVATOR_POS - 0.245, GetDoorsZCoordForFloor(i) + 0.05, 0.000000, 0.000000, 80.000000);
  484.  
  485. // Format string for the floor 3D text label
  486. format(string, sizeof(string), "{CCCCCC}[%s]\n{CCCCCC}Press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}' to call", FloorNames[i]);
  487.  
  488. // Get label Z position
  489. z = GetDoorsZCoordForFloor(i);
  490.  
  491. // Create floor label
  492. Label_Floors[i] = Create3DTextLabel(string, 0xCCCCCCAA, X_ELEVATOR_POS + 2, Y_ELEVATOR_POS -3, z - 0.2, 10.5, 0, 1);
  493. }
  494.  
  495. // Open the car park floor doors and the elevator doors
  496. Floor_OpenDoors(0);
  497. Elevator_OpenDoors();
  498.  
  499. // Exit here
  500. return 1;
  501. }
  502.  
  503. stock Elevator_Destroy()
  504. {
  505. // Destroys the elevator.
  506.  
  507. DestroyObject(Obj_Elevator);
  508. DestroyObject(Obj_ElevatorDoors[0]);
  509. DestroyObject(Obj_ElevatorDoors[1]);
  510. Delete3DTextLabel(Label_Elevator);
  511.  
  512. for(new i; i < sizeof(Obj_FloorDoors); i ++)
  513. {
  514. DestroyObject(Obj_FloorDoors[i][0]);
  515. DestroyObject(Obj_FloorDoors[i][1]);
  516. Delete3DTextLabel(Label_Floors[i]);
  517. }
  518.  
  519. return 1;
  520. }
  521.  
  522. stock Elevator_OpenDoors()
  523. {
  524. // Opens the elevator's doors.
  525.  
  526. new Float:x, Float:y, Float:z;
  527.  
  528. GetObjectPos(Obj_ElevatorDoors[0], x, y, z);
  529. MoveObject(Obj_ElevatorDoors[0], X_DOOR_L_OPENED, Y_DOOR_L_OPENED, z, DOORS_SPEED);
  530. MoveObject(Obj_ElevatorDoors[1], X_DOOR_R_OPENED, Y_DOOR_R_OPENED, z, DOORS_SPEED);
  531.  
  532. return 1;
  533. }
  534.  
  535. stock Elevator_CloseDoors()
  536. {
  537. // Closes the elevator's doors.
  538.  
  539. if(ElevatorState == ELEVATOR_STATE_MOVING)
  540. return 0;
  541.  
  542. new Float:x, Float:y, Float:z;
  543.  
  544. GetObjectPos(Obj_ElevatorDoors[0], x, y, z);
  545. MoveObject(Obj_ElevatorDoors[0], X_ELEVATOR_POS, Y_ELEVATOR_POS, z, DOORS_SPEED);
  546. MoveObject(Obj_ElevatorDoors[1], X_ELEVATOR_POS, Y_ELEVATOR_POS, z, DOORS_SPEED);
  547.  
  548. return 1;
  549. }
  550.  
  551. stock Floor_OpenDoors(floorid)
  552. {
  553. // Opens the doors at the specified floor.
  554.  
  555. MoveObject(Obj_FloorDoors[floorid][0], X_FDOOR_L_OPENED, Y_FDOOR_L_OPENED, GetDoorsZCoordForFloor(floorid) + 0.05, DOORS_SPEED);
  556. MoveObject(Obj_FloorDoors[floorid][1], X_FDOOR_R_OPENED, Y_FDOOR_R_OPENED, GetDoorsZCoordForFloor(floorid) + 0.05, DOORS_SPEED);
  557.  
  558. PlaySoundForPlayersInRange(6401, 50.0, X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid) + 5.0);
  559.  
  560. return 1;
  561. }
  562.  
  563. stock Floor_CloseDoors(floorid)
  564. {
  565. // Closes the doors at the specified floor.
  566.  
  567. MoveObject(Obj_FloorDoors[floorid][0], X_ELEVATOR_POS, Y_ELEVATOR_POS - 0.245, GetDoorsZCoordForFloor(floorid) + 0.05, DOORS_SPEED);
  568. MoveObject(Obj_FloorDoors[floorid][1], X_ELEVATOR_POS, Y_ELEVATOR_POS - 0.245, GetDoorsZCoordForFloor(floorid) + 0.05, DOORS_SPEED);
  569.  
  570. PlaySoundForPlayersInRange(6401, 50.0, X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid) + 5.0);
  571.  
  572. return 1;
  573. }
  574.  
  575. stock Elevator_MoveToFloor(floorid)
  576. {
  577. // Moves the elevator to specified floor (doors are meant to be already closed).
  578.  
  579. ElevatorState = ELEVATOR_STATE_MOVING;
  580. ElevatorFloor = floorid;
  581.  
  582. // Move the elevator slowly, to give time to clients to sync the object surfing. Then, boost it up:
  583. MoveObject(Obj_Elevator, X_ELEVATOR_POS, Y_ELEVATOR_POS, GetElevatorZCoordForFloor(floorid), 0.25);
  584. MoveObject(Obj_ElevatorDoors[0], X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid), 0.25);
  585. MoveObject(Obj_ElevatorDoors[1], X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid), 0.25);
  586. Delete3DTextLabel(Label_Elevator);
  587.  
  588. ElevatorBoostTimer = SetTimerEx("Elevator_Boost", 2000, 0, "i", floorid);
  589.  
  590. return 1;
  591. }
  592.  
  593. public Elevator_Boost(floorid)
  594. {
  595. // Increases the elevator's speed until it reaches 'floorid'
  596. StopObject(Obj_Elevator);
  597. StopObject(Obj_ElevatorDoors[0]);
  598. StopObject(Obj_ElevatorDoors[1]);
  599.  
  600. MoveObject(Obj_Elevator, X_ELEVATOR_POS, Y_ELEVATOR_POS, GetElevatorZCoordForFloor(floorid), ELEVATOR_SPEED);
  601. MoveObject(Obj_ElevatorDoors[0], X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid), ELEVATOR_SPEED);
  602. MoveObject(Obj_ElevatorDoors[1], X_ELEVATOR_POS, Y_ELEVATOR_POS, GetDoorsZCoordForFloor(floorid), ELEVATOR_SPEED);
  603.  
  604. return 1;
  605. }
  606.  
  607. public Elevator_TurnToIdle()
  608. {
  609. ElevatorState = ELEVATOR_STATE_IDLE;
  610. ReadNextFloorInQueue();
  611.  
  612. return 1;
  613. }
  614.  
  615. stock RemoveFirstQueueFloor()
  616. {
  617. // Removes the data in ElevatorQueue[0], and reorders the queue accordingly.
  618.  
  619. for(new i; i < sizeof(ElevatorQueue) - 1; i ++)
  620. ElevatorQueue[i] = ElevatorQueue[i + 1];
  621.  
  622. ElevatorQueue[sizeof(ElevatorQueue) - 1] = INVALID_FLOOR;
  623.  
  624. return 1;
  625. }
  626.  
  627. stock AddFloorToQueue(floorid)
  628. {
  629. // Adds 'floorid' at the end of the queue.
  630.  
  631. // Scan for the first empty space:
  632. new slot = -1;
  633. for(new i; i < sizeof(ElevatorQueue); i ++)
  634. {
  635. if(ElevatorQueue[i] == INVALID_FLOOR)
  636. {
  637. slot = i;
  638. break;
  639. }
  640. }
  641.  
  642. if(slot != -1)
  643. {
  644. ElevatorQueue[slot] = floorid;
  645.  
  646. // If needed, move the elevator.
  647. if(ElevatorState == ELEVATOR_STATE_IDLE)
  648. ReadNextFloorInQueue();
  649.  
  650. return 1;
  651. }
  652.  
  653. return 0;
  654. }
  655.  
  656. stock ResetElevatorQueue()
  657. {
  658. // Resets the queue.
  659.  
  660. for(new i; i < sizeof(ElevatorQueue); i ++)
  661. {
  662. ElevatorQueue[i] = INVALID_FLOOR;
  663. FloorRequestedBy[i] = INVALID_PLAYER_ID;
  664. }
  665.  
  666. return 1;
  667. }
  668.  
  669. stock IsFloorInQueue(floorid)
  670. {
  671. // Checks if the specified floor is currently part of the queue.
  672.  
  673. for(new i; i < sizeof(ElevatorQueue); i ++)
  674. if(ElevatorQueue[i] == floorid)
  675. return 1;
  676.  
  677. return 0;
  678. }
  679.  
  680. stock ReadNextFloorInQueue()
  681. {
  682. // Reads the next floor in the queue, closes doors, and goes to it.
  683.  
  684. if(ElevatorState != ELEVATOR_STATE_IDLE || ElevatorQueue[0] == INVALID_FLOOR)
  685. return 0;
  686.  
  687. Elevator_CloseDoors();
  688. Floor_CloseDoors(ElevatorFloor);
  689.  
  690. return 1;
  691. }
  692.  
  693. stock DidPlayerRequestElevator(playerid)
  694. {
  695. for(new i; i < sizeof(FloorRequestedBy); i ++)
  696. if(FloorRequestedBy[i] == playerid)
  697. return 1;
  698.  
  699. return 0;
  700. }
  701.  
  702. stock ShowElevatorDialog(playerid)
  703. {
  704. new string[512];
  705. for(new i; i < sizeof(ElevatorQueue); i ++)
  706. {
  707. if(FloorRequestedBy[i] != INVALID_PLAYER_ID)
  708. strcat(string, "{FF0000}");
  709.  
  710. strcat(string, FloorNames[i]);
  711. strcat(string, "\n");
  712. }
  713.  
  714. ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_LIST, "LS BeachSide Elevator...", string, "Accept", "Cancel");
  715.  
  716. return 1;
  717. }
  718.  
  719. stock CallElevator(playerid, floorid)
  720. {
  721. // Calls the elevator (also used with the elevator dialog).
  722.  
  723. if(FloorRequestedBy[floorid] != INVALID_PLAYER_ID || IsFloorInQueue(floorid))
  724. return 0;
  725.  
  726. FloorRequestedBy[floorid] = playerid;
  727. AddFloorToQueue(floorid);
  728.  
  729. return 1;
  730. }
  731.  
  732. stock Float:GetElevatorZCoordForFloor(floorid)
  733. {
  734. // Return Z height value
  735. return (GROUND_Z_COORD + FloorZOffsets[floorid]);
  736. }
  737.  
  738. stock Float:GetDoorsZCoordForFloor(floorid)
  739. {
  740. // Return Z height value
  741. return (GROUND_Z_COORD + FloorZOffsets[floorid]);
  742. }
Add Comment
Please, Sign In to add comment