SA-MP Forums Archive
OnPlayerStateChange - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerStateChange (/showthread.php?tid=453633)



OnPlayerStateChange - Muhamed.pwn - 25.07.2013

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.


Re: OnPlayerStateChange - Kebab- - 25.07.2013

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!


Re: OnPlayerStateChange - Muhamed.pwn - 25.07.2013

Still the same.


Re: OnPlayerStateChange - NotIntegrated - 25.07.2013

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



Re: OnPlayerStateChange - Muhamed.pwn - 25.07.2013

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


Re: OnPlayerStateChange - NotIntegrated - 25.07.2013

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


Re: OnPlayerStateChange - Muhamed.pwn - 25.07.2013

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;
}



Re: OnPlayerStateChange - Threshold - 26.07.2013

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);
            }
        }
    }



Re: OnPlayerStateChange - Muhamed.pwn - 26.07.2013

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.


Re: OnPlayerStateChange - Threshold - 26.07.2013

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.