Jakwob-WG

[FS] Fuel pawn

Oct 12th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.31 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4.  
  5. new fuel[MAX_VEHICLES]; //fuel per vehicle
  6. forward timer_fuel_lower(); //timer for lowering the fuel value
  7. forward timer_refuel(playerid); //timer to refuel vehicle
  8. new isrefuelling[MAX_PLAYERS] = 0; //bool to check if player is already refuelling
  9. new Text:td_fuel[MAX_PLAYERS]; //textdraw with fuel
  10.  
  11. public OnFilterScriptInit()//when the filterscript loads
  12. {
  13.     for(new i=0;i<MAX_VEHICLES;i++) {
  14.         fuel[i] = 100; //sets every car's fuel to 100 in a loop
  15.     }
  16.     SetTimer("timer_fuel_lower",4200,true); //sets the timer to drop the fuel
  17.     return 1;
  18. }
  19.  
  20. public OnPlayerSpawn(playerid)
  21. {
  22.     td_fuel[playerid] = TextDrawCreate(45,324,"Fuel: 100"); //create the textdraw at position
  23.     TextDrawBackgroundColor(td_fuel[playerid],0x00000033); //setting an nice backgroundcolor
  24.     TextDrawFont(td_fuel[playerid],3); //font type of textdraw
  25.     TextDrawLetterSize(td_fuel[playerid],0.699999,1.700000); //size...
  26.     TextDrawColor(td_fuel[playerid],0x000000ff); //color
  27.     TextDrawSetShadow(td_fuel[playerid],3); //dropping the shadow
  28.     return 1;
  29. }
  30.  
  31. public OnPlayerStateChange(playerid, newstate, oldstate)
  32. {
  33.     if (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  34.     {
  35.         new vid = GetPlayerVehicleID(playerid);
  36.         new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //quickly doing a small update on fuel (so it wont jump from 100 to its real value)
  37.         TextDrawSetString(td_fuel[playerid],string);
  38.         TextDrawShowForPlayer(playerid,td_fuel[playerid]); //showing if an player is a driver or passenger of the ar
  39.     } else {
  40.         TextDrawHideForPlayer(playerid,td_fuel[playerid]); //hiding if a player isnt driving/or an passenger
  41.     }
  42.     return 1;
  43. }
  44.  
  45. public OnPlayerCommandText(playerid,cmdtext[]) {
  46.  
  47.     if (!strcmp("/refuel",cmdtext,true,7)) {
  48.         if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFC800FF,"You are not in an vehicle!"); //if a player isnt in a vehicle, it stops here
  49.         if (isrefuelling[playerid]) return SendClientMessage(playerid,0xFFC800FF,"You are already refuelling!"); //if a player is already refuelling, it stops here
  50.         if (GetPlayerMoney(playerid) - 80 <0) return SendClientMessage(playerid,0xFFC800FF,"You dont have enough money!"); //if a player doesnt have $80 anymore, it stops here
  51.         GivePlayerMoney(playerid,-80); //Sets the player's cash -$80
  52.         SetCameraBehindPlayer(playerid); //Sets the camera behind the player (looks better because the player will be frozen for a few secs)
  53.         TogglePlayerControllable(playerid,0); //freezes the player so he cant drive and refuel at the same time
  54.         isrefuelling[playerid] = 1; //setting isrefuelling to 1 so the player cant spam /refuel
  55.         TextDrawSetString(td_fuel[playerid],"Refuelling..."); //changing textdraw to /refuel
  56.         SetTimerEx("timer_refuel",4500,false,"i",playerid); //setting refueltimer
  57.         return 1;
  58.     }
  59.  
  60.     return 0;
  61. }
  62.  
  63. public timer_fuel_lower()
  64. {
  65.     for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
  66.         if (isrefuelling[i]) continue; //stop when a player is already refuelling
  67.         new vid = GetPlayerVehicleID(i); //getting vehicle ID
  68.         if (GetPlayerVehicleSeat(i) == 0) { //if the player is a driver (it should only lower the fuel when theres an driver!)
  69.             fuel[vid] = fuel[vid] -1; //lowering fuel value
  70.             if (fuel[vid]<1) //if fuel is empty
  71.             {
  72.                 fuel[vid] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
  73.                 RemovePlayerFromVehicle(i); //remove player out of vehicle
  74.                 GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
  75.             }
  76.         }
  77.         new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
  78.         TextDrawSetString(td_fuel[i],string); //updating textdraw
  79.     }
  80.     return 1;
  81. }
  82.  
  83. public timer_refuel(playerid)
  84. {
  85.     new vid = GetPlayerVehicleID(playerid);
  86.     fuel[vid] = fuel[vid] = 100; //restoring fuel to 100
  87.     isrefuelling[playerid] = 0;//resetting anti-spam thingy :3
  88.     TextDrawSetString(td_fuel[playerid],"Fuel:100"); //small update on textdraw
  89.     TogglePlayerControllable(playerid,1); //unfreeze player
  90. }
Advertisement
Add Comment
Please, Sign In to add comment