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=280351)



OnPlayerStateChange - Wesley221 - 31.08.2011

Hey guys,
Im having problems with the callback OnPlayerStateChange. Im trying to check that the newstate == driver, and the oldstate == onfoot, and then show him a textdraw. Somehow it doesnt work, but in game it shows its changing.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[39];
    format(string, sizeof(string), "You changed from state %d to state %d!", oldstate, newstate);
    SendClientMessage(playerid,0xFFFFFFFF,string);
    if( oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT )
    {
   
        TextDrawHideForPlayer(playerid, Speedo[playerid]);
    }
    if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
        TextDrawShowForPlayer(playerid, Speedo[playerid]);
    }
    return 1;
}
It shows "You changed from state %d to state %d!" in game, with the %d with a number ofcourse.
Anyone knows what the problem is?


Re : OnPlayerStateChange - Naruto_Emilio - 31.08.2011

pawn Код:
if(newstate == PLAYER_STATE_ONFOOT )
        {
   
        TextDrawHideForPlayer(playerid, Speedo[playerid]);
    }
    if(newstate == PLAYER_STATE_DRIVER )
    {
        TextDrawShowForPlayer(playerid, Speedo[playerid]);
    }
    return 1;
}
try this hope it works for you


Re: OnPlayerStateChange - Wesley221 - 31.08.2011

I just debugged all of it, and i found out its skipping one line.
"vehicleid = GetPlayerVehicleID(playerid);".
I do have new vehicle; above it.


Re : OnPlayerStateChange - Naruto_Emilio - 31.08.2011

did you used
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
.


Re: OnPlayerStateChange - Wesley221 - 31.08.2011

pawn Код:
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid); // it skips this line, and just continues the things that are down this



Re : Re: OnPlayerStateChange - Naruto_Emilio - 31.08.2011

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
pawn Код:
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid); // it skips this line, and just continues the things that are down this
try
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);



Re: OnPlayerStateChange - Wesley221 - 31.08.2011

I did that and still was the same


Re : OnPlayerStateChange - Naruto_Emilio - 31.08.2011

Then in the place vehicleid in your script use GetPlayerVehicleID(playerid);
Example:
pawn Код:
if(GetPlayerVehicleID == watever car)



Re: OnPlayerStateChange - IceCube! - 31.08.2011

Removed... just looked and saw my error


Re: OnPlayerStateChange - Wesley221 - 01.09.2011

Now it skips "TextDrawSetSTring()" and "TextDrawShowForPlayer();.

pawn Код:
TextDrawSetString(Speedo[playerid], Vehstring);
TextDrawShowForPlayer(playerid, Speedo[playerid]);
I did format the Vehstring, dont worry about that.