sm-plugins/PlaytimeReward/scripting/PlaytimeReward.sp

85 lines
1.7 KiB
SourcePawn
Raw Normal View History

2018-07-23 10:49:15 +02:00
#pragma semicolon 1
#include <sourcemod>
#include "loghelper.inc"
#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 OnMapStart()
{
GetTeams();
}
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))
2018-12-16 01:59:26 +01:00
continue;
2018-07-23 10:49:15 +02:00
g_iClientConnectionTime[i] += 30;
char sPlayerEvent[32];
int iTime = 1800;
for (;;)
{
if ((g_iClientConnectionTime[i] / iTime) < 1.0)
{
if (iTime == 1800)
break;
if (iTime >= 36000)
{
LogPlayerEvent(i, "triggered", "staying_server_600");
g_iClientConnectionTime[i] = 0; //start over, but i doubt someone will ever reach so far ;)
}
Format(sPlayerEvent, sizeof(sPlayerEvent), "staying_server_%d", (iTime - 1800) / 60);
LogPlayerEvent(i, "triggered", sPlayerEvent);
break;
}
iTime += 1800;
2018-07-23 10:49:15 +02:00
}
}
}
stock bool IsValidClient(int client)
{
return (client >= 1 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));
}