Help with my fuel system :S
#1

Ok i have a callback to remove fuel and when it gets to 0 its continues to -1 etc

pawn Код:
public FuelUpdate()
{
    new string[128];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
    {
        if(IsPlayerInAnyVehicle(i))
        {
            if(IsPlayerConnected(i))
            {
                  new PVeh = GetPlayerVehicleID(i);
                  if(VFuel[PVeh] >= 1 || VFuel[PVeh] <= 100)//If inbettween 1 and 100...
                  {
                      VFuel[PVeh] -= 1;//Remove 1 fuel///
                      format(string, sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~g~Fuel: ~w~%d%",VFuel[PVeh]);//And show it
                      GameTextForPlayer(i,string,18000,3);//In GameText
                  }
                  else//Else if its 0
                  {
                      RemovePlayerFromVehicle(i);//Remove Player
                      SendClientMessage(i,RED,"This Vehicle Is Out Of Fuel!");//Tell Them Its Empty.
                  }
              }
          }
      }
   }
}
Now how come if you in a vehicle and run the fuel empty (Not Getting Of IT Yet) it continues -1 -2 etc and keeps going not removing them and telling them its empty

Please help :S

EDIT: if you run it to 0 or -1 then get of then try get back on THEN it tells u its empty :S
Reply
#2

|| = OR
&& = AND

pawn Код:
if(VFuel[PVeh] >= 1 && VFuel[PVeh] <= 100)
Reply
#3

pawn Код:
public FuelUpdate()
{
    new string[128];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(GetPlayerState(i) == 2)
        {
            new PVeh = GetPlayerVehicleID(i);
            if(VFuel[PVeh])//If inbettween 1 and 100
            {
                VFuel[PVeh] -= 1;//Remove 1 fuel///
                format(string, 128,"~n~~n~~n~~n~~n~~n~~n~~n~~g~Fuel: ~w~%d%",VFuel[PVeh]);//And show it
                GameTextForPlayer(i,string,18000,3);//In GameText
            }
            else//Else if its 0
            {
                RemovePlayerFromVehicle(i);//Remove Player
                SendClientMessage(i,RED,"This Vehicle Is Out Of Fuel!");//Tell Them Its Empty.
            }
        }
    }
return 1;
}
Try that. It should be more optimized. You really need to only check if the fuel is over 0.
Reply
#4

Код:
if(VFuel[PVeh])//If inbettween 1 and 100
Please explain how this tells it thats its not at 0?

EDIT: And if i use If(GetPlayerState[playerid] == PLAYER_STATE_DRIVER) i dont have to use IsPlayerInAnyVehicle becuase it already knows there in one?? Loll makes sence xD
Reply
#5

EDIT: I haven't read your post much...

BUUUT, you should change to:
pawn Код:
new fuel = 30; // 30 fuel
pawn Код:
fuel--; // Taking 1 fuel away, you should use this instead of the thingy u'r usin'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)