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



OnPlayerUpdate HELP - Supermaxultraswag - 08.11.2014

public OnPlayerUpdate(playerid)
{
if (GetPlayerScore(playerid) > 100)
{
SendClientMessage(playerid, -1, "hey");
}
return 1;
}

it starts to send me messages continuously, when i reach 100 score... i need a only one message... how can i fix this?




Re: OnPlayerUpdate HELP - dominik523 - 08.11.2014

This will send "hey" only when the player has score of 100. You could place this under some other callback as OnPlayerUpdate is too fast for this.
Код:
public OnPlayerUpdate(playerid)
{
if (GetPlayerScore(playerid) == 100) 
{
SendClientMessage(playerid, -1, "hey");
}
return 1;
}
The best way to do what you want is something like this:
Код:
// this should go when you call SetPlayerScore
new OldScore = GetPlayerScore(playerid);
SetPlayerScore(playerid, OldScore + 1); // this can be anything you want
if(OldScore < 100 && GetPlayerScore(playerid) >= 100)
	SendClientMessage(playerid, -1, "You have reached 100 score.");



Re: OnPlayerUpdate HELP - Supermaxultraswag - 08.11.2014

Quote:
Originally Posted by dominik523
Посмотреть сообщение
This will send "hey" only when the player has score of 100. You could place this under some other callback as OnPlayerUpdate is too fast for this.
Код:
public OnPlayerUpdate(playerid)
{
if (GetPlayerScore(playerid) == 100) 
{
SendClientMessage(playerid, -1, "hey");
}
return 1;
}
The best way to do what you want is something like this:
Код:
// this should go when you call SetPlayerScore
new OldScore = GetPlayerScore(playerid);
SetPlayerScore(playerid, OldScore + 1); // this can be anything you want
if(OldScore < 100 && GetPlayerScore(playerid) >= 100)
	SendClientMessage(playerid, -1, "You have reached 100 score.");
Thank you, but doesnt this line "SetPlayerScore(playerid, OldScore + 1);" add 1 score to player? I just want to check player scores, not add them.


Re: OnPlayerUpdate HELP - biker122 - 08.11.2014

As provided above in the last 2nd post, or declare a new global variable and do this:
pawn Код:
//Before your callbacks & commands
new HSent[MAX_PLAYERS] = 0;

public OnPlayerUpdate(playerid)
{
    if(HSent[playerid] == 0)
    {
        if(GetPlayerScore(playerid) >= 100)
        {
            SendClientMessage(playerid, -1, "hey");
            HSent[playerid] = 1;
        }
    }
    return 1;
}



Re: OnPlayerUpdate HELP - dominik523 - 08.11.2014

Yes, it will add 1 score. That was just an example of where you can check if the player has reached 100 score.