CheckDerby gets called twice.
#1

I am still on the process creating the 11th game for X Games Series, the Derby!

I am having some problems with the CheckDerby.
Information about CheckDerby: It is used to detect if the player has fallen out of the arena by checking the Z height.

I have tried making a bool variable and set it to true if a winner is declared, so in that way the next time CheckDerby is called in, it will be blocked in by the code i placed in (returning 1 instead). However this didn't worked. The timer is set to be called for 3500 mileseconds. This callback gets called twice or thrice.. Help me out bruh.

PHP код:
forward CheckDerby();
public 
CheckDerby()
{
    new 
string[150];
    if(
derby_time == false) return 1;
    if(
winner_derby == true) return 1;
    foreach(
derbyplayerid)
    {
        new 
Float:_pos[3];
        
GetPlayerPos(playerid_pos[0], _pos[1], _pos[2]);
        switch(
mode)
        {
            case 
DB_ID:
            {
                if(
_pos[2] <= 10)
                {
                    if(
OnDerby[playerid] == true)
                    {
                        
format(stringsizeof string"Eliminated:"white" %s has lost the derby [Fall out of Arena] (%d position)"GetName(playerid), Iter_Count(derby));
                        
SendClientMessageToAll(COLOR_REDstring);
                        
Iter_Remove(derbyplayerid);
                        new 
specplayer Iter_Random(derby);
                        
StartSpectate(playeridspecplayer);
                        
OnDerby[playerid] = false;
                    }
                    if (
Iter_Count(derby) == 1)
                    {
                        foreach(
derbyx)
                        {
                            
format(stringsizeof string"Winner:"white" %s has won the Derby, they won 5+ scores, 4 cakes and $2500"GetName(x));
                            
SendClientMessageToAll(COLOR_GREENstring);
                            
SetPlayerScore(xGetPlayerScore(x) + 5);
                            
GivePlayerCash(x2500);
                            
GiveCake(x4);
                            
User[x][accountDerby] ++;
                            
winner_derby true;
                            
SetTimer("ProcessEnding"3500false);
                            
KillTimer(timer);
                            
KillTimer(timer2);
                        }
                    }
                }
            }
        }
    }
    return 
1;

Reply
#2

4char, Bump.
Reply
#3

Propably it should be something like this

pawn Код:
forward CheckDerby();
public CheckDerby()
{

    if(derby_time == false) return 0;
    if(winner_derby == true) return 0;

    new string[145], Float:_pos[3];
    foreach(derby, playerid)
    {
        if(OnDerby[playerid])
        {
            GetPlayerPos(playerid, _pos[0], _pos[1], _pos[2]);
            switch(mode)
            {
                case DB_ID:
                {
                    if(_pos[2] < 10.1)
                    {
                        format(string, sizeof string, "Eliminated:"white" %s has lost the derby [Fall out of Arena] (%d position)", GetName(playerid), Iter_Count(derby));
                        SendClientMessageToAll(COLOR_RED, string);
                        Iter_Remove(derby, playerid);
                        new specplayer = Iter_Random(derby);
                        StartSpectate(playerid, specplayer);
                        OnDerby[playerid] = false;
                    }
                }
            }
        }
    }

    if(Iter_Count(derby) < 2)
    {
        foreach(derby, x)
        {
            format(string, sizeof string, "Winner:"white" %s has won the Derby, they won 5+ scores, 4 cakes and $2500", GetName(x));
            SendClientMessageToAll(COLOR_GREEN, string);
            SetPlayerScore(x, GetPlayerScore(x) + 5);
            GivePlayerCash(x, 2500);
            GiveCake(x, 4);
            User[x][accountDerby] ++;
        }
        winner_derby = true;
        SetTimer("ProcessEnding", 3500, false);
        KillTimer(timer);
        KillTimer(timer2);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)