Nyft_

Galão de Gasolina ~Nyft

Jul 2nd, 2021 (edited)
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.21 KB | None | 0 0
  1. #include a_samp
  2. #include streamer
  3. #include sscanf2
  4. #include pawn.cmd
  5.  
  6. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  7.  
  8. #define function%0(%1) \
  9.     forward%0(%1); public%0(%1)
  10.  
  11. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  12.  
  13. #define PICKUP_FILL_X           1961.5599
  14. #define PICKUP_FILL_Y           1342.9359
  15. #define PICKUP_FILL_Z           15.3746
  16.  
  17. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  18.  
  19. static const Float:AMOUNT_FILL = 1.0;           // Retirar ao encher o galão (1.0)
  20. static const Float:AMOUNT_REFUEL = 1.0;         // Retirar ao abastecer (1.0)
  21. static const Float:PRICE_PER_LITER = 5.0;       // Preço p/Litro ($5)
  22.  
  23. static bool:HasGallon[MAX_PLAYERS];
  24. static Float:VehicleFuel[MAX_VEHICLES];         // Variável da Gasolina
  25. static Float:GasGallon[MAX_PLAYERS];            // Variável do Galão
  26. static Float:BuyGas[MAX_PLAYERS];
  27. static GallonTimer[MAX_VEHICLES] = {-1, ...};
  28. static GallonFillTimer[MAX_PLAYERS] = {-1, ...};
  29.  
  30. main(){}
  31.  
  32. public OnGameModeInit()
  33. {
  34.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 270.0000, 0, 0, 0, 0, 0, 0);
  35.  
  36.     CreateDynamicMapIcon(PICKUP_FILL_X, PICKUP_FILL_Y, PICKUP_FILL_Z, 55, -1, .streamdistance = 75.0);
  37.     CreateDynamicPickup(1650, 1, PICKUP_FILL_X, PICKUP_FILL_Y, PICKUP_FILL_Z+0.25, .streamdistance = 50.0);
  38.     CreateDynamic3DTextLabel("{1E90FF}Encher Galão\n{FFFFFF}Pressione Y ou (/enchergalao)", -1, PICKUP_FILL_X, PICKUP_FILL_Y, PICKUP_FILL_Z+0.75, 25.0, .testlos = 1);
  39.     return 1;
  40. }
  41.  
  42. public OnPlayerDisconnect(playerid, reason)
  43. {
  44.     if(HasGallon[playerid])
  45.     {
  46.         ResetFillGallon(playerid);
  47.         GasGallon[playerid] = 0.0;
  48.         HasGallon[playerid] = false;
  49.     }
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  54. {
  55.     new vehicleid = GetPlayerVehicleID(playerid);
  56.  
  57.     if((newkeys & KEY_YES) && IsPlayerInRangeOfPoint(playerid, 1.0, PICKUP_FILL_X, PICKUP_FILL_Y, PICKUP_FILL_Z))
  58.     {
  59.         callcmd::enchergalao(playerid);
  60.         // Caso usar zcmd faça: cmd_enchergalao(playerid);
  61.     }
  62.     if(newkeys & KEY_NO)
  63.     {
  64.         if(GallonFillTimer[playerid] != -1)
  65.         {
  66.             ResetFillGallon(playerid);
  67.             TogglePlayerControllable(playerid, true);
  68.             SendClientMessage(playerid, -1, "* Você decidiu parar de encher seu galão de combustível (/usargalao).");
  69.         }
  70.         if(GallonTimer[vehicleid] != -1)
  71.         {
  72.             KillTimer(GallonTimer[vehicleid]);
  73.             GallonTimer[vehicleid] = -1;
  74.             ToggleVehicleEngineState(vehicleid, true);
  75.             SendClientMessage(playerid, -1, "* Você decidiu parar de abastecer esse veículo.");
  76.         }
  77.     }
  78.     return 1;
  79. }
  80.  
  81. function OnFillGallon(playerid)
  82. {
  83.     if((GasGallon[playerid] += AMOUNT_FILL) >= 100.0)
  84.     {
  85.         GasGallon[playerid] = 100.0;
  86.         ResetFillGallon(playerid);
  87.         TogglePlayerControllable(playerid, true);
  88.         SendClientMessage(playerid, -1, "* Você terminou de encher o seu galão de combustível (/usargalao).");
  89.         return 1;
  90.     }
  91.     if(GetPlayerMoney(playerid) < PRICE_PER_LITER)
  92.     {
  93.         ResetFillGallon(playerid);
  94.         ResetPlayerMoney(playerid);
  95.         TogglePlayerControllable(playerid, true);
  96.         SendClientMessage(playerid, -1, "* Você não possui dinheiro suficiente (/g).");
  97.         return 1;
  98.     }
  99.     new string[64];
  100.     BuyGas[playerid] += AMOUNT_FILL;
  101.     GivePlayerMoney(playerid, -floatround(AMOUNT_FILL * PRICE_PER_LITER));
  102.     format(string, sizeof(string), "~b~~h~Enchendo Galao...~n~~n~~g~$%i ~r~- ~y~%.1fL", floatround(BuyGas[playerid] * PRICE_PER_LITER), GasGallon[playerid]);
  103.     GameTextForPlayer(playerid, string, 500, 3);
  104.     return 1;
  105. }
  106.  
  107. function OnGallonRefuel(vehicleid)
  108. {
  109.     for(new i, j = GetPlayerPoolSize(); i <= j; ++i)
  110.     {
  111.         if(!GetVehicleEngineState(vehicleid) && IsPlayerInVehicle(i, vehicleid) && GetPlayerVehicleSeat(i) == 0)
  112.         {
  113.             if((VehicleFuel[vehicleid] += AMOUNT_REFUEL) >= 100.0)
  114.             {
  115.                 KillTimer(GallonTimer[vehicleid]);
  116.                 GallonTimer[vehicleid] = -1;
  117.                 VehicleFuel[vehicleid] = 100.0;
  118.                 SendClientMessage(i, -1, "* Você encheu todo o tanque do seu veículo.");
  119.                 break;
  120.             }
  121.             if((GasGallon[i] -= AMOUNT_REFUEL) <= 0.0)
  122.             {
  123.                 KillTimer(GallonTimer[vehicleid]);
  124.                 GallonTimer[vehicleid] = -1;
  125.                 GasGallon[i] = 0.0;
  126.                 ToggleVehicleEngineState(vehicleid, true);
  127.                 SendClientMessage(i, -1, "* Seu galão não possui mais gasolina.");
  128.                 break;
  129.             }
  130.             new string[70];
  131.             format(string, sizeof(string), "~b~~h~Abastecendo...~n~~n~~r~Tanque: ~w~%.1fL~n~~r~Galao: ~w~%.1fL", VehicleFuel[vehicleid], GasGallon[i]);
  132.             GameTextForPlayer(i, string, 500, 3);
  133.         }
  134.     }
  135.     return 1;
  136. }
  137.  
  138. AddVehicle(modelid, Float:x, Float:y, Float:z, Float:a, Float:fuel, color1, color2, respawn_delay = -1)
  139. {
  140.     new vehicleid = CreateVehicle(modelid, x, y, z, a, color1, color2, respawn_delay);
  141.     VehicleFuel[vehicleid] = fuel;
  142.     return vehicleid;
  143. }
  144.  
  145. ToggleVehicleEngineState(vehicleid, bool:value)
  146. {
  147.     if(!IsValidVehicle(vehicleid))
  148.         return 0;
  149.  
  150.     new engine, lights, alarm, doors, bonnet, boot, objective;
  151.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  152.     SetVehicleParamsEx(vehicleid, value ? (VEHICLE_PARAMS_ON) : (VEHICLE_PARAMS_OFF), lights, alarm, doors, bonnet, boot, objective);
  153.     return value;
  154. }
  155.  
  156. GetVehicleEngineState(vehicleid)
  157. {
  158.     if(!IsValidVehicle(vehicleid))
  159.         return 0;
  160.  
  161.     new engine, lights, alarm, doors, bonnet, boot, objective;
  162.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  163.     return (engine == VEHICLE_PARAMS_ON);
  164. }
  165.  
  166. ResetFillGallon(playerid)
  167. {
  168.     if(GallonFillTimer[playerid] != -1)
  169.     {
  170.         KillTimer(GallonFillTimer[playerid]);
  171.         GallonFillTimer[playerid] = -1;
  172.         BuyGas[playerid] = 0.0;
  173.     }
  174. }
  175.  
  176. CMD:usargalao(playerid)
  177. {
  178.     if(!HasGallon[playerid])
  179.         return SendClientMessage(playerid, -1, "* Você não possui um galão de combustível (/galao).");
  180.  
  181.     if(!IsPlayerInAnyVehicle(playerid))
  182.         return SendClientMessage(playerid, -1, "* Você não está em um veículo (/v).");
  183.  
  184.     new vehicleid = GetPlayerVehicleID(playerid);
  185.  
  186.     if(VehicleFuel[vehicleid] >= 100.0)
  187.         return SendClientMessage(playerid, -1, "* Seu veículo já está com o tanque cheio.");
  188.  
  189.     if(!GasGallon[playerid])
  190.         return SendClientMessage(playerid, -1, "* Seu galão não possui gasolina (/enchergalao).");
  191.  
  192.     if(GallonTimer[vehicleid] != -1)
  193.         return SendClientMessage(playerid, -1, "* Você já está abastecendo seu veículo.");
  194.  
  195.     ToggleVehicleEngineState(vehicleid, false);
  196.     SendClientMessage(playerid, -1, "* Abastecendo veículo... Pressione 'N' para parar.");
  197.     GallonTimer[vehicleid] = SetTimerEx("OnGallonRefuel", 500, true, "i", vehicleid);
  198.     return 1;
  199. }
  200. CMD:enchergalao(playerid)
  201. {
  202.     if(!HasGallon[playerid])
  203.         return SendClientMessage(playerid, -1, "* Você não possui um galão de combustível (/galao).");
  204.  
  205.     if(!IsPlayerInRangeOfPoint(playerid, 1.0, PICKUP_FILL_X, PICKUP_FILL_Y, PICKUP_FILL_Z))
  206.         return SendClientMessage(playerid, -1, "* Você não está no local de encher o galão de combustível.");
  207.  
  208.     if(IsPlayerInAnyVehicle(playerid))
  209.         return SendClientMessage(playerid, -1, "* Você está conduzindo um veículo.");
  210.  
  211.     if(GetPlayerMoney(playerid) < PRICE_PER_LITER)
  212.         return SendClientMessage(playerid, -1, "* Você não possui dinheiro suficiente (/g).");
  213.  
  214.     if(GallonFillTimer[playerid] != -1)
  215.         return SendClientMessage(playerid, -1, "* Você já está enchendo seu galão de combustível.");
  216.  
  217.     if(GasGallon[playerid] >= 100.0)
  218.         return SendClientMessage(playerid, -1, "* Seu galão já está cheio.");
  219.  
  220.     TogglePlayerControllable(playerid, false);
  221.     SendClientMessage(playerid, -1, "* Enchendo galão... Pressione 'N' para parar.");
  222.     GallonFillTimer[playerid] = SetTimerEx("OnFillGallon", 500, true, "i", playerid);
  223.     return 1;
  224. }
  225. CMD:galao(playerid)
  226. {
  227.     if(HasGallon[playerid])
  228.         return SendClientMessage(playerid, -1, "* Você já possui um galão.");
  229.  
  230.     if(GasGallon[playerid] >= 100.0)
  231.         return SendClientMessage(playerid, -1, "* Você está com o galão cheio.");
  232.  
  233.     HasGallon[playerid] = true;
  234.     GasGallon[playerid] = 0.0;
  235.     SendClientMessage(playerid, -1, "* Você pegou um galão de gasolina (/enchergalao).");
  236.     return 1;
  237. }
  238. CMD:v(playerid, params[])
  239. {
  240.     new modelid;
  241.  
  242.     if(sscanf(params, "i", modelid))
  243.         return SendClientMessage(playerid, -1, "* Use: /v [modelo]");
  244.  
  245.     if(!(400 <= modelid <= 611))
  246.         return SendClientMessage(playerid, -1, "* Use modelos de 400 ao 611.");
  247.  
  248.     new vehicleid, Float:x, Float:y, Float:z, Float:a;
  249.     GetPlayerPos(playerid, x, y, z);
  250.     GetPlayerFacingAngle(playerid, a);
  251.  
  252.     vehicleid = AddVehicle(modelid, x, y, z, a, 25.0, -1, -1);
  253.     PutPlayerInVehicle(playerid, vehicleid, 0);
  254.     return 1;
  255. }
  256. CMD:g(playerid)
  257. {
  258.     GivePlayerMoney(playerid, 1000);
  259.     GameTextForPlayer(playerid, "~g~+$1000", 1000, 3);
  260.     return 1;
  261. }
Add Comment
Please, Sign In to add comment