Help with OnPlayerUpdate
#1

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?
Reply
#2

the reason is this callback is called very frequently per second per player
Reply
#3

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?
Reply
#4

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


Forum Jump:


Users browsing this thread: 3 Guest(s)