diff --git a/AfkManager/scripting/AfkManager.sp b/AfkManager/scripting/AfkManager.sp index eefadbff..fc482a4c 100644 --- a/AfkManager/scripting/AfkManager.sp +++ b/AfkManager/scripting/AfkManager.sp @@ -1,6 +1,7 @@ #include #include #include +#include #undef REQUIRE_PLUGIN #include @@ -70,7 +71,7 @@ public void Cvar_Immunity(ConVar convar, const char[] oldValue, const char[] new public void OnPluginStart() { - Handle cvar; + ConVar cvar; HookConVarChange((cvar = CreateConVar("sm_afk_move_min", "10", "Min players for AFK move")), Cvar_MoveMinPlayers); g_iMoveMinPlayers = GetConVarInt(cvar); @@ -103,6 +104,14 @@ public void OnPluginStart() AutoExecConfig(true, "plugin.AfkManager"); } +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + CreateNative("GetClientIdleTime", Native_GetClientIdleTime); + RegPluginLibrary("AfkManager"); + + return APLRes_Success; +} + public void OnMapStart() { CreateTimer(AFK_CHECK_INTERVAL, Timer_CheckPlayer, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); @@ -402,3 +411,31 @@ public Action Timer_CheckPlayer(Handle Timer, any Data) return Plugin_Continue; } + +public int Native_GetClientIdleTime(Handle plugin, int numParams) +{ + int client = GetNativeCell(1); + + if(client > MaxClients || client <= 0) + { + ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid."); + return -1; + } + + if(!IsClientInGame(client)) + { + ThrowNativeError(SP_ERROR_NATIVE, "Client is not in-game."); + return -1; + } + + if(IsFakeClient(client)) + { + ThrowNativeError(SP_ERROR_NATIVE, "Client is fake-client."); + return -1; + } + + if(!g_Players_bEnabled[client]) + return 0; + + return GetTime() - g_Players_iLastAction[client]; +} diff --git a/AfkManager/scripting/include/AfkManager.inc b/AfkManager/scripting/include/AfkManager.inc new file mode 100644 index 00000000..108254bf --- /dev/null +++ b/AfkManager/scripting/include/AfkManager.inc @@ -0,0 +1,24 @@ +#if defined _AfkManager_Included + #endinput +#endif +#define _AfkManager_Included + +native int GetClientIdleTime(int client); + +public SharedPlugin __pl_AfkManager = +{ + name = "AfkManager", + file = "AfkManager.smx", +#if defined REQUIRE_PLUGIN + required = 1, +#else + required = 0, +#endif +}; + +#if !defined REQUIRE_PLUGIN +public __pl_AfkManager_SetNTVOptional() +{ + MarkNativeAsOptional("GetClientIdleTime"); +} +#endif