HLStats: Add ZRiot 'module'.
This commit is contained in:
parent
e1ad359361
commit
df7f13159c
132
hlstatsx/scripting/hlstatsx_zr.sp
Normal file
132
hlstatsx/scripting/hlstatsx_zr.sp
Normal file
@ -0,0 +1,132 @@
|
||||
#include <loghelper>
|
||||
#include <sourcemod>
|
||||
#include <zriot>
|
||||
|
||||
#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));
|
||||
}
|
58
includes/zriot.inc
Normal file
58
includes/zriot.inc
Normal file
@ -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[]);
|
Loading…
Reference in New Issue
Block a user