Timer rank spam
#1

I am tired of getting the spam in chat using my script's rank system.

Here is my code:
pawn Код:
public RankDetection(playerid)
{
    if(PlayerInfo[playerid][Xp] == 0)
    {
        SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private II!");
        PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
        return 0;
    }
    return 0;
}
I've tried OnPlayerUpdate, I have tried return 1. I don't get what the problem is. There are no errors, just it spams you in game.
Thanks for any help.
Reply
#2

Can you show us your timer? It's probably looping over and over.
Reply
#3

Variable.
pawn Код:
Detected[MAX_PLAYERS];
pawn Код:
public RankDetection(playerid)
{
    if(PlayerInfo[playerid][Xp] == 0 && Detected[playerid] != 1 )
    {
        SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private II!");
        PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
        Detected[playerid] = 1;
        return 1;
    }
    return 1;
}
Reply
#4

Infamouz,

It's called in OnPlayerConnect, but here is the line with SetTimerEx:
pawn Код:
rtimer = SetTimerEx("RankDetection", 1500, 1, "i", playerid);
I have a feeling it is because i set it to whenever it is equal to.
Reply
#5

Thanks Dark_Rain, got it to work
Reply
#6

Well you could use the suggestion above although I would prefer to call the timer once every-time the players rank is set/increased.
Reply
#7

Dark_Rain, how can i set it so that i can do it with more than one rank? Because the same code wouldnt work because it would be detected.
Reply
#8

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
Dark_Rain, how can i set it so that i can do it with more than one rank? Because the same code wouldnt work because it would be detected.
Use a switch/case statement.
pawn Код:
switch(PlayerInfo[playerid][Xp])
{
     case 20:
               {
                    SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private I!");
               }
     case 40:
               {
                    SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private II!");
               }
                   //etc.
}
And I recommend not using any timers for that, just call the function whenever the score increases.
Reply
#9

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Use a switch/case statement.
pawn Код:
switch(PlayerInfo[playerid][Xp])
{
     case 20:
               {
                    SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private I!");
               }
     case 40:
               {
                    SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private II!");
               }
                   //etc.
}
And I recommend not using any timers for that, just call the function whenever the score increases.
Could you explain more?
Reply
#10

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
Could you explain more?
Explain what? The code or the suggestion?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)