Guest User

Vehicle Spawner

a guest
May 28th, 2012
1,278
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. .:[Vehicle Spawner V. 1.0]:. by x96664
  3. Please don't remove my credits!
  4. Use /v to open vehicle dialog.
  5.  
  6. */
  7. #include <a_samp>
  8. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  9. //Colors
  10. #define COLOR_WHITE 0xFFFFFFAA
  11. #define COLOR_RED 0xff0000a7
  12. //RC vehicles
  13. #define RC_BANDIT   441
  14. #define RC_BARON    464
  15. #define RC_GOBLIN   501
  16. #define RC_RAIDER   465
  17. #define D_TRAM      449
  18. #define RC_TIGER    564
  19. #define RC_CAM      594
  20. //Dialogs                           I'm using bigger dialog ids to don't make conflict with your server dialogs.
  21. #define Dialog_Unique_Vehicle 10000
  22. #define Dialog_Trailers_Vehicle 10001
  23. #define Dialog_Boats_Vehicle 10002
  24. #define Dialog_Station_Vehicle 10003
  25. #define Dialog_Sport_Vehicle 10004
  26. #define Dialog_Saloon_Vehicle 10005
  27. #define Dialog_Public_Service_Vehicle 10006
  28. #define Dialog_Off-Road_Vehicle 10007
  29. #define Dialog_LowRyder_Vehicle 10008
  30. #define Dialog_Industry_Vehicle 10009
  31. #define Dialog_Convertable_Vehicle 10010
  32. #define Dialog_Bike_Vehicle 10011
  33. #define Dialog_Helicopters 10012
  34. #define Dialog_Airplanes 10013
  35. #define Dialog_Rc_Vehicle 10014
  36. #define Dialog_Vehicle 10015
  37. //Forward
  38. forward VehicleSpawner(playerid,model);
  39. //new
  40. new VehicleSpawn[MAX_PLAYERS];
  41. //vehicles
  42. new Airplanes[] = { 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513 };
  43. new Helicopters[] = { 548, 425, 417, 487, 488, 497, 563, 447, 469 };
  44. new Bikes[] = { 581, 509, 481, 462, 521, 463, 510, 522, 461, 448, 471, 468, 586 };
  45. new Industrials[] = { 499, 422, 482, 498, 609, 524, 578, 455, 403, 414, 582, 443, 514, 413, 515, 440, 543, 605, 459, 531, 408, 552, 478, 456, 554 };
  46. new Lowriders[] = { 536, 575, 534, 567, 535, 566, 576, 412 };
  47. new Offroad[] = { 568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 495 };
  48. new Pulic_Services[] = { 416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 598, 597, 599, 432, 601, 420 };
  49. new Saloons[] = { 445, 504, 401, 518, 527, 542, 507, 562, 585, 419, 526, 604, 466, 492, 474, 546, 517, 410, 551, 516, 467, 600, 426, 436, 547, 405, 580, 560, 550, 549, 540, 491, 529, 421 };
  50. new Sport[] = { 602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477 };
  51. new Station[] = { 418, 404, 479, 458, 561 };
  52. new Boats[] = { 472, 473, 493, 595, 484, 430, 453, 452, 446, 454 };
  53. new Trailers[] = { 435, 450, 591, 606, 607, 610, 569, 590, 584, 570, 608, 611 };
  54. new Unique[] = { 485, 537, 457, 483, 508, 532, 486, 406, 530, 538, 434, 545, 588, 571, 572, 423, 442, 428, 409, 574, 449, 525, 583, 539 };
  55. new RC_Vehicles[] = { 441, 464, 465, 501, 564, 594 };
  56.  
  57. public OnFilterScriptInit()
  58. {
  59.     print("\n--------------------------------------");
  60.     print("|Vehicle spawner by x96664 loaded!  |");
  61.     print("--------------------------------------\n");
  62.     SetTimer("VehicleSpawnLimiter", 1000, true);
  63.     return 1;
  64. }
  65.  
  66. public OnFilterScriptExit()
  67. {   print("\n--------------------------------------");
  68.     print("|Vehicle spawner by x96664 unloaded!  |");
  69.     print("--------------------------------------\n");
  70.     return 1;
  71. }
  72. public OnPlayerSpawn(playerid)
  73. {
  74.   SendClientMessage(playerid, COLOR_WHITE, "You can spawn a vehicle using /v.");
  75. }
  76. public OnPlayerCommandText(playerid, cmdtext[])
  77. {
  78. dcmd(v, 1,cmdtext);
  79. return 0;
  80. }
  81. dcmd_v(playerid, params[])
  82. {
  83. #pragma unused params
  84. ShowVehicleDialog(playerid);
  85. return 1;
  86. }
  87.  
  88. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  89. {
  90.  
  91.     if(newkeys == KEY_SECONDARY_ATTACK ){
  92.         if(!IsPlayerInAnyVehicle(playerid)){
  93.             new Float:x, Float:y, Float:z, vehicle;
  94.             GetPlayerPos(playerid, x, y, z );
  95.             GetVehicleWithinDistance(playerid, x, y, z, 20.0, vehicle);
  96.  
  97.             if(IsVehicleRc(vehicle)){
  98.               PutPlayerInVehicle(playerid, vehicle, 0);
  99.             }
  100.         }
  101.  
  102.         else {
  103.             new vehicleID = GetPlayerVehicleID(playerid);
  104.             if(IsVehicleRc(vehicleID) || GetVehicleModel(vehicleID) == RC_CAM){
  105.               if(GetVehicleModel(vehicleID) != D_TRAM){
  106.                 new Float:x, Float:y, Float:z;
  107.                 GetPlayerPos(playerid, x, y, z);
  108.                 SetPlayerPos(playerid, x+0.5, y, z+1.0);
  109.                 }
  110.             }
  111.         }
  112.     }
  113. }
  114. GetVehicleWithinDistance( playerid, Float:x1, Float:y1, Float:z1, Float:dist, &veh){
  115.     for(new i = 1; i < MAX_VEHICLES; i++){
  116.         if(GetVehicleModel(i) > 0){
  117.             if(GetPlayerVehicleID(playerid) != i ){
  118.             new Float:x, Float:y, Float:z;
  119.             new Float:x2, Float:y2, Float:z2;
  120.             GetVehiclePos(i, x, y, z);
  121.             x2 = x1 - x; y2 = y1 - y; z2 = z1 - z;
  122.             new Float:vDist = (x2*x2+y2*y2+z2*z2);
  123.             if( vDist < dist){
  124.             veh = i;
  125.             dist = vDist;
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
  131. IsVehicleRc( vehicleid ){
  132.   new model = GetVehicleModel(vehicleid);
  133.   switch(model){
  134.   case RC_GOBLIN, RC_BARON, RC_BANDIT, RC_RAIDER, RC_TIGER: return 1;
  135.   default: return 0;
  136.     }
  137.  
  138.   return 0;
  139. }
  140.  
  141. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  142. {
  143. if(dialogid== Dialog_Vehicle)
  144. {
  145. if ( response==1 )
  146. {
  147. if(listitem==0)ShowPlayerDialog( playerid, Dialog_Airplanes, 2, "{ffffff}Airplanes:", "Andromada\nAT-400\nBeagle\nCropduster\nDodo\nHydra\nNevada\nRustler\nShamal\nSkimmer\nStuntplane", "Select", "Back" );
  148. if(listitem==1)ShowPlayerDialog( playerid, Dialog_Helicopters, 2, "{ffffff}Helicopters:", "Cargobob\nHunter\nLeviathan\nMaverick\nNews Maverick\nPolice Maverick\nRaindance\nSeasparrow\nSparrow", "Select", "Back" );
  149. if(listitem==2)ShowPlayerDialog( playerid, Dialog_Bike_Vehicle, 2, "{ffffff}Bikes:", "BF-400\nBike\nBMX\nFaggio\nFCR-900\nFreeway\nMountain Bike\nNRG-500\nPCJ-600\nPizzaboy\nQuad\nSanchez\nWayfarer", "Select", "Back" );
  150. if(listitem==3)ShowPlayerDialog( playerid, Dialog_Convertable_Vehicle, 2, "{ffffff}Convertibles:", "Comet\nFeltzer\nStallion\nWindsor", "Select", "Back" );
  151. if(listitem==4)ShowPlayerDialog( playerid, Dialog_Industry_Vehicle, 2, "{ffffff}Industrial:", "Benson\nBobcat\nBurrito\nBoxville\nBoxburg\nCement Truck\nDFT-30\nFlatbed\nLinerunner\nMule\nNewsvan\nPacker\nPetrol Tanker\nPony\nRoadtrain\nRumpo\nSadler\nSadler Shit\nTopfun\nTractor\nTrashmaster\nUtility Van\nWalton\nYankee\nYosemite", "Select", "Back" );
  152. if(listitem==5)ShowPlayerDialog( playerid, Dialog_LowRyder_Vehicle, 2, "{ffffff}Lowriders:", "Blade\nBroadway\nRemington\nSavanna\nSlamvan\nTahoma\nTornado\nVoodoo", "Select", "Back" );
  153. if(listitem==6)ShowPlayerDialog( playerid, Dialog_Off-Road_Vehicle, 2, "{ffffff}Off Road:", "Bandito\nBF Injection\nDune\nHuntley\nLandstalker\nMesa\nMonster\nMonster A\nMonster B\nPatriot\nRancher A\nRancher B\nSandking", "Select", "Back" );
  154. if(listitem==7)ShowPlayerDialog( playerid, Dialog_Public_Service_Vehicle, 2, "{ffffff}Public Service Vehicles:", "Ambulance\nBarracks\nBus\nCabbie\nCoach\nCop Bike (HPV-1000)\nEnforcer\nFBI Rancher\nFBI Truck\nFiretruck\nFiretruck LA\nPolice Car (LSPD)\nPolice Car (LVPD)\nPolice Car (SFPD)\nRanger\nRhino\nS.W.A.T\nTaxi", "Select", "Back" );
  155. if(listitem==8)ShowPlayerDialog( playerid, Dialog_Saloon_Vehicle, 2, "{ffffff}Saloons:", "Admiral\nBlooDialog_Weapon_Riflesng Banger\nBravura\nBuccaneer\nCadrona\nClover\nElegant\nElegy\nEmperor\nEsperanto\nFortune\nGlendale Shit\nGlendale\nGreenwood\nHermes\nIntruder\nMajestic\nManana\nMerit\nNebula\nOceanic\nPicador\nPremier\nPrevion\nPrimo\nSentinel\nStafford\nSultan\nSunrise\nTampa\nVincent\nVirgo\nWillard\nWashington", "Select", "Back" );
  156. if(listitem==9)ShowPlayerDialog( playerid, Dialog_Sport_Vehicle, 2, "{ffffff}Sport Vehicles:", "Alpha\nBanshee\nBlista Compact\nBuffalo\nBullet\nCheetah\nClub\nEuros\nFlash\nHotring Racer\nHotring Racer A\nHotring Racer B\nInfernus\nJester\nPhoenix\nSabre\nSuper GT\nTurismo\nUranus\nZR-350", "Select", "Back" );
  157. if(listitem==10)ShowPlayerDialog( playerid, Dialog_Station_Vehicle, 2, "{ffffff}Station Wagons:", "Moonbeam\nPerenniel\nRegina\nSolair\nStratum", "Select", "Back" );
  158. if(listitem==11)ShowPlayerDialog( playerid, Dialog_Boats_Vehicle, 2, "{ffffff}Boats:", "Coastguard\nDinghy\nJetmax\nLaunch\nMarquis\nPredator\nReefer\nSpeeder\nSquallo\nTropic", "Select", "Back" );
  159. if(listitem==12)ShowPlayerDialog( playerid, Dialog_Trailers_Vehicle, 2, "{ffffff}Trailers:", "Article Trailer\nArticle Trailer 2\nArticle Trailer 3\nBaggage Trailer A\nBaggage Trailer B\nFarm Trailer\nFreight Flat Trailer (Train)\nFreight Box Trailer (Train)\nPetrol Trailer\nStreak Trailer (Train)\nStairs Trailer\nUtility Trailer", "Select", "Back" );
  160. if(listitem==13)ShowPlayerDialog( playerid, Dialog_Unique_Vehicle, 2, "{ffffff}Unique Vehicles:", "Baggage\nBrownstreak (Train)\nCaddy\nCamper\nCamper A\nCombine Harvester\nDozer\nDumper\nForklift\nFreight (Train)\nHotknife\nHustler\nHotdog\nKart\nMower\nMr Whoopee\nRomero\nSecuricar\nStretch\nSweeper\nTram\nTowtruck\nTug\nVortex", "Select", "Back" );
  161. if(listitem==14)ShowPlayerDialog( playerid, Dialog_Rc_Vehicle, 2, "{ffffff}RC Vehicles:", "RC Bandit\nRC Baron\nRC Raider\nRC Goblin\nRC Tiger\nRC Cam", "Select", "Back" );
  162. }
  163. }
  164. if(dialogid== Dialog_Airplanes){if ( response ){
  165. VehicleSpawner(playerid,Airplanes[ listitem ]);}}
  166. if(dialogid== Dialog_Helicopters){
  167. if ( response ){
  168. VehicleSpawner(playerid,Helicopters[ listitem ]);
  169. }else ShowVehicleDialog(playerid);
  170. }
  171. if(dialogid== Dialog_Bike_Vehicle){
  172. if ( response ){
  173. VehicleSpawner(playerid,Bikes[ listitem ]);
  174. }else ShowVehicleDialog(playerid);
  175. }
  176. if(dialogid== Dialog_Convertable_Vehicle){
  177. if ( response ){
  178. new Convertibles[] = { 480, 533, 439, 555 };
  179. VehicleSpawner(playerid,Convertibles[ listitem ]);
  180. }else ShowVehicleDialog(playerid);
  181. }
  182. if(dialogid== Dialog_Industry_Vehicle){
  183. if ( response ){
  184. VehicleSpawner(playerid,Industrials[ listitem ]);
  185. }else ShowVehicleDialog(playerid);
  186. }
  187. if(dialogid== Dialog_LowRyder_Vehicle){
  188. if ( response ){
  189. VehicleSpawner(playerid,Lowriders[ listitem ]);
  190. }else ShowVehicleDialog(playerid);
  191. }
  192. if(dialogid== Dialog_Off-Road_Vehicle){
  193. if ( response ){
  194. VehicleSpawner(playerid,Offroad[ listitem ]);
  195. }else ShowVehicleDialog(playerid);
  196. }
  197. if(dialogid== Dialog_Public_Service_Vehicle){
  198. if ( response ){
  199. VehicleSpawner(playerid,Pulic_Services[ listitem ]);
  200. }else ShowVehicleDialog(playerid);
  201. }
  202. if(dialogid== Dialog_Saloon_Vehicle){
  203. if ( response ){
  204. VehicleSpawner(playerid,Saloons[ listitem ]);
  205. }else ShowVehicleDialog(playerid);
  206. }
  207. if(dialogid== Dialog_Sport_Vehicle){
  208. if ( response ){
  209. VehicleSpawner(playerid,Sport[ listitem ]);
  210. }else ShowVehicleDialog(playerid);
  211. }
  212. if(dialogid== Dialog_Station_Vehicle){
  213. if ( response ){
  214. VehicleSpawner(playerid,Station[ listitem ]);
  215. }else ShowVehicleDialog(playerid);
  216. }
  217. if(dialogid== Dialog_Boats_Vehicle){
  218. if ( response ){
  219. VehicleSpawner(playerid,Boats[ listitem ]);
  220. }else ShowVehicleDialog(playerid);
  221. }
  222. if(dialogid== Dialog_Trailers_Vehicle){
  223. if ( response ){
  224. VehicleSpawner(playerid,Trailers[ listitem ]);
  225. }else ShowVehicleDialog(playerid);
  226. }
  227. if(dialogid== Dialog_Unique_Vehicle){
  228. if ( response ){
  229. VehicleSpawner(playerid,Unique[ listitem ]);
  230. }else ShowVehicleDialog(playerid);
  231. }
  232. if(dialogid== Dialog_Rc_Vehicle){
  233. if ( response ){
  234. VehicleSpawner(playerid,RC_Vehicles[ listitem ]);
  235. }else ShowVehicleDialog(playerid);
  236. }
  237. return 1;
  238. }
  239.  
  240. stock ShowVehicleDialog(playerid)
  241. {
  242. ShowPlayerDialog(playerid, Dialog_Vehicle, 2, "{ffffff}Vehicle categories:", "Airplanes\nHelicopters\nBikes\nConvertibles\nIndustrial\nLowriders\nOff Road\nPublic Service Vehicles\nSaloons\nSport Vehicles\nStation Wagons\nBoats\nTrailers\nUnique Vehicles\nRC Vehicles", "Select", "Back" );
  243. }
  244.  
  245. public VehicleSpawner(playerid,model){
  246.     if(IsPlayerInAnyVehicle(playerid)){
  247.         SendClientMessage(playerid, COLOR_RED, "Error: You're already in vehicle!");
  248.     }
  249.     else{
  250.     if(VehicleSpawn[playerid]==0){
  251.     new Float:x,Float:y,Float:z,Float:a, vehicleid;
  252.     GetPlayerPos(playerid,x,y,z);
  253.     GetPlayerFacingAngle(playerid,a);
  254.     vehicleid = CreateVehicle(model,x+1,y+1,z,a,-1,-1,-1);
  255.     PutPlayerInVehicle(playerid, vehicleid, 0);
  256.     SetVehicleHealth(vehicleid,  1000.0);
  257.     LinkVehicleToInterior(vehicleid, GetPlayerInterior(playerid));
  258.     }
  259.   }
  260. }
RAW Paste Data