Guest User

Untitled

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