Help with OnPlayerStateChange(playerid, newstate, oldstate)
#1

Fixed!
Reply
#2

Try OnPlayerExitVehicle https://sampwiki.blast.hk/wiki/OnPlayerExitVehicle
Reply
#3

Fixed!
Reply
#4

Look i'm not sure about this but you might try
Код:
if(vehicle != 437 || vehicle != 431)
Again i'm not sure
Reply
#5

Fixed!
Reply
#6

Fixed!
Reply
#7

This should work, ive restructured things a little, fixed the if statement to be proper, and made it use AND instead of OR:
Код:
new vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
if(newstate == PLAYER_STATE_DRIVER) {
    if(Bus_Driver[playerid] == 1) {
        if((vehicle != 437) && (vehicle != 431)) {
            new string[256],
                busdriver[MAX_PLAYER_NAME];
                
            DestroyDynamicRaceCP(BD_Checkpoint[playerid]);
            BD_Steps[playerid] = BD_Checkpoint[playerid] = -1;

            Bus_Driver[playerid] = 0;
            
            GetPlayerName(playerid, busdriver, sizeof(busdriver));
            format(string, sizeof(string), "%s (%d) is no longer a bus driver in Los Santos.", busdriver, playerid);
            
            SendClientMessageToAll(white,string);
            SendClientMessage(playerid, white, "[ BUSS DRIVER: You are no longer  bus driver. ]");
        } else {
            // ... (vehicle is a bus!)
        }
    } else {
        // ... (playerid isnt a busdriver)
    }
}
return 1;
------------------------

Heres a mini programming lesson about using AND & OR in if statements:

If you want to check if a variable is not A OR B (OR C) you actually need to use AND, instead of OR, take the following example:
Код:
new exampleValue = 75;
if((exampleValue != 50) || (exampleValue != 100)) {
    print("exampleValue isnt 50 or exampleValue isnt 100");
} else {
    print("exampleValue is 50 or exampleValue is 100");
}
That would return "exampleValue isnt 50 or exampleValue isnt 100", wich is correct, because exampleValue is 75, 75 isnt 50, and 75 isnt 100, so the if statement continues.
But now what happens if we do this:
Код:
new exampleValue = 100;
if((exampleValue != 50) || (exampleValue != 100)) {
    print("exampleValue isnt 50 or exampleValue isnt 100");
} else {
    print("exampleValue is 50 or exampleValue is 100");
}
That would still return "exampleValue isnt 50 or example isnt 100", because, exampleValue is 100, 100 does not equal 50, but 100 does equal a 100.

Now the thing is, because you use OR in the if statement, only 1 of the conditions will do, so because 100 does not equal 50, the if statement continues.
Now when you use AND, like so:
Код:
new exampleValue = 100;
if((exampleValue != 50) && (exampleValue != 100)) {
    print("exampleValue isnt 50 and exampleValue isnt 100");
} else {
    print("exampleValue is 50 or exampleValue is 100");
}
It would return "exampleValue is 50 or exampleValue is 100", because while exampleValue is not 50, it is a 100, so the if statement is false (seeing how it checks to make sure exampleValue is not a 100) and stops.
Reply
#8

When the job is started you should store the VehicleID (not model), then all you have to do is put a check in OnPlayerEnterVehicle. Check if the player is on a bus mission, if they are, check if it's the same vehicleid you stored - if it's not the correct vehicleid, mission failed. This way, it's guaranteed to only work with the vehicle that the job was started in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)