Advertisement
Guest User

Fuel System v0.2 by ~Peppinux AKA Peppe_Stasu

a guest
Feb 23rd, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.29 KB | None | 0 0
  1. /*******************************************************************************
  2. *                                                                              *
  3. *               #Nome script:     Fuel System                                  *
  4. *               #Versione script: 0.2                                          *
  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.     bool:pAvvisato[MAX_PLAYERS];
  28.  
  29. //******************************************************************************
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n================================"),
  34.     print("| Fuel System v0.2             |"),
  35.     print("| By ~Peppinux AKA Peppe_Stasu |"),
  36.     print("| Caricato con successo!       |"),
  37.     print("================================\n");
  38.     for(new i = 1; i < MAX_VEHICLES; i++) if(i != INVALID_VEHICLE_ID) vFuel[i] = 100;
  39.     return 1;
  40. }
  41.  
  42. //==============================================================================
  43.  
  44. public OnFilterScriptExit()
  45. {
  46.     print("\n================================"),
  47.     print("| Fuel System v0.2             |"),
  48.     print("| By ~Peppinux AKA Peppe_Stasu |"),
  49.     print("| Rimosso con successo!        |"),
  50.     print("================================\n");
  51.     return 1;
  52. }
  53.  
  54. //==============================================================================
  55.  
  56. public OnPlayerDisconnect(playerid, reason)
  57. {
  58.     if(IsPlayerInAnyVehicle(playerid)) KillTimer(pFuelTimer[playerid]);
  59.     return 1;
  60. }
  61.  
  62. //==============================================================================
  63.  
  64. public OnPlayerCommandText(playerid, cmdtext[])
  65. {
  66.     new
  67.         cmd[256],
  68.         idx;
  69.     cmd = strtok(cmdtext, idx);
  70.  
  71.     if(!strcmp(cmdtext, "/serbatoio", true))
  72.     {
  73.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  74.         new string[128];
  75.         format(string, sizeof(string),  "{00FF00}INFO: {AFAFAF}Benzina attualmente presente nel sebratoio: %d.", vFuel[GetPlayerVehicleID(playerid)]),
  76.         SendClientMessage(playerid, -1, string),
  77.         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.");
  78.         for(new i = 0; i < MAX_PLAYERS; i++)
  79.         {
  80.             if(IsPlayerConnected(i) && (GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid)))
  81.             {
  82.                 new pName[MAX_PLAYER_NAME];
  83.                 GetPlayerName(playerid, pName, sizeof(pName)),
  84.                 format(string, sizeof(string),  "* %s guarda l'indicatore di benzina dell'auto. *", pName),
  85.                 SendClientMessage(i, 0x00FF00FF, string);
  86.             }
  87.         }
  88.         return 1;
  89.     }
  90.  
  91.     if(!strcmp(cmdtext, "/pieno", true))
  92.     {
  93.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  94.         if(!isPlayerAtGasStation(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere ad un rifornimento.");
  95.         new
  96.             string[128],
  97.             soldiIndispensabili = (100 - vFuel[GetPlayerVehicleID(playerid)]) * 2;
  98.         if(GetPlayerMoney(playerid) < soldiIndispensabili)
  99.         {
  100.             format(string, sizeof(string),  "{F60000}ERRORE: {AFAFAF}Servono $%d per fare il pieno alla tua auto attualmente.", soldiIndispensabili),
  101.             SendClientMessage(playerid, -1, string);
  102.             return 1;
  103.         }
  104.         vFuel[GetPlayerVehicleID(playerid)] = 100,
  105.         GivePlayerMoney(playerid, -soldiIndispensabili),
  106.         format(string, sizeof(string),  "{00FF00}INFO: {AFAFAF}Hai fatto il pieno alla tua auto per $%d. Ricorda che per controllare la tua benzina puoi digitare /serbatoio", soldiIndispensabili),
  107.         SendClientMessage(playerid, -1, string);
  108.         return 1;
  109.     }
  110.    
  111.     if(!strcmp(cmd, "/benzina", true))
  112.     {
  113.         if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere in un veicolo.");
  114.         if(!isPlayerAtGasStation(playerid)) return SendClientMessage(playerid, -1, "{F60000}ERRORE: {AFAFAF}Devi essere ad un rifornimento.");
  115.         new
  116.             tmp[256],
  117.             ammontare;
  118.         tmp = strtok(cmdtext, idx);
  119.         if(!strlen(tmp)) return SendClientMessage(playerid, -1, "{F6D500}USO: {AFAFAF}/benzina [Ammontare]. Usa /pieno se vuoi fare direttamente il pieno.");
  120.         ammontare = strval(tmp);
  121.         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.");
  122.         new
  123.             string[128],
  124.             soldiIndispensabili = ammontare * 2;
  125.         if(GetPlayerMoney(playerid) < soldiIndispensabili)
  126.         {
  127.             format(string, sizeof(string),  "{F60000}ERRORE: {AFAFAF}Per rifornire il tuo veicolo del %d%% di benzina hai bisogno di $%d.", ammontare, soldiIndispensabili),
  128.             SendClientMessage(playerid, -1, string);
  129.             return 1;
  130.         }
  131.         vFuel[GetPlayerVehicleID(playerid)] += ammontare;
  132.         GivePlayerMoney(playerid, -soldiIndispensabili);
  133.         format(string, sizeof(string),  "{00FF00}INFO: {AFAFAF}Hai aggiunto il %d%% di benzina per $%d.", ammontare, soldiIndispensabili),
  134.         SendClientMessage(playerid, -1, string);
  135.         return 1;
  136.     }
  137.    
  138.     if(!strcmp(cmdtext, "/pienoall", true))
  139.     {
  140.         new
  141.             string[128],
  142.             pName[MAX_PLAYER_NAME];
  143.         for(new i = 1; i < MAX_VEHICLES; i++) if(i != INVALID_VEHICLE_ID) vFuel[i] = 100;
  144.         GetPlayerName(playerid, pName, sizeof(pName));
  145.         format(string, sizeof(string), "{F60000}AVVISO: {AFAFAF}L'Admin %s ha rifornito tutti i veicoli di benzina al 100%%.", pName);
  146.         return 1;
  147.     }
  148.    
  149.     return 0;
  150. }
  151.  
  152. //==============================================================================
  153.  
  154. public OnPlayerStateChange(playerid, newstate, oldstate)
  155. {
  156.     if(newstate == PLAYER_STATE_DRIVER) pFuelTimer[playerid] = SetTimerEx("scaloBenzina", 20*1000/*20 sec*/, true, "d", GetPlayerVehicleID(playerid));
  157.     else if(newstate == PLAYER_STATE_PASSENGER) KillTimer(pFuelTimer[playerid]);
  158.     return 1;
  159. }
  160.  
  161. //==============================================================================
  162.  
  163. public OnPlayerUpdate(playerid)
  164. {
  165.     if(isPlayerAtGasStation(playerid))
  166.     {
  167.         pAvvisato[playerid] = true;
  168.         SendClientMessage(playerid, -1, "{00FF00}INFO: {AFAFAF}Benvenuto ad un rifornimento. Qui puoi usare i comandi /pieno e /benzina [Ammontare].");
  169.     }
  170.     else
  171.     {
  172.         if(pAvvisato[playerid] == true) pAvvisato[playerid] = false;
  173.     }
  174.     return 1;
  175. }
  176.  
  177. //******************************************************************************
  178.  
  179. stock strtok(const string[], &index)
  180. {
  181.     new length = strlen(string);
  182.     while((index < length) && (string[index] <= ' ')) index++;
  183.     new
  184.         offset = index,
  185.         result[20];
  186.     while((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  187.     {
  188.         result[index - offset] = string[index];
  189.         index++;
  190.     }
  191.     result[index - offset] = EOS;
  192.     return result;
  193. }
  194.  
  195. //==============================================================================
  196.  
  197. isPlayerAtGasStation(playerid)
  198. {
  199.     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)
  200.     || 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)
  201.     || 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)
  202.     || 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))
  203.     return 1; // Coordinate by Los Angeles RolePlay
  204.     return 0;
  205. }
  206.  
  207. //==============================================================================
  208.  
  209. getVehicleDriver(vehicleid)
  210. {
  211.     for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
  212.     return -1;
  213. }
  214.  
  215. //==============================================================================
  216.  
  217. public scaloBenzina(vehicleid)
  218. {
  219.     if(vFuel[vehicleid] > 0) vFuel[vehicleid]--;
  220.     switch(vFuel[vehicleid])
  221.     {
  222.         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.");
  223.         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.");
  224.         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!");
  225.         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.");
  226.     }
  227. }
  228.  
  229. //******************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement