sm-plugins/PlaytimeReward/scripting/PlaytimeReward.sp

63 lines
1.4 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_iClientSteamAccountID[MAXPLAYERS + 1];
2018-07-23 10:49:15 +02:00
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);
}
2018-07-23 10:49:15 +02:00
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
int iSteamAccountID = GetSteamAccountID(i);
if (g_iClientSteamAccountID[i] != iSteamAccountID)
{
g_iClientSteamAccountID[i] = iSteamAccountID;
g_iClientConnectionTime[i] = 0;
}
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));
}