From df7f13159cc4fc48e6af1bffaa910e6f35f455b1 Mon Sep 17 00:00:00 2001 From: zaCade Date: Sun, 18 Nov 2018 19:09:43 +0100 Subject: [PATCH] HLStats: Add ZRiot 'module'. --- hlstatsx/scripting/hlstatsx_zr.sp | 132 ++++++++++++++++++++++++++++++ includes/zriot.inc | 58 +++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 hlstatsx/scripting/hlstatsx_zr.sp create mode 100644 includes/zriot.inc diff --git a/hlstatsx/scripting/hlstatsx_zr.sp b/hlstatsx/scripting/hlstatsx_zr.sp new file mode 100644 index 0000000..27284f4 --- /dev/null +++ b/hlstatsx/scripting/hlstatsx_zr.sp @@ -0,0 +1,132 @@ +#include +#include +#include + +#pragma semicolon 1 +#pragma newdecls required + +/* CONVARS */ +ConVar g_cvarStreakInterval = null; +ConVar g_cvarMinimumStreak = null; +ConVar g_cvarMaximumStreak = null; + +/* INTERGERS */ +int g_iKillCount[MAXPLAYERS+1] = 0; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Plugin myinfo = +{ + name = "HLstatsX CE - Zombie Riot", + author = "zaCade", + description = "Create additional actions for the default HLstatsX", + version = "1.0.0" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + g_cvarStreakInterval = CreateConVar("hlx_zr_killstreaks_interval", "10", "amount of kills required to progress to the next killstreak", 0, true, 1.0); + g_cvarMinimumStreak = CreateConVar("hlx_zr_killstreaks_minimal", "10", "amount of kills required for the lowest killstreak", 0, true, 0.0); + g_cvarMaximumStreak = CreateConVar("hlx_zr_killstreaks_maximal", "200", "amount of kills required for the highest killstreak", 0, true, 0.0); + + HookEvent("round_end", OnRoundEnding, EventHookMode_Pre); + HookEvent("player_spawn", OnClientSpawn, EventHookMode_Pre); + HookEvent("player_death", OnClientDeath, EventHookMode_Pre); + + AutoExecConfig(); + GetTeams(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnMapStart() +{ + GetTeams(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + for (int client = 1; client <= MaxClients; client++) + { + if (IsValidClient(client)) + { + EndKillStreak(client); + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + int client = GetClientOfUserId(hEvent.GetInt("userid")); + + ResetClient(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + int client = GetClientOfUserId(hEvent.GetInt("userid")); + int killer = GetClientOfUserId(hEvent.GetInt("attacker")); + + EndKillStreak(client); + + if (IsValidClient(killer)) + { + g_iKillCount[killer] += 1; + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientDisconnect(int client) +{ + ResetClient(client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void EndKillStreak(int client) +{ + if (g_iKillCount[client] >= g_cvarMinimumStreak.IntValue) + { + if (g_iKillCount[client] > g_cvarMaximumStreak.IntValue) + g_iKillCount[client] = g_cvarMaximumStreak.IntValue; + + char sEvent[32]; + Format(sEvent, sizeof(sEvent), "zr_kill_streak_%d", RoundToFloor(float(g_iKillCount[client]) / float(g_cvarStreakInterval.IntValue)) * g_cvarStreakInterval.IntValue); + + LogPlayerEvent(client, "triggered", sEvent); + ResetClient(client); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock void ResetClient(int client) +{ + g_iKillCount[client] = 0; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock bool IsValidClient(int client) +{ + return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client)); +} diff --git a/includes/zriot.inc b/includes/zriot.inc new file mode 100644 index 0000000..73928f2 --- /dev/null +++ b/includes/zriot.inc @@ -0,0 +1,58 @@ +/** + * ==================== + * Zombie Riot + * File: zriot.inc + * Author: Greyscale + * ==================== + */ + +/** + * Used to check if a player is a zombie. + * @param client Client index. + * @return True if the player is a zombie, and false if human. + */ +native bool:ZRiot_IsClientZombie(client); + +/** + * Retrieves the team index of the zombies + * @note Remember these are based off cvars, 0 will be returned if called before the cvar is set + */ +native ZRiot_GetZombieTeam(); + +/** + * Retrieves the team index of the humans + * @note Remember these are based off cvars, 0 will be returned if called before the cvar is set + */ +native ZRiot_GetHumanTeam(); + +/** + * Turns a human into a zombie + * @param client Client index. + */ +native ZRiot_Zombie(client); + +/** + * Called when a player turns into a zombie. This is not called at round end. + * @param client Client index. + */ +forward ZRiot_OnClientZombie(client); + +/** + * Turns a zombie into a human (will not work for bots) + * @param client Client index. + */ +native ZRiot_Human(client); + +/** + * Called when a player turns into a human. This is not called at round end. + * @param client Client index. + */ +forward ZRiot_OnClientHuman(client); + +/** + * Called when the HUD is being updated on a client (not called for bots) + * @param client Client index. + * @param hinttext The text string being sent to the usermsg "HintText" + * @note If hinttext is modified the new value will be sent to the client + */ +forward ZRiot_OnClientHUDUpdate(client, String:hinttext[]); \ No newline at end of file