statechange
#1

When mowerjob is false and i exit the mower, I still get the msg as if it was true; , I'm a bit tired so if anyone can help me out a little would be appreciated
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) // Player entered a vehicle as a driver
    {
        if(GetVehicleModel(vehicleid) == 572 && MowerJob[playerid] == true)
        {
                MowerJob[playerid] = false;
                SendClientMessage(playerid,-1,"{00E4FF}[LAWN MOWING]{FFFFFF} You have left your vehicle, mission has been {FF0000}cancelled.");
                return 1;
        }
        else if(GetVehicleModel(vehicleid) == 572 && MowerJob[playerid] == false)
        {
            SendClientMessage(playerid,-1,"{00E4FF}[LAWN MOWING]{FFFFFF} You left your mower, mowerjob was already 0.");
            return 1;
        }
        return 1;
    }
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // Player entered a vehicle as a driver
    {
        if(GetVehicleModel(vehicleid) == 572)
        {
            if(MowerJob[playerid] == false)
            {
                SendClientMessage(playerid,-1,"{00E4FF}[LAWN MOWING]{FFFFFF} To begin this job, type {FFC500}/lawnmower {FFFFFF}or press {FFC500}2.");
                GameTextForPlayer(playerid, "~w~To start a ~g~~h~~h~lawn mowing mission~w~, type ~y~/lawnmower ~w~or press ~y~2", 5000, 3);
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

In case the player exits the vehicle, vehicleid will be 0.
His oldstate may still hold he was the driver, but newstate is onfoot, and using GetPlayerVehicleID will return 0.
You're still checking if he's inside a mower vehicle while he's already onfoot (your first "if(oldstate ...." statement).
Note: the comment after that line is not correct as well.

You could use OnPlayerExitVehicle to store the vehicleid in the player's account (create an array like LastVehicle[MAX_PLAYERS] for example, like your MowerJob array) and use that value inside OnPlayerStateChange.
Reply
#3

my suggestion is make a local variable to save the vehicleid.
then check for the variable if it's equal the vehicle ID you want.
and after exiting the car set the variable to zero.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)