SA-MP Forums Archive
Help with OnPlayerUpdate - 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: Help with OnPlayerUpdate (/showthread.php?tid=571829)



Help with OnPlayerUpdate - danielpalade - 22.04.2015

So, this is my code:

Код:
public OnPlayerUpdate(playerid)
{
	new vehicleid = GetPlayerVehicleID(playerid);
	if(IsTrailerAttachedToVehicle(vehicleid))
	{
		SendClientMessage(playerid, COLOR_MAXZONE, "Test");
	}
	return 1;
}
For some reason it spams my chat with Test when a trailer is attach. How can I fix this?


Re: Help with OnPlayerUpdate - Azula - 22.04.2015

the reason is this callback is called very frequently per second per player


Respuesta: Re: Help with OnPlayerUpdate - danielpalade - 22.04.2015

Quote:
Originally Posted by Azula
Посмотреть сообщение
the reason is this callback is called very frequently per second per player
And is there a way to stop it?


Re: Help with OnPlayerUpdate - Abagail - 22.04.2015

You can store if they've seen the message inside of a variable.
Ex:
pawn Код:
new PlayerSawMessage[MAX_PLAYERS] = -1;
public OnPlayerUpdate(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(IsTrailerAttachedToVehicle(vehicleid) && ~PlayerSawMessage[playerid])
    {
        SendClientMessage(playerid, COLOR_MAXZONE, "Test");
                PlayerSawMessage[playerid] = 0;
    }
        else if(PlayerSawMessage[playerid]) PlayerSawMessage[playerid] = -1;
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    PlayerSawMessage[playerid] = -1;
    return true;
}