SA-MP Forums Archive
Whats wrong with Afk Check? - 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: Whats wrong with Afk Check? (/showthread.php?tid=334405)



Whats wrong with Afk Check? - Admigo - 14.04.2012

Heey all,

I used a code on forums for checking players who are afk.
But everyone have the 3dtextlabel Paused when they dont afk.
Код:
//onplayerupdate
if( GetPVarInt(playerid, "pause") != 0 )
	{
		label=Create3DTextLabel("Paused!",0xFFFFFFFF,30.0,40.0,50.0,40.0,0 ,0);
	    Attach3DTextLabelToPlayer(label, playerid, 0.0, 0.0, 0.7);
 	}
 	else if( GetPVarInt(playerid, "pause") == 0 )
	{
		Delete3DTextLabel(label);
	}
	SetPVarInt(playerid, "pause", 1);
Please,how can i fix this?

Thanks Admigo


Re: Whats wrong with Afk Check? - mineralo - 14.04.2012

try this
pawn Код:
if( GetPVarInt(playerid, "pause") != 0 )
    {
        label=Create3DTextLabel("Paused!",0xFFFFFFFF,30.0,40.0,50.0,40.0,0 ,0);
        Attach3DTextLabelToPlayer(label, playerid, 0.0, 0.0, 0.7);
    }
    else
    {
        Delete3DTextLabel(label);
    }



Re: Whats wrong with Afk Check? - Admigo - 14.04.2012

Still not working.
What i did wrong?


Re: Whats wrong with Afk Check? - Cypress - 14.04.2012

pawn Код:
new
     LastUpdate[MAX_PLAYER],
     Text3D:Paused[MAX_PLAYERS];


public OnGameModeInti()
{
   SetTimer("Paused",1000, 1);
   return 1;
}

public OnPlayerUpdate(playerid)
{
   LastUpdate[playerid] = gettime();
   return 1;
}

forward Paused(playerid);
public Paused(playerid)
{
   for(new i = 0; i < MAX_PLAYERS; i++)
   {
       if(gettime() - LastUpdate[i] >=5)
       {
           Paused[i] = Create3DTextLabel("Paused",-1,30.0,40.0,50.0,40.0,0);
           Attach3DTextLabelToPlayer(Paused[i], playerid, 0.0, 0.0, 0.7);
       }
       else
       {
           Delete3DTextLabel(Paused[i]);
       }  
   }
   return 1;
}
I guess it's better using a custom 1 second timer than putting this code into OnPlayerUpdate.


Re: Whats wrong with Afk Check? - Admigo - 14.04.2012

Quote:
Originally Posted by Cypress
Посмотреть сообщение
pawn Код:
new
     LastUpdate[MAX_PLAYER],
     Text3D:Paused[MAX_PLAYERS];


public OnGameModeInti()
{
   SetTimer("Paused",1000, 1);
   return 1;
}

public OnPlayerUpdate(playerid)
{
   LastUpdate[playerid] = gettime();
   return 1;
}

forward Paused(playerid);
public Paused(playerid)
{
   for(new i = 0; i < MAX_PLAYERS; i++)
   {
       if(gettime() - LastUpdate[i] >=5)
       {
           Paused[i] = Create3DTextLabel("Paused",-1,30.0,40.0,50.0,40.0,0);
           Attach3DTextLabelToPlayer(Paused[i], playerid, 0.0, 0.0, 0.7);
       }
       else
       {
           Delete3DTextLabel(Paused[i]);
       }  
   }
   return 1;
}
I guess it's better using a custom 1 second timer than putting this code into OnPlayerUpdate.
Dont work
Tested with a beta tester on my server.
He pressed escape and alt+tabbed but the 3dlabel dont shows above head.
Please,how can i fix this?


Re: Whats wrong with Afk Check? - MP2 - 14.04.2012

You're deleting the 'paused' label even if they haven't just returned from being paused.


Re: Whats wrong with Afk Check? - FalconX - 14.04.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
You're deleting the 'paused' label even if they haven't just returned from being paused.
Come on admingo why are you even using Pvars when you can do with simple method

pawn Код:
forward Checking();

forward OnPlayerPause(playerid);
 
new iAFKp[MAX_PLAYERS];
 
public OnFilterScriptInit() // or game mode init
{
        SetTimer("Checking", 1000, true);
        return 1;
}

public Checking()
{
    for(new x = 0; x < MAX_PLAYERS; x++)
    {
        iAFKp[x]++;
        if(iAFKp[x] > 3)
        {
                        OnPlayerPause(x);
        }
    }
}
 

public OnPlayerPause(playerid)
{
        new tmpstring[128];
        format(tmpstring, sizeof(tmpstring), "PAUSED for %d seconds", iAFKp[playerid]);
        SetPlayerChatBubble(playerid, tmpstring, COLOR, 10.0, 1000);
        return 1;
}

public OnPlayerUpdate(playerid) // to check if he is paused, onplayerupdate stops if a player press ESC so it's best to do this way
{
        iAFKp[playerid] = 0;
        return 1;
}



Re: Whats wrong with Afk Check? - MP2 - 14.04.2012

His method is more efficient, calling a timer once a second is pointless as gettime()-variable has the EXACT same result, minus the timer!


Re: Whats wrong with Afk Check? - FalconX - 14.04.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
His method is more efficient, calling a timer once a second is pointless as gettime()-variable has the EXACT same result, minus the timer!
You are right but as he is not a very professional in scripting and is new in this field (no offense at all), this way is good for him as far as I think

-FalconX


Re: Whats wrong with Afk Check? - Admigo - 15.04.2012

Quote:
Originally Posted by ue_falconx
Посмотреть сообщение
Come on admingo why are you even using Pvars when you can do with simple method

pawn Код:
forward Checking();

forward OnPlayerPause(playerid);
 
new iAFKp[MAX_PLAYERS];
 
public OnFilterScriptInit() // or game mode init
{
        SetTimer("Checking", 1000, true);
        return 1;
}

public Checking()
{
    for(new x = 0; x < MAX_PLAYERS; x++)
    {
        iAFKp[x]++;
        if(iAFKp[x] > 3)
        {
                        OnPlayerPause(x);
        }
    }
}
 

public OnPlayerPause(playerid)
{
        new tmpstring[128];
        format(tmpstring, sizeof(tmpstring), "PAUSED for %d seconds", iAFKp[playerid]);
        SetPlayerChatBubble(playerid, tmpstring, COLOR, 10.0, 1000);
        return 1;
}

public OnPlayerUpdate(playerid) // to check if he is paused, onplayerupdate stops if a player press ESC so it's best to do this way
{
        iAFKp[playerid] = 0;
        return 1;
}
I dont want to know how much seconds a player is paused. I want to have a paused label above his head and when he is back in game it will be removed.