OnPlayerUpdate HELP
#1

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?

Reply
#2

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.");
Reply
#3

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)