SHARE
TWEET

Untitled

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