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.

264 lines
7.4 KiB

5 years ago
  1. //
  2. // RC BARNSTORM - A demonstration vehicle vs vehicle script for SA-MP 0.2
  3. // -- by kyeman (SA-MP team) 2007
  4. //
  5. // This script demonstrates the following :-
  6. // - An automatic vehicle observer mode switchable via a key press.
  7. // - Text drawing and the use of GTA ~k~ key constants.
  8. // - Use of RC vehicles
  9. // - Dynamic creation and destruction of vehicles
  10. // - The OnPlayerKeyStateChange event/callback and determining
  11. // if a key has just been pressed.
  12. // - Bypassing SA-MP's class selection with SetSpawnInfo
  13. #include <a_samp>
  14. #include <core>
  15. #include <float>
  16. new gPlayerVehicles[MAX_PLAYERS]; // the vehicleid for the active playerid
  17. new gPlayerObserving[MAX_PLAYERS]; // player observing which active player
  18. new Text:txtObsHelper;
  19. new Float:gSpawnPositions[26][4] = { // positions where players in vehicles spawn
  20. {-205.7703,-119.6655,2.4094,342.0546},
  21. {-202.1386,-54.1213,2.4111,95.6799},
  22. {-197.2334,7.5293,2.4034,16.0852},
  23. {-135.7348,61.7265,2.4112,354.3534},
  24. {-73.7883,73.4238,2.4082,260.5399},
  25. {-6.9850,27.9988,2.4112,201.7691},
  26. {0.6782,-16.0898,2.4076,161.7720},
  27. {-46.3365,-88.3937,2.4092,180.7382},
  28. {-72.4389,-127.2939,2.4107,113.5616},
  29. {-128.1940,-144.1725,2.4094,78.9676},
  30. {-266.0189,-50.6718,2.4125,223.8079},
  31. {-244.2617,-1.0468,2.1038,257.3333},
  32. {-93.3146,-32.4889,2.4085,186.0631},
  33. {-130.7054,-93.4983,2.4124,73.8375},
  34. {-117.4049,4.2989,2.4112,337.1284},
  35. {-26.1622,135.8739,2.4094,248.1580},
  36. {45.5705,86.7586,2.0753,147.3342},
  37. {54.9881,2.2997,1.1132,95.7173},
  38. {-248.9905,-119.3982,2.4083,303.7859},
  39. {-60.1321,55.5239,2.4038,325.2209},
  40. {-60.9184,47.9302,5.7706,342.8299},
  41. {-70.0303,-22.0071,2.4113,165.2789},
  42. {-138.3093,-83.2640,2.4152,4.0455},
  43. {-25.5989,94.6100,2.4041,150.8322},
  44. {-161.0327,-70.5945,2.4042,142.9221},
  45. {-54.8308,-139.6148,2.4119,258.7639}
  46. };
  47. //------------------------------------------------------------------------------------------------------
  48. main()
  49. {
  50. print("Running: RC BARNSTORM by kyeman 2007");
  51. }
  52. //------------------------------------------------
  53. // ObserverSwitchToNextVehicle
  54. // Will increment the current observed player
  55. // until it finds a new player with an active vehicle.
  56. ObserverSwitchToNextVehicle(playerid)
  57. {
  58. new x=0;
  59. while(x!=MAX_PLAYERS) { // MAX_PLAYERS iterations
  60. gPlayerObserving[playerid]++;
  61. if(gPlayerObserving[playerid] == MAX_PLAYERS) {
  62. // we need to cycle back to the start
  63. gPlayerObserving[playerid] = 0;
  64. }
  65. // see if the target player has a vehicle,
  66. // if so assign this player to observe it
  67. if(gPlayerVehicles[gPlayerObserving[playerid]] != 0) {
  68. PlayerSpectateVehicle(playerid,gPlayerVehicles[gPlayerObserving[playerid]]);
  69. return;
  70. }
  71. x++;
  72. }
  73. // didn't find any vehicles to observe. we'll have to default to last
  74. PlayerSpectateVehicle(playerid,gPlayerVehicles[gPlayerObserving[playerid]]);
  75. }
  76. //------------------------------------------------
  77. // IsKeyJustDown. Returns 1 if the key
  78. // has just been pressed, 0 otherwise.
  79. IsKeyJustDown(key, newkeys, oldkeys)
  80. {
  81. if((newkeys & key) && !(oldkeys & key)) return 1;
  82. return 0;
  83. }
  84. //------------------------------------------------
  85. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  86. {
  87. if(gPlayerObserving[playerid] >= 0 && IsKeyJustDown(KEY_SPRINT,newkeys,oldkeys)) {
  88. // They're requesting to spawn, so take them out of observer mode
  89. // this will cause them to spawn automatically, using the SpawnInfo
  90. // we previously forced upon them during OnPlayerRequestClass
  91. TogglePlayerSpectating(playerid,0);
  92. gPlayerObserving[playerid] = (-1);
  93. SendClientMessage(playerid,0xFFFFFFFF,"Leaving spectate");
  94. return;
  95. }
  96. if(gPlayerObserving[playerid] >= 0 && IsKeyJustDown(KEY_FIRE,newkeys,oldkeys)) {
  97. // They're requesting to change observer to another vehicle.
  98. ObserverSwitchToNextVehicle(playerid);
  99. }
  100. }
  101. //------------------------------------------------
  102. public OnPlayerConnect(playerid)
  103. {
  104. GameTextForPlayer(playerid,"~w~SA-MP: ~r~RC Barnstorm",5000,5);
  105. return 1;
  106. }
  107. //------------------------------------------------
  108. public OnPlayerDisconnect(playerid)
  109. {
  110. if(gPlayerVehicles[playerid]) {
  111. // Make sure their vehicle is destroyed when they leave.
  112. DestroyVehicle(gPlayerVehicles[playerid]);
  113. gPlayerVehicles[playerid] = 0;
  114. }
  115. return 0;
  116. }
  117. //------------------------------------------------
  118. //rcbarron = 464
  119. public OnPlayerSpawn(playerid)
  120. {
  121. // Create their own vehicle and put them in
  122. gPlayerVehicles[playerid] = CreateVehicle(464,
  123. gSpawnPositions[playerid][0],
  124. gSpawnPositions[playerid][1],
  125. gSpawnPositions[playerid][2],
  126. gSpawnPositions[playerid][3],
  127. -1,-1,10);
  128. PutPlayerInVehicle(playerid,gPlayerVehicles[playerid],0);
  129. //ForceClassSelection(playerid); // for next time they respawn
  130. TextDrawHideForPlayer(playerid, txtObsHelper);
  131. SetPlayerWorldBounds(playerid,200.0,-300.0,200.0,-200.0);
  132. return 1;
  133. }
  134. //------------------------------------------------
  135. public OnPlayerDeath(playerid, killerid, reason)
  136. {
  137. // We need to cleanup their vehicle
  138. RemovePlayerFromVehicle(gPlayerVehicles[playerid]);
  139. DestroyVehicle(gPlayerVehicles[playerid]);
  140. gPlayerVehicles[playerid] = 0;
  141. // Send the death information to all clients
  142. SendDeathMessage(killerid,playerid,reason);
  143. // If anyone was observing them, they'll have to switch to the next
  144. new x=0;
  145. while(x!=MAX_PLAYERS) {
  146. if(x != playerid && gPlayerObserving[x] == playerid) {
  147. ObserverSwitchToNextVehicle(x);
  148. }
  149. x++;
  150. }
  151. return 1;
  152. }
  153. //------------------------------------------------
  154. public OnPlayerRequestClass(playerid, classid)
  155. {
  156. // put them straight into observer mode, effectively
  157. // bypassing class selection.
  158. TogglePlayerSpectating(playerid,1);
  159. ObserverSwitchToNextVehicle(playerid);
  160. TextDrawShowForPlayer(playerid, txtObsHelper);
  161. // also force this dud spawn info upon them so that they
  162. // have spawn information set.
  163. SetSpawnInfo(playerid,0,0,
  164. gSpawnPositions[playerid][0],
  165. gSpawnPositions[playerid][1],
  166. gSpawnPositions[playerid][2],
  167. gSpawnPositions[playerid][3],
  168. -1,-1,-1,-1,-1,-1);
  169. return 0;
  170. }
  171. //------------------------------------------------
  172. public OnGameModeInit()
  173. {
  174. SetGameModeText("RC Barnstorm");
  175. // General settings for the gamemode
  176. ShowPlayerMarkers(0);
  177. ShowNameTags(1);
  178. SetWorldTime(7);
  179. SetWeather(5);
  180. // Add a dud player class
  181. AddPlayerClass(0,0.0,0.0,4.0,0.0,-1,-1,-1,-1,-1,-1);
  182. // Init our globals
  183. new x=0;
  184. while(x!=MAX_PLAYERS) {
  185. gPlayerVehicles[x] = 0;
  186. gPlayerObserving[x] = (-1);
  187. x++;
  188. }
  189. // Init our observer helper text display
  190. txtObsHelper = TextDrawCreate(20.0, 400.0,
  191. "Press ~b~~k~~PED_SPRINT~ ~w~to spawn~n~Press ~b~~k~~PED_FIREWEAPON~ ~w~to switch players");
  192. TextDrawUseBox(txtObsHelper, 0);
  193. TextDrawFont(txtObsHelper, 2);
  194. TextDrawSetShadow(txtObsHelper,0);
  195. TextDrawSetOutline(txtObsHelper,1);
  196. TextDrawBackgroundColor(txtObsHelper,0x000000FF);
  197. TextDrawColor(txtObsHelper,0xFFFFFFFF);
  198. return 1;
  199. }
  200. //------------------------------------------------
  201. public OnPlayerUpdate(playerid)
  202. {
  203. /*
  204. new Keys,ud,lr;
  205. if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING) {
  206. GetPlayerKeys(playerid,Keys,ud,lr);
  207. if(ud > 0) {
  208. SendClientMessage(playerid, 0xFFFFFFFF, "DOWN");
  209. }
  210. else if(ud < 0) {
  211. SendClientMessage(playerid, 0xFFFFFFFF, "UP");
  212. }
  213. if(lr > 0) {
  214. SendClientMessage(playerid, 0xFFFFFFFF, "RIGHT");
  215. }
  216. else if(lr < 0) {
  217. SendClientMessage(playerid, 0xFFFFFFFF, "LEFT");
  218. }
  219. }*/
  220. return 1;
  221. }
  222. //------------------------------------------------