Help with OnPlayerStateChange
#1

Fixed!
Reply
#2

Why you dont use public OnPlayerEnterVehicle?
Reply
#3

Use this:

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate

    new 
vehicleid GetVehicleModel(GetPlayerVehicleID(playerid)); 
    if(
vehicleid == 437 || vehicleid == 431
    { 
        if(
Bus_Driver[playerid] == 1
        { 
            
SendClientMessage(playerid,COLOR_YELLOW"Use /busdriver to begin.");
        } 
    } 
    if(
vehicleid != 437 || vehicleid != 431
    { 
        if(
Bus_Driver[playerid] == 0
        { 
            
SendClientMessage(playerid,COLOR_YELLOW"Bus driver job has been cancelled as you got into another vehicle other than a coach, or a bus.");
        } 
    } 
    return 
1

Reply
#4

Either add an else before the 2nd if statement or replace the || with && in the 2nd statement
Reply
#5

Fixed!
Reply
#6

Quote:
Originally Posted by Sc0pion
Посмотреть сообщение
Player looses the job doesn't matter which vehicle he/she gets in.

PHP код:
public OnPlayerEnterVehicle(playeridvehicleid)
{
/*------------------------------------------------------
-> When player exits a vehicle
------------------------------------------------------*/
/*------------------------------------------------------
-> When player enters a diffenrent vehicle when doing a job
------------------------------------------------------*/
    
new busdrivervehicle GetVehicleModel(GetPlayerVehicleID(playerid));
    if(
busdrivervehicle != 437 || busdrivervehicle != 431)
    {
        if(
Bus_Driver[playerid] == 1)
        {
            new 
Bstring[256], busdriver[MAX_PLAYER_NAME];
            
GetPlayerName(playeridbusdriversizeof(busdriver));
            
Bus_Driver[playerid] = 0;
            
DestroyDynamicRaceCP(BD_Checkpoint[playerid]);
            
BD_Steps[playerid] = BD_Checkpoint[playerid] = -1;
            
SendClientMessage(playeridgreen"[ NOTIFICATION: Your bus driver job has been abandoned as you got into a different vehicle. ]");
            
format(Bstringsizeof(Bstring), "[ BUS DRIVER: %s (Id: %d) is no longer a bus driver in Los Santos. ]"busdriverplayerid);
            return 
SendClientMessageToAll(green,Bstring);
        }
    }
    
return 
1;


You are wrong mate:
PHP код:
if(Bus_Driver[playerid] == 0)// Not a bus driver 
if(Bus_Driver[playerid] == 1//Is a bus driver 
Oh sorry for that,i dident noticed
Reply
#7

Fixed!
Reply
#8

Try this:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate) 
{ 
    new vehicleid = GetVehicleModel(GetPlayerVehicleID(playerid)); 
/*------------------------------------------------------ 
-> When player enters a coach or a buss 
------------------------------------------------------*/ 
    if(vehicleid == 437 || vehicleid == 431) 
    { 
        if(Bus_Driver[playerid] == 0) 
        { 
            return SendClientMessage(playerid,COLOR_YELLOW, "Use /busdriver to begin.");// This works when I'm not a bus driver. 
        } 
    } 
    if(vehicleid != 437 && vehicleid != 431) 
    { 
        if(Bus_Driver[playerid] == 1) 
        { 
            return SendClientMessage(playerid,COLOR_YELLOW, "Bus driver job has been cancelled as you got into another vehicle other than a coach, or a bus.");
        } 
    } 
    return 1; 
}
Reply
#9

Fixed!
Reply
#10

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetVehicleModel(GetPlayerVehicleID(playerid));
        /*------------------------------------------------------
        -> When player enters a coach or a buss
        ------------------------------------------------------*/

        if(vehicleid == 437 || vehicleid == 431)
        {
            if(!Bus_Driver[playerid]) SendClientMessage(playerid, COLOR_YELLOW, "Use /busdriver to begin.");
        }
        else
        {
            if(Bus_Driver[playerid] == 1)
            {
                SendClientMessage(playerid,COLOR_YELLOW, "Bus driver job has been cancelled as you got into another vehicle other than a coach, or a bus.");
                //Bus_Driver[playerid] = 0;
            }
        }
    }
    return 1;
}
The problem was this line:
pawn Код:
if(vehicleid != 437 || vehicleid != 431)
This means, if the vehicle model isn't 437, or isn't 431, then continue..
Let's say your vehicle model is 437. (Bus or coach? too lazy to search)

If your vehicle model is 437, that means it is NOT equal to 431. If your vehicle model is 431, that means it is NOT equal to 437. So this statement would successfully continue for any and every vehicle model. The correct usage would have been:

pawn Код:
if(vehicleid != 437 && vehicleid != 431)
This way, if the model is NOT 437, AND the model is NOT 431, then continue.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)