SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.8 KiB

5 years ago
  1. //
  2. // Used for testing interpolated rotations with MoveObject
  3. // Also used to test AttachObjectToObject
  4. // A cargo ship goes around and visits some route points
  5. //
  6. // SA-MP 0.3d and above
  7. //
  8. // - Kye 2011
  9. //
  10. #include <a_samp>
  11. #include "../include/gl_common.inc" // for PlaySoundForPlayersInRange()
  12. #define NUM_SHIP_ROUTE_POINTS 25
  13. #define SHIP_HULL_ID 9585 // massive cargo ship's hull. This is used as the main object
  14. #define SHIP_MOVE_SPEED 10.0
  15. #define SHIP_DRAW_DISTANCE 300.0
  16. #define NUM_SHIP_ATTACHMENTS 10
  17. new Float:gShipHullOrigin[3] =
  18. { -2409.8438, 1544.9453, 7.0000 }; // so we can convert world space to model space for attachment positions
  19. new gShipAttachmentModelIds[NUM_SHIP_ATTACHMENTS] = {
  20. 9586, // Ship main platform
  21. 9761, // Ship rails
  22. 9584, // Bridge exterior
  23. 9698, // Bridge interior
  24. 9821, // Bridge interior doors
  25. 9818, // Bridge radio desk
  26. 9819, // Captain's desk
  27. 9822, // Captain's seat
  28. 9820, // Bridge ducts and lights
  29. 9590 // Cargo bay area
  30. };
  31. new Float:gShipAttachmentPos[NUM_SHIP_ATTACHMENTS][3] = {
  32. // these are world space positions used on the original cargo ship in the game
  33. // they will be converted to model space before attaching
  34. {-2412.1250, 1544.9453, 17.0469},
  35. {-2411.3906, 1544.9453, 27.0781},
  36. {-2485.0781, 1544.9453, 26.1953},
  37. {-2473.5859, 1543.7734, 29.0781},
  38. {-2474.3594, 1547.2422, 24.7500},
  39. {-2470.2656, 1544.9609, 33.8672},
  40. {-2470.4531, 1551.1172, 33.1406},
  41. {-2470.9375, 1550.7500, 32.9063},
  42. {-2474.6250, 1545.0859, 33.0625},
  43. {-2403.5078, 1544.9453, 8.7188}
  44. };
  45. // Pirate ship route points (position/rotation)
  46. new Float:gShipRoutePoints[NUM_SHIP_ROUTE_POINTS][6] = {
  47. {-1982.57, 2052.56, 0.00, 0.00, 0.00, 144.84},
  48. {-2178.63, 2103.67, 0.00, 0.00, 0.00, 189.24},
  49. {-2366.64, 2020.28, 0.00, 0.00, 0.00, 215.22},
  50. {-2539.06, 1892.52, 0.00, 0.00, 0.00, 215.22},
  51. {-2722.79, 1787.85, 0.00, 0.00, 0.00, 205.62},
  52. {-2918.51, 1729.60, 0.00, 0.00, 0.00, 190.50},
  53. {-3124.70, 1758.03, 0.00, 0.00, 0.00, 156.36},
  54. {-3316.51, 1850.08, 0.00, 0.00, 0.00, 153.36},
  55. {-3541.12, 1977.99, 0.00, 0.00, 0.00, 145.74},
  56. {-3772.54, 2140.70, 0.00, 0.00, 0.00, 144.96},
  57. {-4078.78, 2272.93, 0.00, 0.00, 0.00, 167.52},
  58. {-4382.22, 2222.52, 0.00, 0.36, 0.06, 206.70},
  59. {-4578.11, 2013.70, 0.00, 0.36, 0.54, 244.80},
  60. {-4603.54, 1718.89, 0.00, 1.92, -0.36, 283.26},
  61. {-4463.49, 1504.50, 0.00, 0.92, -0.36, 316.32},
  62. {-4228.00, 1380.52, 0.00, 0.92, -0.36, 342.54},
  63. {-3950.14, 1346.96, 0.00, 0.02, -0.06, 359.64},
  64. {-3646.69, 1344.57, 0.00, 0.02, -0.06, 359.64},
  65. {-3350.01, 1410.39, 0.00, 0.02, -0.06, 384.48},
  66. {-2854.63, 1651.56, 0.00, 0.02, -0.06, 378.54},
  67. {-2590.84, 1667.61, 0.00, 0.02, -0.06, 356.28},
  68. {-2345.84, 1633.19, 0.00, 0.02, -0.06, 350.28},
  69. {-2106.14, 1639.23, 0.00, 0.02, -0.06, 378.36},
  70. {-1943.63, 1743.98, 0.00, 0.02, -0.06, 411.42},
  71. {-1891.39, 1907.57, 0.00, 0.02, -0.06, 457.14}
  72. };
  73. new gShipCurrentPoint = 1; // current route point the ship is at. We start at route 1
  74. // SA-MP objects
  75. new gMainShipObjectId;
  76. new gShipsAttachments[NUM_SHIP_ROUTE_POINTS];
  77. forward StartMovingTimer();
  78. //-------------------------------------------------
  79. public StartMovingTimer()
  80. {
  81. MoveObject(gMainShipObjectId,gShipRoutePoints[gShipCurrentPoint][0],
  82. gShipRoutePoints[gShipCurrentPoint][1],
  83. gShipRoutePoints[gShipCurrentPoint][2],
  84. SHIP_MOVE_SPEED / 2.0, // slower for the first route
  85. gShipRoutePoints[gShipCurrentPoint][3],
  86. gShipRoutePoints[gShipCurrentPoint][4],
  87. gShipRoutePoints[gShipCurrentPoint][5]);
  88. }
  89. //-------------------------------------------------
  90. public OnFilterScriptInit()
  91. {
  92. gMainShipObjectId = CreateObject(SHIP_HULL_ID, gShipRoutePoints[0][0], gShipRoutePoints[0][1], gShipRoutePoints[0][2],
  93. gShipRoutePoints[0][3], gShipRoutePoints[0][4], gShipRoutePoints[0][5], SHIP_DRAW_DISTANCE);
  94. new x=0;
  95. while(x != NUM_SHIP_ATTACHMENTS) {
  96. gShipsAttachments[x] = CreateObject(gShipAttachmentModelIds[x], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SHIP_DRAW_DISTANCE);
  97. AttachObjectToObject(gShipsAttachments[x], gMainShipObjectId,
  98. gShipAttachmentPos[x][0] - gShipHullOrigin[0],
  99. gShipAttachmentPos[x][1] - gShipHullOrigin[1],
  100. gShipAttachmentPos[x][2] - gShipHullOrigin[2],
  101. 0.0, 0.0, 0.0);
  102. x++;
  103. }
  104. SetTimer("StartMovingTimer",30*1000,0); // pause at route 0 for 30 seconds
  105. return 1;
  106. }
  107. //-------------------------------------------------
  108. public OnFilterScriptExit()
  109. {
  110. DestroyObject(gMainShipObjectId);
  111. new x=0;
  112. while(x != NUM_SHIP_ATTACHMENTS) {
  113. DestroyObject(gShipsAttachments[x]);
  114. x++;
  115. }
  116. return 1;
  117. }
  118. //-------------------------------------------------
  119. public OnObjectMoved(objectid)
  120. {
  121. if(objectid != gMainShipObjectId) return 0;
  122. if(gShipCurrentPoint > 0 && !(gShipCurrentPoint % 5)) {
  123. // play some seagulls audio every 5 points
  124. PlaySoundForPlayersInRange(6200, 200.0, gShipRoutePoints[gShipCurrentPoint][0],
  125. gShipRoutePoints[gShipCurrentPoint][1],
  126. gShipRoutePoints[gShipCurrentPoint][2]);
  127. }
  128. gShipCurrentPoint++;
  129. if(gShipCurrentPoint == NUM_SHIP_ROUTE_POINTS) {
  130. gShipCurrentPoint = 0;
  131. MoveObject(gMainShipObjectId,gShipRoutePoints[gShipCurrentPoint][0],
  132. gShipRoutePoints[gShipCurrentPoint][1],
  133. gShipRoutePoints[gShipCurrentPoint][2],
  134. SHIP_MOVE_SPEED / 2.0, // slower for the last route
  135. gShipRoutePoints[gShipCurrentPoint][3],
  136. gShipRoutePoints[gShipCurrentPoint][4],
  137. gShipRoutePoints[gShipCurrentPoint][5]);
  138. return 1;
  139. }
  140. if(gShipCurrentPoint == 1) {
  141. // Before heading to the first route we should wait a bit
  142. SetTimer("StartMovingTimer",30*1000,0); // pause at route 0 for 30 seconds
  143. return 1;
  144. }
  145. /*
  146. new tempdebug[256+1];
  147. format(tempdebug,256,"The ship is at route: %d", gShipCurrentPoint);
  148. SendClientMessageToAll(0xFFFFFFFF,tempdebug);*/
  149. MoveObject(gMainShipObjectId,gShipRoutePoints[gShipCurrentPoint][0],
  150. gShipRoutePoints[gShipCurrentPoint][1],
  151. gShipRoutePoints[gShipCurrentPoint][2],
  152. SHIP_MOVE_SPEED,
  153. gShipRoutePoints[gShipCurrentPoint][3],
  154. gShipRoutePoints[gShipCurrentPoint][4],
  155. gShipRoutePoints[gShipCurrentPoint][5]);
  156. return 1;
  157. }
  158. //-------------------------------------------------
  159. public OnPlayerCommandText(playerid, cmdtext[])
  160. {
  161. new cmd[256];
  162. new idx;
  163. cmd = strtok(cmdtext, idx);
  164. if(strcmp(cmd, "/boardship", true) == 0) {
  165. if(gShipCurrentPoint != 1) {
  166. SendClientMessage(playerid, 0xFFFF0000, "The ship can't be boarded right now");
  167. return 1;
  168. }
  169. SetPlayerPos(playerid,-1937.7816,2017.7969,16.6640);
  170. return 1;
  171. }
  172. if(strcmp(cmd, "/stopship", true) == 0) {
  173. StopObject(gMainShipObjectId);
  174. return 1;
  175. }
  176. return 0;
  177. }
  178. //-------------------------------------------------