SA-MP Forums Archive
[HELP] AFK Problems (May be related to the new foreach) - 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: [HELP] AFK Problems (May be related to the new foreach) (/showthread.php?tid=358950)



[HELP] AFK Problems (May be related to the new foreach) - wups - 12.07.2012

Hi guys,
recently I updated my foreach to the version with kick ability, though I don't know if that caused it.
Code:
pawn Код:
#define IsPlayerAfk(%0) (PlayerTick[%0]+5000 < GetTickCount())
public OnPlayerUpdate(playerid)
{
    PlayerTick[playerid]=GetTickCount();
    return 1;
}
public Check() // runs every second
{
    foreach (Player, playerid)
    {
                if(!IsPlayerAfk(playerid))
                {
                    // SOME ANTI-CHEAT CODE HERE WITH KICKS'N'BANS
                    if(PlayerAfk[playerid])
                    {
                        DestroyDynamic3DTextLabel(PlayerLabel[playerid]);
                        PlayerAfk[playerid]=false;
                    }
                }
                else
                {
                    if(!PlayerAfk[playerid])
                    {
                        PlayerLabel[playerid] = CreateDynamic3DTextLabel("AFK", COLOR_INDIGO, 0.0,0.0,0.0, 10.0, playerid);
                        PlayerAfk[playerid]=true;
                    }
                }
    }
}
This code worked perfectly before, but now the dynamic3dtextlabel doesn't disappear.
Another thing is that I don't restart my VPS server, and it has been running for 19 days now, maybe that could affect the tick count being wrong?


Re: [HELP] AFK Problems (May be related to the new foreach) - clarencecuzz - 12.07.2012

if(!IsPlayerAfk[playerid])

Does that mean the player IS or ISN'T AFK?


Re: [HELP] AFK Problems (May be related to the new foreach) - Neil. - 12.07.2012

Ain't this

PHP код:
#define IsPlayerAfk(%0) (PlayerTick[%0]+5000 < GetTickCount())
public OnPlayerUpdate(playerid)
{
    
PlayerTick[playerid]=GetTickCount();
    return 
1;
}
public 
Check() // runs every second
{
    foreach (
Playerplayerid)
    {
                if(!
IsPlayerAfk(playerid))
                {
                    
// SOME ANTI-CHEAT CODE HERE WITH KICKS'N'BANS
                    
if(PlayerAfk[playerid])
                    {
                        
DestroyDynamic3DTextLabel(PlayerLabel[playerid]);
                        
PlayerAfk[playerid]=false;
                    }
                }
                else
                {
                    if(!
PlayerAfk[playerid])
                    {
                        
PlayerLabel[playerid] = CreateDynamic3DTextLabel("AFK"COLOR_INDIGO0.0,0.0,0.010.0playerid);
                        
PlayerAfk[playerid]=true;
                    }
                }
    }

should be this?

PHP код:
#define IsPlayerAfk(%0) (PlayerTick[%0]+5000 < GetTickCount())
public OnPlayerUpdate(playerid)
{
    
PlayerTick[playerid]=GetTickCount();
    return 
1;
}
public 
Check() // runs every second
{
    foreach (
Playerplayerid)
    {
                if(!
IsPlayerAfk(playerid))
                {
                    
// SOME ANTI-CHEAT CODE HERE WITH KICKS'N'BANS
                    
if(PlayerAfk[playerid])
                    {
                        
DestroyDynamic3DTextLabel(PlayerLabel[playerid]);
                        
PlayerAfk[playerid]=false;
                    }
                }
                else
                {
                    if(
PlayerAfk[playerid])// This line
                    
{
                        
PlayerLabel[playerid] = CreateDynamic3DTextLabel("AFK"COLOR_INDIGO0.0,0.0,0.010.0playerid);
                        
PlayerAfk[playerid]=true;
                    }
                }
    }




Re: [HELP] AFK Problems (May be related to the new foreach) - clarencecuzz - 12.07.2012

If that's true, then it should be this:
pawn Код:
#define IsPlayerAfk(%0) (PlayerTick[%0]+5000 < GetTickCount())
public OnPlayerUpdate(playerid)
{
    PlayerTick[playerid]=GetTickCount();
    return 1;
}
public Check() // runs every second
{
    foreach (Player, playerid)
    {
                if(!IsPlayerAfk(playerid))
                {
                    // SOME ANTI-CHEAT CODE HERE WITH KICKS'N'BANS
                    if(!PlayerAfk[playerid])
                    {
                        DestroyDynamic3DTextLabel(PlayerLabel[playerid]);
                        PlayerAfk[playerid]=false;
                    }
                }
                else
                {
                    if(PlayerAfk[playerid])// This line
                    {
                        PlayerLabel[playerid] = CreateDynamic3DTextLabel("AFK", COLOR_INDIGO, 0.0,0.0,0.0, 10.0, playerid);
                        PlayerAfk[playerid]=true;
                    }
                }
    }
    return 1;
}



Re: [HELP] AFK Problems (May be related to the new foreach) - wups - 12.07.2012

People, You're missing the point. Recheck the code. Both of you are incorrect.


Re: [HELP] AFK Problems (May be related to the new foreach) - wups - 13.07.2012

Sorry for bumping.