Can somone make this run when player not in veh?
#1

Hey I need a little favour from somone that could make this code run even the player is not inside the vehicle.

That means, the fuel still goes down, even the player is not inside the vehicle, and the engine is turned off.
(Btw: You don't need to care about the flashing indicator message, I can fix that one self)

Thanks !

pawn Код:
public FuelUpdate()
{
    //new string[256];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        new VID = GetPlayerVehicleID(i);
        new MOD = GetVehicleModel(i);
        if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            if(IsPlayerConnected(i))
            {
                new vehicle = GetPlayerVehicleID(i);
                if(IsABike(vehicle)) return 1;

                if(Filling[i] == 0 && VehicleStarted[VID] == 1 && MOD != 510 && MOD != 509 && MOD != 481)
                {
                    if(VehicleGas[VID] <= 10)
                    {
                        new Float:x, Float:y, Float:z;
                        GetPlayerPos(i, x, y, z);
                        PlayerPlaySound(i, 1085, x, y, z);
                    }
                    if(VehicleGas[VID] >= 1)
                    {
                        VehicleGas[VID] -= 1;
                    }
                    else
                    {
                        TogglePlayerControllable(i,0);
                        if(VehicleStarted[VID] == 1)
                        {
                            new string[128];
                            new sendername[MAX_PLAYER_NAME];
                            GetPlayerName(i, sendername, sizeof(sendername));
                            format(string, sizeof(string), "* Vehicle engine stops, fuel indicator flashes (( %s's vehicle ))", sendername);
                            ProxDetector(30.0, i, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                            VehicleStarted[VID] = 0;
                        }
                        GameTextForPlayer(i,"~n~~n~~n~~n~~b~Your car is without fuel!",2500,3);
                        SendClientMessage(i,COLOR_CMD,"     - Your Vehicle is without fuel!!");
                    }
                }
            }
        }
    }
    return 1;
}
Reply
#2

Код:
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
It's that line which tracks if they are in a vehicle (driving), remove the line for no state check or add more states using the || oper.

Код:
new
    state = GetPlayerState( playerid );

if ( state == PLAYER_STATE_DRIVER || state == PLAYER_STATE_ON_FOOT )
{
    // code
}

// or a switch

switch ( state )
{
    case PLAYER_STATE_DRIVER, PLAYER_STATE_ON_FOOT:
    {
        // code
    }
}
Reply
#3

I'm not asking for that the driver is driving or not. Just that the fuel % goes down, when it's none drivers inside the car. And engine is on.
Reply
#4

Just the concept:
1. Remove the PLAYER_STATE check and the whole for-player stuff
2. Add the vehicleid to the function as parameter
3. Start a timer calling the function when the engine is started
4. Kill the timer when the engine is stopped
Reply
#5

I fixed it now, by removing the PLAYER_STATE check, and just making a loop for vehicles

No timer killing or calling
Reply
#6

so all ur vehicles are gonna be losing fuell.. by the second..(timerseconds)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)