AFK system help
#1

hey so I have an afk system that is working fine but is there is a way that if the player stops moving for a while he goes afk I can set the timer but I need the function here is the code if required:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    GetPlayerName(playerid, names, sizeof(names));

	if (strcmp("/afk", cmdtext, true, 10) == 0)
	{
		if(IsAfk[playerid]) return SendClientMessage(playerid, 0xADD8E6FF, "You're already in AFK mode.");
		IsAfk[playerid] = 1;
		TogglePlayerControllable(playerid, 0);
	format(string,sizeof(string),"%s is AFK.", names);
	SendClientMessageToAll(0xFFFF00FF, string);
	GetPlayerPos(playerid, X, Y, Z);
	GetPlayerHealth(playerid, health);
	afktext = CreatePlayer3DTextLabel(playerid,"Player is in AFK mode.",0xFF0000FF, X,Y,Z,40.0);
		return 1;
	}
	if (strcmp("/back", cmdtext, true, 10) == 0)
	{
		if(IsAfk[playerid] == 1)
		{
			Afk_Back(playerid);
		}
		else
		SendClientMessage(playerid, 0xFF0000FF, "You're not AFK!.");
		return 1;
	}
	return 0;
}

/*public OnPlayerStateChange(playerid, newstate, oldstate)
{
        if(IsAfk[playerid] == 1)
        {
                Afk_Back(playerid);
        }
        else
           SendClientMessage(playerid, 0xADD8E6FF, "You're not in AFK mode.");
        return 1;
}*/

stock Afk_Back(playerid)
{
        IsAfk[playerid] = 0;
        TogglePlayerControllable(playerid, 1);
    format(string,sizeof(string),"%s is back.", names);
    SendClientMessageToAll(0xFFFF00FF, string);
    DeletePlayer3DTextLabel(playerid, afktext);
    return 1;
}
Reply
#2

Quote:
Originally Posted by Method 1
PHP код:
#include <YSI/y_timers>
new Float:lastpos[MAX_PLAYERS][3];
new 
afk_strike[MAX_PLAYERS];
ptask IsAFK[1000](playerid)
{
    if(
Is_AFK[playerid] == false)
    {
        new 
Float:newpos[3];
        
GetPlayerPos(playeridnewpos[0], newpos[1], newpos[2]);
        if(
newpos[0] == lastpos[0] && newpos[1] == lastpos[1] && newpos[2] == lastpos[2])
        {
            
afk_strike++;
            if(!(
afk_strike 30))
            {
                
PutHimInAFK(playerid);
            }
        }
        else
            
afk_strike 0;
    }
    return 
1;

Quote:
Originally Posted by Method 2
PHP код:
new Float:lastpos[MAX_PLAYERS][3];
new 
afk_strike[MAX_PLAYERS];
forward IsAFK(playerid);
public 
IsAFK(playerid)
{
    if(
Is_AFK[playerid] == false)
    {
        new 
Float:newpos[3];
        
GetPlayerPos(playeridnewpos[0], newpos[1], newpos[2]);
        if(
newpos[0] == lastpos[0] && newpos[1] == lastpos[1] && newpos[2] == lastpos[2])
        {
            
afk_strike++;
            if(!(
afk_strike 30))
            {
                
PutHimInAFK(playerid);
            }
        }
        else
            
afk_strike 0;
    }
    return 
1;
}
new 
TimerID[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
    
TimerID[playerid] = SetTimer("IsAFK"1000true"i"playerid);
}
public 
OnPlayerDisconnect(playerid)
{
    
KillTimer(TimerID[playerid]);

Use any of the above to check if a player is standing Idle.. Clear variables on Disconnect/Connect
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)