toribio

toribio

Feb 28th, 2010
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. if(strcmp(cmd, "/gasolina", true) == 0)
  2. {
  3.     new tmp[256], vehicleid;
  4.     new gas, string[128], offset, total;
  5.     tmp = strtok(cmdtext, idx);
  6.  
  7.     if(!strlen(tmp))
  8.     {
  9.         SendClientMessage(playerid, COLOR_RED, "/gasolina [quantia]");
  10.         return 1;
  11.     }
  12.     gas = strval(tmp);
  13.  
  14.     if(AreaPosto[playerid] == 0)
  15.     {
  16.         SendClientMessage(playerid, COLOR_RED, "Você não está no posto!");
  17.         return 1;
  18.     }
  19.     if(!(vehicleid = GetPlayerVehicleID(playerid)))
  20.     {
  21.         SendClientMessage(playerid, COLOR_RED, "Você não está em um veículo!");
  22.         return 1;
  23.     }
  24.     if(gas > 100 || gas <= 0)
  25.     {
  26.         SendClientMessage(playerid, COLOR_RED, "Quantia inválida! Gas apenas de 1 à 100");
  27.         return 1;
  28.     }
  29.     if(GetVehicleGas(vehicleid) >= 100)
  30.     {
  31.         SendClientMessage(playerid, COLOR_RED, "O tanque de seu carro já está cheio!");
  32.         return 1;
  33.     }
  34.  
  35.     offset  = 100 - GetVehicleGas(vehicleid);
  36.     total   = (gas + GetVehicleGas(vehicleid) > 100) ? gas - offset : gas;
  37.  
  38.     if(GetPlayerMoney(playerid) < total)
  39.     {    
  40.         format(string, sizeof string, "Você não tem dinheiro para abastecer %d litros. Custo: $1 cada litro!", total);
  41.         SendClientMessage(playerid, COLOR_RED, string);
  42.         return 1;
  43.     }
  44.     GivePlayerMoney(playerid, -total);
  45.     AddVehicleGas(vehicleid, total);
  46.     if(GetVehicleGas(vehicleid) >= 100)
  47.     {    
  48.         format(string, sizeof string, "Foram abastecidos %d litros, tanque cheio agora!", total);
  49.         SendClientMessage(playerid, COLOR_GREEN, string);
  50.     }
  51.     else
  52.     {
  53.         format(string, sizeof string, "Foram abastecidos %d litros, total: %d", total, GetVehicleGas(vehicleid));
  54.         SendClientMessage(playerid, COLOR_GREEN, string);
  55.     }
  56.     return 1;
  57. }
Add Comment
Please, Sign In to add comment