SA-MP Forums Archive
Car 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Car Fuel System (/showthread.php?tid=250094)



Car Fuel System - Tommy_Mandaz - 21.04.2011

pawn Код:
FuelTimerLower = SetTimerEx("timer_fuel_lower",50000,true,"i",playerid);
Would that work so onplayerentervehicle it starts it for that player and that vehicle only? Because SetTimer sets it for more then one person and car... I only want the that car that the player is driving to be losing fuel. Thanks.


Re: Car Fuel System - Haydz - 21.04.2011

I would suggest using OnPlayerStateChange for using the timer, and you will need a seperate FuelTimerLower for each player( so don't cancel otherplayers timers)

pawn Код:
new FuelTimerLower[MAX_PLAYERS];
public OnPlayerStateChange(playerid, newstate,oldstate)
{
        if(newstate == PLAYER_STATE_DRIVER)
        {
              FuelTimerLower[playerid] = SetTimerEx("timer_fuel_lower",50000,true,"i",playerid);  
        }
        if(oldstate == PLAYER_STATE_DRIVER)
        {
              KillTimer(FuelTimerLower[playerid]);
        }
}
Then that would start/kill the timer for each different player. also, if you want it so it lowers the carfuel of the car you're in you will need to show us your 'timer_fuel_lower' function


Re: Car Fuel System - Tommy_Mandaz - 21.04.2011

Ahh that makes sense :P... And here it is... I think I did it right not sure :P.


pawn Код:
public timer_fuel_lower()
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if (isrefuelling[i]) continue;
        vid = GetPlayerVehicleID(i);
        if (GetPlayerVehicleSeat(i) == 0)
        {
            fuel[vid] = fuel[vid] -1;
            new string[125];
            TextDrawShowForPlayer(i,td_fuel[i]);
            format(string,sizeof string,"Fuel:%i",fuel[vid]);
            TextDrawSetString(td_fuel[i],string);
            TextDrawSetString(td_fuel[i],string);
            if (fuel[vid]<1)
            {
                fuel[vid] = 0;
                RemovePlayerFromVehicle(i);
                GameTextForPlayer(i,"~r~Your vehicle has no more fuel!",5000,4);
            }
        }
        else
        {
            TextDrawHideForPlayer(i,td_fuel[i]);
        }
    }
    return 1;
}



Re: Car Fuel System - Vince - 21.04.2011

No, you're still looping through all players in that function. Get rid of the loop, add playerid as parameter in the function header and replace all i vars with playerid.


Re: Car Fuel System - Tommy_Mandaz - 21.04.2011

Like this?:

pawn Код:
forward timer_fuel_lower(playerid);
public timer_fuel_lower(playerid)
{
    vid = GetPlayerVehicleID(playerid);
    if (GetPlayerVehicleSeat(playerid) == 0)
    {
        fuel[vid] = fuel[vid] -1;
        new string[125];
        TextDrawShowForPlayer(playerid,td_fuel[playerid]);
        format(string,sizeof string,"Fuel:%i",fuel[vid]);
        TextDrawSetString(td_fuel[playerid],string);
        TextDrawSetString(td_fuel[playerid],string);
        if (fuel[vid]<1)
        {
            fuel[vid] = 0;
            RemovePlayerFromVehicle(playerid);
            GameTextForPlayer(playerid,"~r~Your vehicle has no more fuel!",5000,4);
        }
    }
    else
    {
        TextDrawHideForPlayer(playerid,td_fuel[playerid]);
    }
    return 1;
}



Re: Car Fuel System - Vince - 21.04.2011

Perfect.

This forum requires that you wait 120 seconds between posts. Please try again in 46 seconds.
Well, f*ck that!


Re: Car Fuel System - Tommy_Mandaz - 21.04.2011

Lol and thanks a lot