AfkManager: add GetClientIdleTime native

This commit is contained in:
BotoX 2016-09-09 22:43:02 +02:00
parent ce896e1a04
commit 0e1c5fbda3
2 changed files with 62 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <AfkManager>
#undef REQUIRE_PLUGIN
#include <zombiereloaded>
@ -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];
}

View File

@ -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