Advertisement
moustachauve

Fuel system

Dec 6th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.60 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5.  
  6. #define SQL_HOST "localhost"
  7. #define SQL_USER "root"
  8. #define SQL_PASS "toto91"
  9. #define SQL_DB "samp"
  10.  
  11. new timer_gaz;
  12.  
  13. public OnVehicleSpawn(vehicleid)
  14. {
  15.     new query[200];
  16.     format(query, sizeof(query), "DELETE FROM `car` WHERE `id` = %i LIMIT 1;", vehicleid);
  17.     mysql_query(query);
  18.     return 1;
  19. }
  20.  
  21. public gaz(vehicleid) {
  22.     new query[200];
  23.     format(query, sizeof(query), "SELECT gas FROM `car` WHERE `id` = %i", vehicleid);
  24.     mysql_query(query);
  25.     mysql_store_result();
  26.     new gas = mysql_fetch_int();
  27.     mysql_free_result();
  28.     printf("%i", gas);
  29.     if(gas > 0) {
  30.         if((gas-1) > 1) {
  31.             gas = 0;
  32.             new engine, lights, alarm, doors, bonnet, boot, objective;
  33.             GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  34.             SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
  35.             new query1[200];
  36.             format(query1, sizeof(query1), "UPDATE `car` SET `gas` = %i WHERE `id` = %i;", gas, vehicleid);
  37.             mysql_query(query1);
  38.             printf("%i", gas);
  39.         }
  40.         else {
  41.             gas = gas-1;
  42.             new query1[200];
  43.             format(query1, sizeof(query1), "UPDATE `car` SET `gas` = %i WHERE `id` = %i;", gas, vehicleid);
  44.             mysql_query(query1);
  45.             printf("%i", gas);
  46.         }
  47.     }
  48.     return 1;
  49. }
  50.  
  51. forward gaz(vehicleid);
  52.  
  53. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  54. {
  55.     if(!ispassenger) {
  56.        
  57.         new query1[200];
  58.         format(query1, sizeof(query1), "SELECT * FROM `car` WHERE `id` = %i", vehicleid);
  59.         mysql_query(query1);
  60.         mysql_store_result();
  61.         new rows = mysql_num_rows();
  62.         mysql_free_result();
  63.         if(!rows) {
  64.             new query2[200];
  65.             format(query2, sizeof(query2), "INSERT INTO car (id, owner, gas) VALUES ('%i', '%i', 100)", vehicleid, playerid);
  66.             mysql_query(query2);
  67.         }
  68.         else {
  69.             timer_gaz = SetTimerEx("gaz", 2150, true, "i", vehicleid);
  70.         }
  71.     }
  72.     return 1;
  73. }
  74.  
  75. public OnPlayerExitVehicle(playerid, vehicleid) {
  76.     KillTimer(timer_gaz);
  77.     return 1;
  78. }
  79.  
  80. public OnFilterScriptInit()
  81. {
  82.     print("\n--------------------------------------");
  83.     print("Car system by Moustachauve");
  84.     print("--------------------------------------\n");
  85.     mysql_debug(1);
  86.     mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  87.     mysql_query("TRUNCATE TABLE `car`");
  88.     print("Table 'Car' videe avec succes !");
  89.     return 1;
  90. }
  91.  
  92. public OnFilterScriptExit()
  93. {
  94.     mysql_query("TRUNCATE TABLE `car`");
  95.     print("Table 'Car' videe avec succes !");
  96.     mysql_close();
  97.     print("Connexion avec la base terminé.");
  98.     return 1;
  99. }
  100.  
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement