SA-MP Forums Archive
[REQUESTING HELP] Textdraw Update (Fuel System) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [REQUESTING HELP] Textdraw Update (Fuel System) (/showthread.php?tid=330650)



[REQUESTING HELP] Textdraw Update (Fuel System) - NoZ - 02.04.2012

Alright, Hey Guys.

So I'm Using this Code this sPetrol Function,
I'm not Sure if its the Problem. But.

This Coding is Acutally Making the Out of Place Textdraw 'Petrol: 100'.
Now Ive Tried for Hours on End Fixing this Thing.
And i Know its Possibly ganna be some Stupid Little Error,

Код:
new string[125];format(string,sizeof string,"Petrol:%i",Petrol[VehicleIdentificationNumber]);
Код:
public sPetrol()
{
    for(new i=0;i<gMVehicles;i++)
		{
        if (IsCarRefueling[i]) continue; //stop when a player is already refuelling
        new VehicleIdentificationNumber = GetPlayerVehicleID(i); //getting vehicle ID
        if (GetPlayerVehicleSeat(i) == 0)
			{
            Petrol[VehicleIdentificationNumber] = Petrol[VehicleIdentificationNumber] -1; //lowering fuel value
            if (Petrol[VehicleIdentificationNumber]<1) //if fuel is empty
            {
                Petrol[VehicleIdentificationNumber] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
                RemovePlayerFromVehicle(i); //remove player out of vehicle
                GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
            }
        }
       
        new string[125];format(string,sizeof string,"Petrol:%i",Petrol[VehicleIdentificationNumber]); //preparing string with next fuel value //The Petrol:%i Here acutally is this 'Petrol: 100' out of place on the textdraw?

        TextDrawSetString(gPetrol[i],string); //updating textdraw
    }
    return 1;
}


public Refueling_Timer(playerid)
{
    new VehicleIdentificationNumber = GetPlayerVehicleID(playerid);
    Petrol[VehicleIdentificationNumber] = Petrol[VehicleIdentificationNumber] = 100;
    IsCarRefueling[playerid] = 0;
	TextDrawSetString(gPetrol[playerid],"Petrol:100");
    TogglePlayerControllable(playerid,1);
}
Now the White Text 'Petrol:100' is Out of Place.
I Dont Understand How it Gets Their.
A: There's no Co-ords Set for There.

Could Anyone Please Shed Some Light?

if you need more code shown just ask.



Cheers,


Re: [REQUESTING HELP] Textdraw Update (Fuel System) - [KHK]Khalid - 02.04.2012

pawn Код:
public Refueling_Timer(playerid)
{
    new VehicleIdentificationNumber = GetPlayerVehicleID(playerid);
    Petrol[VehicleIdentificationNumber] = Petrol[VehicleIdentificationNumber] = 100;
    IsCarRefueling[playerid] = 0;
    TextDrawHideForPlayer(playerid, gPetrol[playerid]); // check https://sampwiki.blast.hk/wiki/TextDrawHideForPlayer
    TextDrawSetString(gPetrol[playerid],"Petrol:100");
    TextDrawShowForPlayer(playerid, gPetrol[playerid]); // check https://sampwiki.blast.hk/wiki/TextDrawShowForPlayer
    TogglePlayerControllable(playerid,1);
}



Re: [REQUESTING HELP] Textdraw Update (Fuel System) - NoZ - 02.04.2012

Still Does Exactly the Same Thing,


Re: [REQUESTING HELP] Textdraw Update (Fuel System) - MP2 - 02.04.2012

Why do you have two textdraws to display the fuel?


Re: [REQUESTING HELP] Textdraw Update (Fuel System) - NoZ - 02.04.2012

Based of this Tutorail;
https://sampforum.blast.hk/showthread.php?tid=169284

Because the one in the first timer is updating the fuel value;


Re: [REQUESTING HELP] Textdraw Update (Fuel System) - Pillhead2007 - 23.02.2014

Mine Was Based Off That One And It Keep Staying At petrol 100 then it would go To 96 then back to 100 and double the textdraw try my fix just change the offset of the textdraw to suit your needs
PHP код:
forward FuelConsumption();
forward RefillFuel(playerid);
new 
RefillingFuel[MAX_PLAYERS];
new 
Text:FuelTxt[MAX_PLAYERS];
new 
Fuel[MAX_VEHICLES];
new 
FuelRefillTimer;
new 
FuelTimer;
main()
{
  for(new 
i=0;i<MAX_PLAYERS;i++)
  {
    
//--[Fuel]
    
FuelTxt[i] = TextDrawCreate(430,420,"Fuel:%i%");
    
TextDrawBackgroundColor(FuelTxt[i],0x00000033);
    
TextDrawFont(FuelTxt[i],3);
    
TextDrawLetterSize(FuelTxt[i],0.399999,1.700000);
    
TextDrawColor(FuelTxt[i],0xFFFFFFFF);
    
TextDrawSetShadow(FuelTxt[i],3);
  }
}
public 
FuelConsumption()
{
  for(new 
i=0;i<MAX_PLAYERS;i++)
  {
    new 
vehicleid GetPlayerVehicleID(i);
    new 
engine,lights,alarm,doors,bonnet,boot,objective;
    
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(
GetPlayerVehicleSeat(i) == 0)
    {
      
Fuel[vehicleid]--;
      if(
Fuel[vehicleid]<= 0)
      {
        
Fuel[vehicleid] = 0;
        
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
        
VehicleInfo[vehicleid][Engine] = 0;
        
GameTextForPlayer(i,"~w~You Are Out Of ~r~Fuel~w~!",5000,4);
      }
    }
    new 
string[125];
    
format(string,sizeof string,"Fuel:%i%",Fuel[vehicleid]);
    
TextDrawSetString(FuelTxt[i],string);
  }
  return 
1;
}
public 
RefillFuel(playerid)
{
  new 
vehicleid GetPlayerVehicleID(playerid);
  if(
IsPlayerConnected(playerid))
  {
    if(
RefillingFuel[playerid] == 1)
    {
      if(
Fuel[vehicleid] < 100)
      {
        
Fuel[vehicleid] = 100;
        
RefillingFuel[playerid] = 0;
        
KillTimer(FuelRefillTimer);
        
TogglePlayerControllable(playerid0);
      }
    }
    new 
string[128];
    
format(string,sizeof string,"Fuel:%i%",Fuel[vehicleid]);
    
TextDrawSetString(FuelTxt[playerid],string);
    
KillTimer(FuelRefillTimer);
    
TogglePlayerControllable(playerid1);
    
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn On Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~ ");
    
GameTextForPlayer(playerid,"~w~You Can Now Turn On Ignition ~n~ To Turn On Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~!",3000,4);
  }
  return 
1;
}
public 
OnGameModeInit()
{
  for(new 
i=0;i<MAX_VEHICLES;i++)
  {
    
Fuel[i] = 100;
  }
  return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
  new 
vehicleid GetPlayerVehicleID(playerid);
  if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
    if(
PRESSED(KEY_SUBMISSION))
    {
      new 
engine,lights,alarm,doors,bonnet,boot,objective;
      
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
      if(
VehicleInfo[vehicleid][Engine] != 1)
      {
        if(
Fuel[vehicleid] > 0)
        {
          
SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
          
VehicleInfo[vehicleid][Engine] = 1;
          
GameTextForPlayer(playerid,"~w~Ignition: ~g~On"200,3);
          
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" Ignition State:"COLOR_GREEN" On");
          
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn Off Ignition Press Key ~k~~TOGGLE_SUBMISSIONS~ ");
          
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" To Turn On/Off Lights Press Key ~k~~PED_FIREWEAPON~ ");
          
FuelTimer SetTimer("FuelConsumption",20000,true);
        }
        if(
Fuel[vehicleid]<= 0)
        {
          
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
          
VehicleInfo[vehicleid][Engine] = 0;
          
GameTextForPlayer(playerid,"~w~You Are Out Of ~r~Fuel!"200,3);
          
SendClientMessage(playerid,-1,COLOR_YELLOW"<<Vehicle Info>>"COLOR_WHITE" Fuel:"COLOR_RED" Empty");
          
KillTimer(FuelTimer);
           }
          }
       }
     }
     return 
1;




Re: [REQUESTING HELP] Textdraw Update (Fuel System) - Aerotactics - 23.02.2014

Pillhead...

STOP FUCKING REPLYING TO 2 YEAR OLD POSTS!