sm-plugins/hlstatsx/scripting/hlstatsx_difficulty.sp

146 lines
5.4 KiB
SourcePawn
Raw Normal View History

2018-08-07 22:13:31 +02:00
#include <sourcemod>
#include <cstrike>
#include <zombiereloaded>
new bool:G_bIsHuman[MAXPLAYERS+1];
new bool:G_bIsZombie[MAXPLAYERS+1];
new Handle:G_hCvar_Difficulty_Humans;
new Handle:G_hCvar_Difficulty_Zombies;
new Handle:G_hCvar_Difficulty_Humans_BlockTime;
bool g_bHumanPointsEnabled = false;
Handle g_hTimer = INVALID_HANDLE;
2018-08-07 22:13:31 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin:myinfo =
{
name = "HLstatsX CE Difficulty",
author = "zaCade + Neon",
description = "Grant points to the winning team. (zombies/humans)",
version = "1.2",
2018-08-07 22:13:31 +02:00
url = ""
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnPluginStart()
{
G_hCvar_Difficulty_Humans = CreateConVar("hlx_difficulty_humans", "0", "", 0, true, 0.0, true, 3.0);
G_hCvar_Difficulty_Zombies = CreateConVar("hlx_difficulty_zombies", "0", "", 0, true, 0.0, true, 3.0);
G_hCvar_Difficulty_Humans_BlockTime = CreateConVar("hlx_difficulty_humans_blocktime", "60", "", 0, true, 0.0, true, 180.0);
2018-08-07 22:13:31 +02:00
HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
AutoExecConfig(true, "plugin.hlstatsx_difficulty");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public ZR_OnClientInfected(client, attacker, bool:motherinfect, bool:respawnoverride, bool:respawn)
{
G_bIsHuman[client] = false;
G_bIsZombie[client] = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public ZR_OnClientHumanPost(client, bool:respawn, bool:protect)
{
G_bIsHuman[client] = true;
G_bIsZombie[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
if (g_hTimer != INVALID_HANDLE)
2018-09-07 18:40:49 +02:00
{
KillTimer(g_hTimer);
g_hTimer = INVALID_HANDLE;
2018-09-07 18:40:49 +02:00
}
g_bHumanPointsEnabled = false;
g_hTimer = CreateTimer(GetConVarFloat(G_hCvar_Difficulty_Humans_BlockTime), EnableHumanPoints, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
2018-08-07 22:13:31 +02:00
for (new client = 1; client <= MaxClients; client++)
{
G_bIsHuman[client] = true;
G_bIsZombie[client] = false;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
switch(GetEventInt(event, "winner"))
{
case(CS_TEAM_CT): CreateTimer(0.2, OnHumansWin, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
case(CS_TEAM_T): CreateTimer(0.2, OnZombiesWin, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action EnableHumanPoints(Handle timer)
{
g_bHumanPointsEnabled = true;
g_hTimer = INVALID_HANDLE;
}
2018-08-07 22:13:31 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action:OnHumansWin(Handle:timer)
{
if (!g_bHumanPointsEnabled)
{
PrintToChatAll("[SM] Round ended too fast. Humans will not be rewarded for the Win.");
return;
}
2018-08-07 22:13:31 +02:00
for (new client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && IsPlayerAlive(client) && !IsClientObserver(client) && !IsFakeClient(client))
{
if (G_bIsHuman[client] && !G_bIsZombie[client])
{
new String:sAuthid[64];
if (!GetClientAuthString(client, sAuthid, sizeof(sAuthid)))
Format(sAuthid, sizeof(sAuthid), "UNKNOWN");
LogToGame("\"%N<%d><%s><%s>\" triggered \"human_win_%i\"", client, GetClientUserId(client), sAuthid, "CT", GetConVarInt(G_hCvar_Difficulty_Humans));
}
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action:OnZombiesWin(Handle:timer)
{
for (new client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client) && IsPlayerAlive(client) && !IsClientObserver(client) && !IsFakeClient(client))
{
if (G_bIsZombie[client] && !G_bIsHuman[client])
{
new String:sAuthid[64];
if (!GetClientAuthString(client, sAuthid, sizeof(sAuthid)))
Format(sAuthid, sizeof(sAuthid), "UNKNOWN");
LogToGame("\"%N<%d><%s><%s>\" triggered \"zombie_win_%i\"", client, GetClientUserId(client), sAuthid, "TERRORIST", GetConVarInt(G_hCvar_Difficulty_Zombies));
}
}
}
}