Advertisement
Jujuv

[SA:MP | DROPED] Dynamic Vehicles

May 22nd, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.66 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5.  
  6. /*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Message de l'auteur]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
  7.  
  8. Ce systeme se veux relativement simpliste.Il existe surement beaucoups de moyens d'optimiser la vitesse d'execution de celui-ci sans même passer par le moindre plugin.
  9. Il existe surement des optimisations possibles sans même utiliser de bibliotheques supplémentaires.si vous désirez améliorer/modifier celui-ci, vous y êtes invités!
  10. Ce script n'est soumis à AUCUNES licences et je renonce à mes droits de propriété intelectuele car il me semble que la lois française me donne des droits de propriétés à défaut de licence.
  11.  
  12. Partagez le, modifiez le, hackez le, vendsez le mais surtout apréciez le!
  13.  
  14. Concernant la vente, il n'y qu'une limite: votre moral !
  15.  
  16. J'ai choisie l'utilisation de JSON (by DracoBlue) pour ses performances et sa simplicité d'utilisation.
  17. De même pour ZCMD.
  18.  
  19. //--------------------------------------------------------------------------For English Readers-------------------------------------------------------------------------//
  20.  
  21. For my english readers: This system is pretty simple and you may find many ways to improve the code without using more library(s) and/or plugin(s) and if you want to improve it by yourself: do it!
  22. This script is FREE and you may do everything you want with!
  23.  
  24. Share it, Use it, sell it, hack it, but LOVE IT !
  25.  
  26. About selling: there is only one limit: your soul!
  27.  
  28. BTW, sorry for my bad english (^_^)
  29.  
  30. ------------------------------------------------------------------------Message to sa:mp team--------------------------------------------------------------------//
  31.  
  32. @Sa:Mp admin team: if u read this message (i think you will never ...) please tell WHY THE HELL I GOT BANNED FROM UR FORUM ?
  33. I have just asked about sa:mp major issues to tell my opinion and i got banned without any reason!
  34.  
  35. I'm Jujuv and i have done a new account wich will probably spot.
  36.  
  37.  
  38. //-------------------------------------------------------------------------Anyway------------------------------------------------------------------------------//
  39.  
  40. Have fun and remember to play only for fun !
  41. Jujuv.
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. */
  49. //--------------------------------------------------------------------------------Inclusion de bibliotheques--------------------------------------------------------------//
  50. #include <a_samp>
  51. #include <djson>
  52. #include <zcmd>
  53.  
  54.  
  55. //-------------------------------------------------------------------------------definitions de macros-------------------------------------------------------------------//
  56.  
  57. #define VEHFILE "vehicles.json"
  58.  
  59. /*Properties*/
  60. #define VEH_RESPAWN_DELAY 60
  61.  
  62. /*Dialog IDs*/
  63. #define DIALOG_CAR_COLOR_CHOOSE 1       /*Ces macro permetent de régler facilement les conflits d'IDs si vous utilisez d'autres boites de dialogue*/
  64. #define DIALOG_CAR_COLOR_CHOOSE_SECOND 2
  65.  
  66. /*Colors*/
  67. #define COLOR_RED 0xD70000FF
  68. #define COLOR_YELLOW 0xFBEE04FF
  69.  
  70. //----------------------------------------------------------------------------------Structures d'enumerations----------------------------------------------------------------------------------//
  71. enum E_VEH_DATA
  72. {
  73.     registered,
  74.     colour1,
  75.     colour2
  76. }
  77.  
  78. //-----------------------------------------------------------------------------Variables & tableaux globaux-------------------------------------------------------------------//
  79. new vehInfo[MAX_VEHICLES][E_VEH_DATA];
  80. //----------------------------------------------------------------------------Debut des callbacks et fonctions----------------------------------------------------------------//
  81.  
  82. #if defined FILTERSCRIPT
  83.  
  84. public OnFilterScriptInit()
  85. {
  86.     print("\n--------------------------------------");
  87.     print(" Blank Filterscript by your name here");
  88.     print("--------------------------------------\n");
  89.     return 1;
  90. }
  91.  
  92. public OnFilterScriptExit()
  93. {
  94.     return 1;
  95. }
  96.  
  97. #else
  98.  
  99. main()
  100. {
  101.     print("\n----------------------------------");
  102.     print(" Simple Dynamic Vehicles System");
  103.     print("----------------------------------\n");
  104. }
  105.  
  106. #endif
  107.  
  108. public OnGameModeInit()
  109. {
  110.     djson_GameModeInit();//DO NOT REMOVE ! THIS IS NEEDED BY DJSON LIBRARY !
  111.     if(!fexist(VEHFILE)) { djCreateFile(VEHFILE); print("Vehicle file created"); djSetInt(VEHFILE, "Total", 0);}
  112.     else{ LoadRegisteredVehicles(); }
  113.     return 1;
  114. }
  115.  
  116. public OnGameModeExit()
  117. {
  118.     djson_GameModeExit();//DO NOT REMOVE ! THIS IS NEEDED BY DJSON LIBRARY !
  119.     return 1;
  120. }
  121.  
  122. public OnPlayerRequestClass(playerid, classid)
  123. {
  124.  
  125.     //don't use theses lines if it's a filterscript
  126.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  127.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  128.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  129.     return 1;
  130. }
  131.  
  132. public OnPlayerConnect(playerid)
  133. {
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerDisconnect(playerid, reason)
  138. {
  139.     return 1;
  140. }
  141.  
  142. public OnPlayerSpawn(playerid)
  143. {
  144.     return 1;
  145. }
  146.  
  147. public OnPlayerDeath(playerid, killerid, reason)
  148. {
  149.     return 1;
  150. }
  151.  
  152. public OnVehicleSpawn(vehicleid)
  153. {
  154.     return 1;
  155. }
  156.  
  157. public OnVehicleDeath(vehicleid, killerid)
  158. {
  159.     return 1;
  160. }
  161.  
  162. public OnPlayerText(playerid, text[])
  163. {
  164.     return 1;
  165. }
  166.  
  167. /*Don't use OnPlayerCommandText callback ! ZCMD disalow use of this callback !*/
  168.  
  169. /*
  170. public OnPlayerCommandText(playerid, cmdtext[])
  171. {
  172.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  173.     {
  174.         // Do something here
  175.         return 1;
  176.     }
  177.     return 0;
  178. }
  179. */
  180. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  181. {
  182.     return 1;
  183. }
  184.  
  185. public OnPlayerExitVehicle(playerid, vehicleid)
  186. {
  187.     return 1;
  188. }
  189.  
  190. public OnPlayerStateChange(playerid, newstate, oldstate)
  191. {
  192.     return 1;
  193. }
  194.  
  195. public OnPlayerEnterCheckpoint(playerid)
  196. {
  197.     return 1;
  198. }
  199.  
  200. public OnPlayerLeaveCheckpoint(playerid)
  201. {
  202.     return 1;
  203. }
  204.  
  205. public OnPlayerEnterRaceCheckpoint(playerid)
  206. {
  207.     return 1;
  208. }
  209.  
  210. public OnPlayerLeaveRaceCheckpoint(playerid)
  211. {
  212.     return 1;
  213. }
  214.  
  215. public OnRconCommand(cmd[])
  216. {
  217.     return 1;
  218. }
  219.  
  220. public OnPlayerRequestSpawn(playerid)
  221. {
  222.     return 1;
  223. }
  224.  
  225. public OnObjectMoved(objectid)
  226. {
  227.     return 1;
  228. }
  229.  
  230. public OnPlayerObjectMoved(playerid, objectid)
  231. {
  232.     return 1;
  233. }
  234.  
  235. public OnPlayerPickUpPickup(playerid, pickupid)
  236. {
  237.     return 1;
  238. }
  239.  
  240. public OnVehicleMod(playerid, vehicleid, componentid)
  241. {
  242.     return 1;
  243. }
  244.  
  245. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  246. {
  247.     return 1;
  248. }
  249.  
  250. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  251. {
  252.     return 1;
  253. }
  254.  
  255. public OnPlayerSelectedMenuRow(playerid, row)
  256. {
  257.     return 1;
  258. }
  259.  
  260. public OnPlayerExitedMenu(playerid)
  261. {
  262.     return 1;
  263. }
  264.  
  265. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  266. {
  267.     return 1;
  268. }
  269.  
  270. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  271. {
  272.     return 1;
  273. }
  274.  
  275. public OnRconLoginAttempt(ip[], password[], success)
  276. {
  277.     return 1;
  278. }
  279.  
  280. public OnPlayerUpdate(playerid)
  281. {
  282.     return 1;
  283. }
  284.  
  285. public OnPlayerStreamIn(playerid, forplayerid)
  286. {
  287.     return 1;
  288. }
  289.  
  290. public OnPlayerStreamOut(playerid, forplayerid)
  291. {
  292.     return 1;
  293. }
  294.  
  295. public OnVehicleStreamIn(vehicleid, forplayerid)
  296. {
  297.     return 1;
  298. }
  299.  
  300. public OnVehicleStreamOut(vehicleid, forplayerid)
  301. {
  302.     return 1;
  303. }
  304. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  305. {
  306.     return 1;
  307. }
  308.  
  309.  
  310. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  311. {
  312.     switch(dialogid)
  313.     {
  314.         case DIALOG_CAR_COLOR_CHOOSE:
  315.         {
  316.             new colorID = strval(inputtext);
  317.             if(colorID >= 0 && colorID <= 126)
  318.             {
  319.                 SetPVarInt(playerid, "firstCarColor", colorID);
  320.                 ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE_SECOND, DIALOG_STYLE_INPUT, "Choose color ID", "Please enter a second color for your vehicle (color ID)", "Ok", "");
  321.             }
  322.             else { ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE, DIALOG_STYLE_INPUT, "Wrong color ID", "Please enter a valid color ID (0-126)", "Ok", ""); }
  323.         }
  324.         case DIALOG_CAR_COLOR_CHOOSE_SECOND:
  325.         {
  326.             new colorID = strval(inputtext);
  327.             if(colorID >= 0 && colorID <= 126)
  328.             {
  329.                 new Float:x, Float:y, Float:z, Float:fA, vehID;
  330.                 GetPlayerPos(playerid, x, y, z);
  331.                 GetPlayerFacingAngle(playerid, fA);
  332.                
  333.                 vehID = CreateVehicle(GetPVarInt(playerid, "carModelID"), x, y, z, fA, GetPVarInt(playerid, "firstCarColor"), colorID, VEH_RESPAWN_DELAY);
  334.                 PutPlayerInVehicle(playerid, vehID, 0);
  335.             }
  336.             else { ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE_SECOND, DIALOG_STYLE_INPUT, "Wrong color ID", "Please enter a valid color ID (0-126)", "Ok", ""); }
  337.         }
  338.     }
  339.     return 1;
  340. }
  341.  
  342.  
  343. stock LoadRegisteredVehicles()
  344. {
  345.     new str[20], model, Float:x, Float:y, Float:z, Float:a, vehID, color1, color2, total;
  346.    
  347.     print("function called and executed");
  348.     total = djInt(VEHFILE, "Total");
  349.     printf("Total vehicles : %i", total);
  350.     for(new i = 0; i <= total; i++)
  351.     {
  352.         print("one more loop");
  353.         printf("%i loop(s)", i);
  354.         format(str, sizeof(str), "%i/model", i);
  355.         model = djInt(VEHFILE, str);
  356.         if(model != -1)
  357.         {
  358.             print("block is executed");
  359.             format(str, sizeof(str), "%i/axes/x", i);
  360.             x = djFloat(VEHFILE, str);
  361.             print("1");
  362.             format(str, sizeof(str), "%i/axes/y", i);
  363.             y = djFloat(VEHFILE, str);
  364.             print("2");
  365.             format(str, sizeof(str), "%i/axes/z", i);
  366.             z = djFloat(VEHFILE, str);
  367.             print("3");
  368.             format(str, sizeof(str), "%i/axes/facingAngle", i);
  369.             a = djFloat(VEHFILE, str);
  370.             print("4");
  371.             format(str, sizeof(str), "%i/colors/1", i);
  372.             color2 = djInt(VEHFILE, str);
  373.             print("5");
  374.             format(str, sizeof(str), "%i/colors/2", i);
  375.             color1 = djInt(VEHFILE, str);
  376.             print("6");
  377.  
  378.             vehID = CreateVehicle(model, x, y, z, a, color1, color2, VEH_RESPAWN_DELAY);
  379.             print("7");
  380.  
  381.             vehInfo[vehID][registered] = true;
  382.             print("8");
  383.             vehInfo[vehID][colour1] = color1;
  384.             print("9");
  385.             vehInfo[vehID][colour2] = color2;
  386.             print("10");
  387.            
  388.             print("Not realy end of block ...");
  389.             printf("%i vehicles loaded", i);
  390.             print("End of block is executed too");
  391.  
  392.            
  393.         }
  394.      }
  395. }
  396. stock IsVehicleRegistered(vehID)
  397. {
  398.     if(vehInfo[vehID][registered]) { return true; }
  399.     else { return false; }
  400. }
  401.  
  402. stock RegisterVehicle(vehID)
  403. {
  404.     if(!IsVehicleRegistered(vehID))
  405.     {
  406.         new model, Float:x, Float:y, Float:z, Float:fA, total, str[20], i;
  407.         model = GetVehicleModel(vehID);
  408.         GetVehiclePos(vehID, x, y, z);
  409.         GetVehicleZAngle(vehID, fA);
  410.        
  411.         total = djInt(VEHFILE, "Total");
  412.         for(i = total; i > 0; i--)
  413.         {
  414.             format(str, sizeof(str), "%i/model", i);
  415.            
  416.             if(djInt(VEHFILE, str) == -1) {break;}
  417.         }
  418.        
  419.         if(i == 0)
  420.           {
  421.                 i = total+1;
  422.           }
  423.        
  424.         format(str, sizeof(str), "%i/model", i);
  425.         djSetInt(VEHFILE, str, model);
  426.         format(str, sizeof(str), "%i/axes/x", i);
  427.         djSetFloat(VEHFILE, str, x);
  428.         format(str, sizeof(str), "%i/axes/y", i);
  429.         djSetFloat(VEHFILE, str, y);
  430.         format(str, sizeof(str), "%i/axes/z", i);
  431.         djSetFloat(VEHFILE, str, z);
  432.         format(str, sizeof(str), "%i/axes/facingAngle", i);
  433.         djSetFloat(VEHFILE, str, fA);
  434.         format(str, sizeof(str), "%i/colors/1", i);
  435.         djSetInt(VEHFILE, str, vehInfo[vehID][colour1]);
  436.         format(str, sizeof(str), "%i/colors/2", i);
  437.         djSetInt(VEHFILE, str, vehInfo[vehID][colour2]);
  438.  
  439.         vehInfo[vehID][registered] = true;
  440.        
  441.         djSetInt(VEHFILE, "Total", djInt(VEHFILE, "Total")+1 );
  442.  
  443.        
  444.         return true;
  445.     }
  446.     else{ return false; }
  447. }
  448.  
  449. COMMAND:v(playerid, params[])
  450. {
  451.     if(isnull(params)) { SendClientMessage(playerid, COLOR_YELLOW, "Usage: /v [modelID]");}
  452.     else if(IsPlayerAdmin(playerid))//Adaptez cette condition à votre systeme d'admin'
  453.     {
  454.         new modelID = strval(params);
  455.         if(modelID >= 400 && modelID <= 611)
  456.         {
  457.             SetPVarInt(playerid, "carModelID", modelID);
  458.             ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE, DIALOG_STYLE_INPUT, "Select a color", "Please enter a first color for your vehicle (color ID)", "Ok", "");
  459.         }
  460.         else { SendClientMessage(playerid, COLOR_YELLOW, "Please enter a valid vehicle model ID"); }
  461.     }
  462.     else { SendClientMessage(playerid, COLOR_RED, "You must e dmin to use this command"); }
  463.    
  464.     return 1;
  465. }
  466.  
  467. COMMAND:register(playerid, params[])
  468. {
  469.     if(IsPlayerAdmin(playerid))//Adaptez cette condition à votre systeme d'admin'
  470.     {
  471.         if(IsPlayerInAnyVehicle(playerid))
  472.         {
  473.  
  474.             new response =  RegisterVehicle(GetPlayerVehicleID(playerid));
  475.             if(response) { SendClientMessage(playerid, COLOR_YELLOW, "Vehicle registered");}
  476.             else { SendClientMessage(playerid, COLOR_RED, "This vehicle is allready registered"); }
  477.         }
  478.         else{ SendClientMessage(playerid, COLOR_RED, "You must be in any vehicle to do that !");}
  479.     }
  480.     else { SendClientMessage(playerid, COLOR_RED, "You must e dmin to use this command"); }
  481.    
  482.     return 1;
  483. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement