SendClientMessage spamming the chat
#1

So, I made something that if the player targets actor and its robbed recently then the message comes as "This store has been robbed recently......."

but when I aim at the actor, the message is like spamming on the mainchat, how to make that message appear only once?

The code:
pawn Код:
public OnPlayerUpdate(playerid)
{
    new playerTargetActor = GetPlayerTargetActor(playerid);

    if(playerTargetActor != INVALID_ACTOR_ID)
    {
        if(baseactorrobbed >= 1 && robbingstore[playerid] == 0)
        {
        SendClientMessage(playerid, -1, "{1E90FF}[ERROR] {FFFFFF}This store has been robbed recently. Please try again later.");
        return 1;
        }
        return 1;
    }
The picture how it's spamming:
Reply
#2

From what I know, callback OnPlayerUpdate is repeating within your ping time in ms. That's the cause your chat gets spammed while you point your gun at the actor.
Reply
#3

I think, it's because OnPlayerUpdate(playerid) is called at least per seconds. If you do an action, OnPlayerUpdate, will be called. So aiming something, shoot, walk, drive, etc .. call OnPlayerUpdate(playerid) like every 0,5 sec (IT'S NOT THE EXACT VALUE).

So, I think you should add a new variable like warnedPlayer[playerid] and this resetting every minute or 2 mins, etc..
I hope this helped you!
Reply
#4

Код:
public OnPlayerUpdate(playerid)
{
    new playerTargetActor = GetPlayerTargetActor(playerid);

    if(playerTargetActor != INVALID_ACTOR_ID)
    {
		if(baseactorrobbed >= 1 && robbingstore[playerid] == 0)
		{
		SendClientMessage(playerid, -1, "{1E90FF}[ERROR] {FFFFFF}This store has been robbed recently. Please try again later.");
		return 1;
		}
		return 1;
	}
bad way to script make sure don't use OnPlayerUpdate alot.

Well i suggest you to make Array.
Like
PlaceIsRobbed[How many robbing places u have];

then
When he complete that rob
Set PlaceIsRobbed[PlaceID] = 1;
then
Start SetTimerEx("NotAvailableToRob",5*60*1000,0,'i',Pla ceID);

public NotAvailableToRob(PlaceID)
{
PlaceIsRobbed[PlaceID] = 0; // that will availabe that place to rob again.
}

Also Check if When he enter inside Checkpoint That doesn't =1 if it equal to one that mean it is not available to rob.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)