Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.29 KB | None | 0 0
  1. /*******************************************************************************
  2. *                                                                              *
  3. *               #Nome script:     Fuel System                                  *
  4. *               #Versione script: 0.1                                          *
  5. *               #Autore script:   ~Peppinux AKA Peppe_Stasu                    *
  6. *               #Ringraziamenti:                                               *
  7. *                               Francesco_Ronaldo - Idea script                *
  8. *                               Los Angeles RolePlay - Coordinate rifornimenti *
  9. *                                                                              *
  10. *               # Vietato rimuovere i crediti. #                               *
  11. *                                                                              *
  12. *******************************************************************************/
  13.  
  14. //******************************************************************************
  15.  
  16. #include <a_samp>
  17.  
  18. //******************************************************************************
  19.  
  20. forward scaloBenzina(vehicleid);
  21.  
  22. //==============================================================================
  23.  
  24. new
  25.     vFuel[MAX_VEHICLES],
  26.     pFuelTimer[MAX_PLAYERS];
  27.  
  28. //******************************************************************************
  29.  
  30. public OnFilterScriptInit()
  31. {
  32.     print("\n================================"),
  33.     print("| Fuel System v0.1             |"),
  34.     print("| By ~Peppinux AKA Peppe_Stasu |"),
  35.     print("| Caricato con successo!       |"),
  36.     print("================================\n");
  37.     for(new i = 1; i < MAX_VEHICLES; i++) vFuel[i] = 100;
  38.     return 1;
  39. }
  40.  
  41. //==============================================================================
  42.  
  43. public OnFilterScriptExit()
  44. {
  45.     print("\n================================"),
  46.     print("| Fuel System v0.1             |"),
  47.     print("| By ~Peppinux AKA Peppe_Stasu |"),
  48.     print("| Rimosso con successo!        |"),
  49.     print("================================\n");
  50.     return 1;
  51. }
  52.  
  53. //==============================================================================
  54.  
  55. public OnPlayerDisconnect(playerid, reason)
  56. {
  57.     if(IsPlayerInAnyVehicle(playerid)) KillTimer(pFuelTimer[playerid]);
  58.     return 1;
  59. }
  60.  
  61. //==============================================================================
  62.  
  63. public OnPlayerCommandText(playerid, cmdtext[])
  64. {
  65.     new
  66.         cmd[256],
  67.         idx;
  68.     cmd = strtok(cmdtext, idx);
  69.  
  70.     if(!strcmp(cmdtext, "/serbatoio", true))
  71.     {
  72.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  73.         new string[128];
  74.         format(string, 128, "{00FF00}INFO: {AFAFAF}Benzina attualmente presente nel sebratoio: %d.", vFuel[GetPlayerVehicleID(playerid)]),
  75.         SendClientMessage(playerid, -1, string),
  76.         SendClientMessage(playerid, -1, "{00FF00}INFO: {AFAFAF}Se hai bisogno di rifornire la tua auto di carburante digita i comandi /pieno o /benzina ad un rifornimento.");
  77.         for(new i = 0; i < MAX_PLAYERS; i++)
  78.         {
  79.             if(IsPlayerConnected(i) && (GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid)))
  80.             {
  81.                 new pName[24];
  82.                 GetPlayerName(playerid, pName, 24),
  83.                 format(string, 128, "* %s guarda l'indicatore di benzina dell'auto. *", pName),
  84.                 SendClientMessage(i, 0x00FF00FF, string);
  85.             }
  86.         }
  87.         return 1;
  88.     }
  89.  
  90.     if(!strcmp(cmdtext, "/pieno", true))
  91.     {
  92.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  93.         if(!isAtGasStation(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere ad un rifornimento.");
  94.         new
  95.             string[128],
  96.             soldiIndispensabili = (100 - vFuel[GetPlayerVehicleID(playerid)]) * 2;
  97.         if(GetPlayerMoney(playerid) < soldiIndispensabili)
  98.         {
  99.             format(string, 128, "{F60000}ERRORE: {AFAFAF}Servono $%d per fare il pieno alla tua auto attualmente.", soldiIndispensabili),
  100.             SendClientMessage(playerid, -1, string);
  101.             return 1;
  102.         }
  103.         vFuel[GetPlayerVehicleID(playerid)] = 100,
  104.         GivePlayerMoney(playerid, -soldiIndispensabili),
  105.         format(string, 128, "{00FF00}INFO: {AFAFAF}Hai fatto il pieno alla tua auto per $%d. Ricorda che per controllare la tua benzina puoi digitare /serbatoio", soldiIndispensabili),
  106.         SendClientMessage(playerid, -1, string);
  107.         return 1;
  108.     }
  109.    
  110.     if(!strcmp(cmd, "/benzina", true))
  111.     {
  112.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  113.         if(!isAtGasStation(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere ad un rifornimento.");
  114.         new
  115.             tmp[256],
  116.             ammontare;
  117.         tmp = strtok(cmdtext, idx);
  118.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "{F6D500}USO: {AFAFAF}/benzina [Ammontare]. Usa /pieno se vuoi fare direttamente il pieno.");
  119.         ammontare = strval(tmp);
  120.         if(ammontare > 100 - vFuel[GetPlayerVehicleID(playerid)]) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi inserire un numero minore della differenza tra 100 e la benzina attuale del veicolo.");
  121.         new
  122.             string[128],
  123.             soldiIndispensabili = ammontare * 2;
  124.         if(GetPlayerMoney(playerid) < soldiIndispensabili)
  125.         {
  126.             format(string, 128, "{F60000}ERRORE: {AFAFAF}Per rifornire il tuo veicolo del %d%% di benzina hai bisogno di $%d.", ammontare, soldiIndispensabili),
  127.             SendClientMessage(playerid, -1, string);
  128.             return 1;
  129.         }
  130.         vFuel[GetPlayerVehicleID(playerid)] += ammontare;
  131.         GivePlayerMoney(playerid, -soldiIndispensabili);
  132.         format(string, 128, "{00FF00}INFO: {AFAFAF}Hai aggiunto il %d%% di benzina per $%d.", ammontare, soldiIndispensabili),
  133.         SendClientMessage(playerid, -1, string);
  134.         return 1;
  135.     }
  136.    
  137.     return 0;
  138. }
  139.  
  140. //==============================================================================
  141.  
  142. public OnPlayerStateChange(playerid, newstate, oldstate)
  143. {
  144.     if(newstate == PLAYER_STATE_DRIVER) pFuelTimer[playerid] = SetTimerEx("scaloBenzina", 20*1000/*20 sec*/, true, "d", GetPlayerVehicleID(playerid));
  145.     else if(newstate == PLAYER_STATE_PASSENGER) KillTimer(pFuelTimer[playerid]);
  146.     return 1;
  147. }
  148.  
  149. //******************************************************************************
  150.  
  151. stock strtok(const string[], &index)
  152. {
  153.     new length = strlen(string);
  154.     while((index < length) && (string[index] <= ' ')) index++;
  155.     new
  156.         offset = index,
  157.         result[20];
  158.     while((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  159.     {
  160.         result[index - offset] = string[index];
  161.         index++;
  162.     }
  163.     result[index - offset] = EOS;
  164.     return result;
  165. }
  166.  
  167. //==============================================================================
  168.  
  169. isAtGasStation(playerid)
  170. {
  171.     if(IsPlayerInRangeOfPoint(playerid, 10.0, 1004.0070, -939.3102, 42.1797) || IsPlayerInRangeOfPoint(playerid, 10.0, 1944.3260, -1772.9254, 13.3906) || IsPlayerInRangeOfPoint(playerid, 10.0, -90.5515, -1169.4578, 2.4079) || IsPlayerInRangeOfPoint(playerid, 10.0, -1609.7958, -2718.2048, 48.5391)
  172.     || IsPlayerInRangeOfPoint(playerid, 10.0, -2029.4968, 156.4366, 28.9498) || IsPlayerInRangeOfPoint(playerid, 10.0, -2408.7590, 976.0934, 45.4175) || IsPlayerInRangeOfPoint(playerid, 10.0, -2243.9629, -2560.6477, 31.8841) || IsPlayerInRangeOfPoint(playerid, 10.0, -1676.6323, 414.0262, 6.9484)
  173.     || IsPlayerInRangeOfPoint(playerid, 10.0, 2202.2349, 2474.3494, 10.5258)  || IsPlayerInRangeOfPoint(playerid, 10.0, 614.9333, 1689.7418, 6.6968)  || IsPlayerInRangeOfPoint(playerid, 10.0, -1328.8250, 2677.2173, 49.7665)  || IsPlayerInRangeOfPoint(playerid, 10.0, 70.3882, 1218.6783, 18.5165)
  174.     || IsPlayerInRangeOfPoint(playerid, 10.0, 2113.7390, 920.1079, 10.5255)  || IsPlayerInRangeOfPoint(playerid, 10.0, -1327.7218, 2678.8723, 50.0625) || IsPlayerInRangeOfPoint(playerid, 10.0, 656.4265, -559.8610, 16.5015) || IsPlayerInRangeOfPoint(playerid, 10.0, 656.3797, -570.4138, 16.5015))
  175.     return 1; // Coordinate by Los Angeles RolePlay
  176.     return 0;
  177. }
  178.  
  179. //==============================================================================
  180.  
  181. getVehicleDriver(vehicleid)
  182. {
  183.     for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
  184.     return -1;
  185. }
  186.  
  187. //==============================================================================
  188.  
  189. public scaloBenzina(vehicleid)
  190. {
  191.     if(vFuel[vehicleid] > 0) vFuel[vehicleid]--;
  192.     switch(vFuel[vehicleid])
  193.     {
  194.         case 30: SendClientMessage(getVehicleDriver(vehicleid), -1, "{F60000}ATTENZIONE: {AFAFAF}La percentuale di benzina del tuo veicolo è pari al 30%%. Ti consigliamo di fare il /pieno.");
  195.         case 20: SendClientMessage(getVehicleDriver(vehicleid), -1, "{F60000}ATTENZIONE: {AFAFAF}La percentuale di benzina del tuo veicolo è pari al 20%%. Ti consigliamo di fare il /pieno.");
  196.         case 10: SendClientMessage(getVehicleDriver(vehicleid), -1, "{F60000}ATTENZIONE: {AFAFAF}La percentuale di benzina del tuo veicolo è pari al 10%%. Fai il /pieno o rimarrai a piedi!");
  197.         case 5: SendClientMessage(getVehicleDriver(vehicleid), -1, "{F60000}ATTENZIONE: {AFAFAF}La percentuale di benzina del tuo veicolo è pari al 5%%. Fai subito il /pieno o resterai a piedi.");
  198.     }
  199. }
  200.  
  201. //******************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement