Whats wrong with Afk Check?
#1

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
Reply
#2

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);
    }
Reply
#3

Still not working.
What i did wrong?
Reply
#4

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.
Reply
#5

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?
Reply
#6

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

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;
}
Reply
#8

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

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
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)