OnPlayerStateChange
#1

Hey.

I have a small issue with OnPlayerStateChange.


I check if the player is the Driver, then under this code I add another code for checking if the player is in a Job car to (not)remove them from the vehicle.

The first block works but all the code under it won't work!
Here it is:
Код:
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if(BusCar(GetPlayerVehicleID(playerid))) // This works
		{
	 		if(PlayerInfo[playerid][pJob] == 1)
			{
	  			SendClientMessage(playerid,-1,"{1589FF} Welcome Bus Driver.");
			}
			else SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!"); RemovePlayerFromVehicle(playerid);
		}
		if(MechanicCar(GetPlayerVehicleID(playerid))) // All the code under this don't work whatever I put under here
		{
	 		if(PlayerInfo[playerid][pJob] == 2)
			{
	  			SendClientMessage(playerid,-1,"{1589FF} Welcome Mechanic.");
			}
			else SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!"); RemovePlayerFromVehicle(playerid);
		}
	}
Thanks.
Reply
#2

Try this
Код:
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if(BusCar(GetPlayerVehicleID(playerid))) // This works
		{
	 		if(PlayerInfo[playerid][pJob] == 1)
			{
	  			SendClientMessage(playerid,-1,"{1589FF} Welcome Bus Driver.");
			}
			else return SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!"); RemovePlayerFromVehicle(playerid);
		}
		if(MechanicCar(GetPlayerVehicleID(playerid))) // All the code under this don't work whatever I put under here
		{
	 		if(PlayerInfo[playerid][pJob] == 2)
			{
	  			SendClientMessage(playerid,-1,"{1589FF} Welcome Mechanic.");
			}
			else return SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!"); RemovePlayerFromVehicle(playerid);
		}
	}
You've forgot to add the return's to a few sections and tell me if it works!
Reply
#3

Still the same.
Reply
#4

Use "else if",
Код:
else if(MechanicCar(GetPlayerVehicleID(playerid)))
Reply
#5

Quote:
Originally Posted by NotIntegrated
Посмотреть сообщение
Use "else if",
Код:
else if(MechanicCar(GetPlayerVehicleID(playerid)))
Doesn't work, either.
Reply
#6

At the end of OnPlayerStateChange are you returning 0 or 1? And can we see the code for MechanicCar?
Reply
#7

Quote:
Originally Posted by NotIntegrated
Посмотреть сообщение
At the end of OnPlayerStateChange are you returning 0 or 1? And can we see the code for MechanicCar?
OnPlayerStateChange returns 1, here's the MechanicCar stock (it's the same as BusCar):
Код:
stock MechanicCar(vehicleid)
{
    for(new i;i <= sizeof(TowTrucks);i++)
    {
        if(vehicleid == TowTrucks[i]) return 1;
    }
    return 0;
}
Reply
#8

pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
    {
        if(BusCar(GetPlayerVehicleID(playerid))) // This works
        {
            if(PlayerInfo[playerid][pJob] == 1)
            {
                SendClientMessage(playerid,-1,"{1589FF} Welcome Bus Driver.");
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!");
                RemovePlayerFromVehicle(playerid);
            }
        }
        if(MechanicCar(GetPlayerVehicleID(playerid))) // All the code under this don't work whatever I put under here
        {
            if(PlayerInfo[playerid][pJob] == 2)
            {
                SendClientMessage(playerid,-1,"{1589FF} Welcome Mechanic.");
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
Reply
#9

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
    {
        if(BusCar(GetPlayerVehicleID(playerid))) // This works
        {
            if(PlayerInfo[playerid][pJob] == 1)
            {
                SendClientMessage(playerid,-1,"{1589FF} Welcome Bus Driver.");
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!");
                RemovePlayerFromVehicle(playerid);
            }
        }
        if(MechanicCar(GetPlayerVehicleID(playerid))) // All the code under this don't work whatever I put under here
        {
            if(PlayerInfo[playerid][pJob] == 2)
            {
                SendClientMessage(playerid,-1,"{1589FF} Welcome Mechanic.");
            }
            else
            {
                SendClientMessage(playerid,COLOR_GREY,"This vehicle is LOCKED!");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
It's still the same, I don't know what's wrong with this but it's weird.
Reply
#10

Did you change GetPlayerState(playerid) to newstate?
Make sure you copy my code exactly.

If that doesn't work, then the problem is most likely in your 'TowTrucks' array.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)