sm-plugins/PlaytimeReward/scripting/PlaytimeReward.sp

73 lines
1.6 KiB
SourcePawn
Raw Normal View History

2018-07-23 10:49:15 +02:00
#pragma semicolon 1
#include <sourcemod>
2019-06-02 23:21:03 +02:00
#include <hlstatsx_loghelper>
2018-07-23 10:49:15 +02:00
#pragma newdecls required
int g_iClientConnectionTime[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "PlaytimeReward",
author = "Obus + Dogan",
description = "reward players with points for playing on the server",
version = "1.0.0"
2018-07-23 10:49:15 +02:00
};
public void OnPluginStart()
{
CreateTimer(30.0, Timer_CheckConnectionTime, _, TIMER_REPEAT);
HookEvent("player_disconnect", EventHook_PlayerDisconnect, EventHookMode_Post);
}
public void OnPluginEnd()
{
UnhookEvent("player_disconnect", EventHook_PlayerDisconnect, EventHookMode_Post);
}
public void EventHook_PlayerDisconnect(Event hEvent, const char[] sName, bool bDontBroadcast)
{
bool bIsBot = view_as<bool>(hEvent.GetInt("bot"));
if (bIsBot)
return;
int client = GetClientOfUserId(hEvent.GetInt("userid"));
g_iClientConnectionTime[client] = 0;
}
public Action Timer_CheckConnectionTime(Handle hThis)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i))
continue;
2018-12-16 14:10:15 +01:00
g_iClientConnectionTime[i] += 30;
2018-12-16 14:10:15 +01:00
for (int iTime = 1800; iTime <= 36000; iTime += 1800)
{
if ((g_iClientConnectionTime[i] % 1800) == 0)
{
int iConnectionTimeClamped = g_iClientConnectionTime[i];
if (iConnectionTimeClamped > 36000)
iConnectionTimeClamped = 36000;
2018-12-23 13:15:55 +01:00
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "staying_server_%d", iConnectionTimeClamped / 60);
2018-12-23 13:15:55 +01:00
2019-06-02 23:21:03 +02:00
LH_LogPlayerEvent(i, "triggered", sPlayerEvent, true);
break;
}
}
}
2018-07-23 10:49:15 +02:00
}
stock bool IsValidClient(int client)
{
return (client >= 1 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));
}