Advertisement
Guest User

Cargo Ship [ Moving ]

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