PDA

View Full Version : Help with OnPlayerUpdate


danielpalade
22/04/2015, 08:50 PM
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?

Azula
22/04/2015, 08:55 PM
the reason is this callback is called very frequently per second per player

danielpalade
22/04/2015, 10:52 PM
the reason is this callback is called very frequently per second per player

And is there a way to stop it?

Abagail
22/04/2015, 10:55 PM
You can store if they've seen the message inside of a variable.
Ex:

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