SA-MP Forums Archive
Need help with checking if a players been afk longer than 15 mins :D - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need help with checking if a players been afk longer than 15 mins :D (/showthread.php?tid=263222)



Need help with checking if a players been afk longer than 15 mins :D - peterRook - 21.06.2011

So far ive got the afk and back system inplace but need help with checking if the player has been afk longer than 15 mins help? the timers in for the check but dont know what to put >_<'

Код:
#include <a_samp>

public OnGameModeInit()
{
SetTimer("AFKCHECKER", 900000, true);
}

forward AFKCHECKER

public OnCommandText(playerid, cmdtext[])
{
if(strcmp(cmd, "/afk", true) == 0)
        {
            if(IsPlayerConnected(playerid))
            {
			new PlayerText3D:playertextid;
    		new Float:X, Float:Y, Float:Z;
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			format(string, sizeof(string), "* AFK: Player %s is now AFK ", sendername);
			TogglePlayerControllable(playerid, 0)
    		GetPlayerPos( playerid, X, Y, Z );
    		playertextid = CreatePlayer3DTextLabel(playerid, "AFK: %s is afk", COLOR_GREEN, x, y, z, 30);
    		Attach3DTextLabelToPlayer(playertextid, playerid, y, x, z)
    		return 1;
    		}
		}
		
if(strcmp(cmd, "/back", true) == 0)
        {
            if(IsPlayerConnected(playerid))
            {
            Delete3DTextLabel(playertextid);
			TogglePlayerControllable(playerid, 1)
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			format(string, sizeof(string), "* AFK: Player %s is now BACK from AFK ", sendername);
			return 1;
			}
		}
}

public AFKCHECKER
{
}



Re: Need help with checking if a players been afk longer than 15 mins :D - Basicz - 21.06.2011

pawn Код:
// After #includes

new
    pAFKTimer[ MAX_PLAYERS ],
    isAFK[ MAX_PLAYERS ]
;

// OnPlayerConnect

pAFKTimer[ playerid ] = SetTimerEx( "getAFK", 900000, true, "i", playerid );
isAFK[ playerid ] = 0;

// OnPlayerUpdate

if ( isAFK[ playerid ] == 1 )
{
    new
        szString[ 128 ]
    ;

    format( szString, sizeof szString, "* %s is now back on the server.", getpName( playerid ) );

    SendClientMessageToAll( 0xFFFFFFAA, szString );
}

KillTimer( pAFKTimer[ playerid ] );
pAFKTimer[ playerid ] = SetTimerEx( "getAFK", 900000, true, "i", playerid );

// Add this somewhere on your script ( not in a callback / function ).

stock getpName( playerid )
{
    new
        pName[ 24 ]
    ;

    return GetPlayerName( playerid, pName, sizeof pName ), pName;
}

forward getAFK( playerid ); public getAFK( playerid )
{
    new
        szString[ 128 ]
    ;

    format( szString, sizeof szString, "* %s is now AFK.", getpName, playerid );

    SendClientMessageToAll( 0xFFFFFFAA, szString );

    isAFK[ playerid ] = 1;

    return 1;
}
Honestly, I don't know will that works or not, but you'll need to test it.