SetTimerEx work twice in OnPlayerSpawn
#1

Hello my friends, trying to make the wanted level down (1 by 1) but my timer remove 2 stars insead 1

I active the timer in OnPlayerSpawn

PHP код:
WantedTimer[playerid] = SetTimerEx("RemoveWantedLevel", 20000, true, "i", playerid); 
PHP код:
public RemoveWantedLevel(playerid)
{
    if(
IsLogged(playerid))
    {
        new 
WantedLevel = GetPlayerWantedLevel(playerid), tmp_wanted;
        
        switch(
WantedLevel)
        {
            case 
6: tmp_wanted = 5;
            case 
5: tmp_wanted = 4;
            case 
4: tmp_wanted = 3;
            case 
3: tmp_wanted = 2;
            case 
2: tmp_wanted = 1;
            case 
1: tmp_wanted = 0;
        }
        
SetPlayerWantedLevel(playerid, tmp_wanted);
    }
    return 
1;
} 
EDIT: Was a trouble by me, calling 2 times OnPlayerSpawn with ToglePlayerSpectate inside a stock to spawn the player.
Reply
#2

use it on OnPlayerConnect and use the code like this, it's better:
pawn Код:
public RemoveWantedLevel(playerid)
{
    if(IsLogged(playerid) && GetPlayerWantedLevel(playerid) >= 1) SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)-1)
    return 1;
}
Reply
#3

You should always kill a timer before setting it to run, it will avoid overlaps and what not. And no, you are doing something wrong there, buddy. You just haven't noticed yet.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)