This commit is contained in:
xen
2020-03-25 20:09:12 +02:00
committed by xen
commit 527e7ec05e
420 changed files with 68682 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+175
View File
@@ -0,0 +1,175 @@
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#tryinclude <HappyHour>
#define REQUIRE_PLUGIN
#pragma newdecls required
bool g_bHHLoaded;
char g_sTeamList[16][64];
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "HLstatsX CE - LogHelper",
author = "Neon",
description = "Custom HLstatsX Logging",
version = "1.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int errorSize)
{
CreateNative("LH_LogPlayerEvent", Native_LogPlayerEvent);
RegPluginLibrary("HlstatsXLogHelper");
return APLRes_Success;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnAllPluginsLoaded()
{
g_bHHLoaded = LibraryExists("HappyHour");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnLibraryAdded(const char[] sName)
{
if (strcmp(sName, "HappyHour", false) == 0)
g_bHHLoaded = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnLibraryRemoved(const char[] sName)
{
if (strcmp(sName, "HappyHour", false) == 0)
g_bHHLoaded = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
GetTeams();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_LogPlayerEvent(Handle hPlugin, int numParams)
{
int iClient;
char sVerb[64];
char sEvent[256];
bool bHH;
iClient = GetNativeCell(1);
GetNativeString(2, sVerb, sizeof(sVerb));
GetNativeString(3, sEvent, sizeof(sEvent));
bHH = GetNativeCell(4);
if (iClient < 1 || iClient > MaxClients)
{
return ThrowNativeError(SP_ERROR_NATIVE, "Client index %d is invalid", iClient);
}
else if (!IsClientInGame(iClient))
{
return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not ingame", iClient);
}
LogPlayerEventCustom(iClient, sVerb, sEvent, bHH);
return true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void LogPlayerEventCustom(int client, const char[] verb, const char[] event, bool hh)
{
if (!IsValidPlayer(client))
return;
char player_authid[32];
if (!GetClientAuthId(client, AuthId_Engine, player_authid, sizeof(player_authid), false))
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
char sEvent[256];
Format(sEvent, sizeof(sEvent), "%s", event);
if (g_bHHLoaded && HH_IsItHappyHour() && hh)
Format(sEvent, sizeof(sEvent), "%s_hh", sEvent);
char sLog[512];
Format(sLog, sizeof(sLog), "\"%N<%d><%s><%s>\" %s \"%s\"", client, GetClientUserId(client), player_authid, g_sTeamList[GetClientTeam(client)], verb, sEvent);
LogToGame(sLog);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void GetTeams(bool insmod = false)
{
if (!insmod)
{
int max_teams_count = GetTeamCount();
for (int team_index = 0; (team_index < max_teams_count); team_index++)
{
char team_name[64];
GetTeamName(team_index, team_name, sizeof(team_name));
if (strcmp(team_name, "") != 0)
{
g_sTeamList[team_index] = team_name;
}
}
}
else
{
// they really need to get their act together... GetTeamName() would be awesome since they can't even keep their team indexes consistent
char mapname[64];
GetCurrentMap(mapname, sizeof(mapname));
if (strcmp(mapname, "ins_karam") == 0 || strcmp(mapname, "ins_baghdad") == 0)
{
g_sTeamList[1] = "Iraqi Insurgents";
g_sTeamList[2] = "U.S. Marines";
}
else
{
g_sTeamList[1] = "U.S. Marines";
g_sTeamList[2] = "Iraqi Insurgents";
}
g_sTeamList[0] = "Unassigned";
g_sTeamList[3] = "SPECTATOR";
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
static stock bool IsValidPlayer(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client))
{
return true;
}
return false;
}
+269
View File
@@ -0,0 +1,269 @@
#include <cstrike>
#include <hlstatsx_loghelper>
#include <sourcemod>
#include <zombiereloaded>
#pragma semicolon 1
#pragma newdecls required
/* CONVARS */
ConVar g_cvarStreakInterval = null;
ConVar g_cvarMinimumStreak = null;
ConVar g_cvarMaximumStreak = null;
ConVar g_cvarDifficultyHuman = null;
ConVar g_cvarDifficultyZombie = null;
ConVar g_cvarDifficultyDuration = null;
/* HANDLES */
Handle g_tMinimalRoundDuration = INVALID_HANDLE;
/* INTERGERS */
int g_iKillCount[MAXPLAYERS+1] = 0;
/* BOOLEANS */
bool g_bIsHuman[MAXPLAYERS+1] = false;
bool g_bIsZombie[MAXPLAYERS+1] = false;
bool g_bMotherZM[MAXPLAYERS+1] = false;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "HLstatsX CE - Zombie Escape",
author = "zaCade",
description = "Create additional actions for the default HLstatsX",
version = "1.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_cvarStreakInterval = CreateConVar("hlx_ze_killstreaks_interval", "1", "amount of kills required to progress to the next killstreak", 0, true, 1.0);
g_cvarMinimumStreak = CreateConVar("hlx_ze_killstreaks_minimal", "2", "amount of kills required for the lowest killstreak", 0, true, 0.0);
g_cvarMaximumStreak = CreateConVar("hlx_ze_killstreaks_maximal", "12", "amount of kills required for the highest killstreak", 0, true, 0.0);
g_cvarDifficultyHuman = CreateConVar("hlx_ze_difficulty_human", "0", "the difficulty level of the current map for humans", 0, true, 0.0);
g_cvarDifficultyZombie = CreateConVar("hlx_ze_difficulty_zombie", "0", "the difficulty level of the current map for zombies", 0, true, 0.0);
g_cvarDifficultyDuration = CreateConVar("hlx_ze_difficulty_duration", "60", "the minumum amount of time a round has to last in seconds", 0, true, 0.0, true, 180.0);
HookEvent("round_start", OnRoundStarting, EventHookMode_Pre);
HookEvent("round_end", OnRoundEnding, EventHookMode_Pre);
HookEvent("player_spawn", OnClientSpawn, EventHookMode_Pre);
HookEvent("player_death", OnClientDeath, EventHookMode_Pre);
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client))
{
g_bIsHuman[client] = ZR_IsClientHuman(client);
g_bIsZombie[client] = ZR_IsClientZombie(client);
}
}
AutoExecConfig();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapEnd()
{
if (g_tMinimalRoundDuration != INVALID_HANDLE && CloseHandle(g_tMinimalRoundDuration))
g_tMinimalRoundDuration = INVALID_HANDLE;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnRoundStarting(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
if (g_tMinimalRoundDuration != INVALID_HANDLE && CloseHandle(g_tMinimalRoundDuration))
g_tMinimalRoundDuration = INVALID_HANDLE;
g_tMinimalRoundDuration = CreateTimer(g_cvarDifficultyDuration.FloatValue, OnRoundMinimalDuration);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnRoundMinimalDuration(Handle timer)
{
g_tMinimalRoundDuration = INVALID_HANDLE;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientHumanPost(int client, bool respawn, bool protect)
{
g_bIsHuman[client] = true;
g_bIsZombie[client] = false;
g_bMotherZM[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
g_bIsHuman[client] = false;
g_bIsZombie[client] = true;
g_bMotherZM[client] = motherInfect;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast)
{
bool bAwardHumans = ((g_tMinimalRoundDuration == INVALID_HANDLE) && (hEvent.GetInt("winner") == CS_TEAM_CT));
bool bAwardZombies = ((g_tMinimalRoundDuration == INVALID_HANDLE) && (hEvent.GetInt("winner") == CS_TEAM_T));
int iAliveHumans;
int iAliveZombies;
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client) && GetClientTeam(client) == CS_TEAM_CT)
{
iAliveHumans++;
}
else if(IsValidClient(client) && GetClientTeam(client) == CS_TEAM_T)
{
iAliveZombies++;
}
}
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client))
{
if (bAwardHumans && g_bIsHuman[client])
{
if (iAliveHumans == 1)
{
LH_LogPlayerEvent(client, "triggered", "ze_h_win_solo", true);
}
else
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_h_win_%d", g_cvarDifficultyHuman.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
}
else if (bAwardZombies && g_bIsZombie[client])
{
if (iAliveZombies == 1)
{
LH_LogPlayerEvent(client, "triggered", "ze_z_win_solo", true);
}
else if (g_bMotherZM[client])
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_m_win_%d", g_cvarDifficultyZombie.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
else
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_z_win_%d", g_cvarDifficultyZombie.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
}
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 EndKillStreak(int client)
{
if (g_iKillCount[client] >= g_cvarMinimumStreak.IntValue)
{
if (g_iKillCount[client] > g_cvarMaximumStreak.IntValue)
g_iKillCount[client] = g_cvarMaximumStreak.IntValue;
if (g_bIsHuman[client])
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_h_kill_streak_%d", RoundToFloor(float(g_iKillCount[client]) / float(g_cvarStreakInterval.IntValue)) * g_cvarStreakInterval.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
else if (g_bIsZombie[client])
{
if (g_bMotherZM[client])
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_m_kill_streak_%d", RoundToFloor(float(g_iKillCount[client]) / float(g_cvarStreakInterval.IntValue)) * g_cvarStreakInterval.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
else
{
char sPlayerEvent[32];
Format(sPlayerEvent, sizeof(sPlayerEvent), "ze_z_kill_streak_%d", RoundToFloor(float(g_iKillCount[client]) / float(g_cvarStreakInterval.IntValue)) * g_cvarStreakInterval.IntValue);
LH_LogPlayerEvent(client, "triggered", sPlayerEvent, true);
}
}
}
ResetClient(client);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void ResetClient(int client)
{
g_bIsHuman[client] = true;
g_bIsZombie[client] = false;
g_bMotherZM[client] = false;
g_iKillCount[client] = 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client));
}
@@ -0,0 +1,38 @@
#if defined _HlstatsXLogHelper_included
#endinput
#endif
#define _HlstatsXLogHelper_included
/**
* Logs a custom player event to the game.
*
* @param client The client index.
* @param verb The verb to log.
* @param event The event to log.
* @param happyhour If event should be altered during happy hour.
*
* @return True on success, false otherwise.
* @error Invalid client index or not ingame.
*/
native bool LH_LogPlayerEvent(int client, char[] verb, char[] event, bool happyhour = false);
public SharedPlugin __pl_HlstatsXLogHelper =
{
name = "HlstatsXLogHelper",
file = "hlstatsx_loghelper.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
required = 0
#endif
};
#if !defined REQUIRE_PLUGIN
public void __pl_HlstatsXLogHelper_SetNTVOptional()
{
MarkNativeAsOptional("LH_LogPlayerEvent");
}
#endif
+201
View File
@@ -0,0 +1,201 @@
#define LOGHELPER_VERSION 3
#include <sourcemod>
#include <sdktools>
new String:g_team_list[16][64];
// Call this on map start to cache team names in g_team_list
stock GetTeams(bool:insmod = false)
{
if (!insmod)
{
new max_teams_count = GetTeamCount();
for (new team_index = 0; (team_index < max_teams_count); team_index++)
{
decl String: team_name[64];
GetTeamName(team_index, team_name, sizeof(team_name));
if (strcmp(team_name, "") != 0)
{
g_team_list[team_index] = team_name;
}
}
}
else
{
// they really need to get their act together... GetTeamName() would be awesome since they can't even keep their team indexes consistent
decl String:mapname[64];
GetCurrentMap(mapname, sizeof(mapname));
if (strcmp(mapname, "ins_karam") == 0 || strcmp(mapname, "ins_baghdad") == 0)
{
g_team_list[1] = "Iraqi Insurgents";
g_team_list[2] = "U.S. Marines";
}
else
{
g_team_list[1] = "U.S. Marines";
g_team_list[2] = "Iraqi Insurgents";
}
g_team_list[0] = "Unassigned";
g_team_list[3] = "SPECTATOR";
}
}
stock LogPlayerEvent(client, const String:verb[], const String:event[], bool:display_location = false, const String:properties[] = "", iTeam=-1)
{
if (IsValidPlayer(client))
{
decl String:player_authid[32];
if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
}
if(iTeam == -1)
iTeam = GetClientTeam(client);
if (display_location)
{
decl Float:player_origin[3];
GetClientAbsOrigin(client, player_origin);
LogToGame("\"%N<%d><%s><%s>\" %s \"%s\"%s (position \"%d %d %d\")", client, GetClientUserId(client), player_authid, g_team_list[iTeam], verb, event, properties, RoundFloat(player_origin[0]), RoundFloat(player_origin[1]), RoundFloat(player_origin[2]));
}
else
{
LogToGame("\"%N<%d><%s><%s>\" %s \"%s\"%s", client, GetClientUserId(client), player_authid, g_team_list[iTeam], verb, event, properties);
}
}
}
stock LogPlyrPlyrEvent(client, victim, const String:verb[], const String:event[], bool:display_location = false, const String:properties[] = "")
{
if (IsValidPlayer(client) && IsValidPlayer(victim))
{
decl String:player_authid[32];
if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
}
decl String:victim_authid[32];
if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
}
if (display_location)
{
decl Float:player_origin[3];
GetClientAbsOrigin(client, player_origin);
decl Float:victim_origin[3];
GetClientAbsOrigin(victim, victim_origin);
LogToGame("\"%N<%d><%s><%s>\" %s \"%s\" against \"%N<%d><%s><%s>\"%s (position \"%d %d %d\") (victim_position \"%d %d %d\")", client, GetClientUserId(client), player_authid, g_team_list[GetClientTeam(client)], verb, event, victim, GetClientUserId(victim), victim_authid, g_team_list[GetClientTeam(victim)], properties, RoundFloat(player_origin[0]), RoundFloat(player_origin[1]), RoundFloat(player_origin[2]), RoundFloat(victim_origin[0]), RoundFloat(victim_origin[1]), RoundFloat(victim_origin[2]));
}
else
{
LogToGame("\"%N<%d><%s><%s>\" %s \"%s\" against \"%N<%d><%s><%s>\"%s", client, GetClientUserId(client), player_authid, g_team_list[GetClientTeam(client)], verb, event, victim, GetClientUserId(victim), victim_authid, g_team_list[GetClientTeam(victim)], properties);
}
}
}
stock LogKill(attacker, victim, const String:weapon[], bool:display_location = false, const String:properties[] = "")
{
if (IsValidPlayer(attacker) && IsValidPlayer(victim))
{
decl String:attacker_authid[32];
if (!GetClientAuthId(attacker, AuthId_Steam2, attacker_authid, sizeof(attacker_authid)))
{
strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN");
}
decl String:victim_authid[32];
if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
}
if (display_location)
{
decl Float:attacker_origin[3];
GetClientAbsOrigin(attacker, attacker_origin);
decl Float:victim_origin[3];
GetClientAbsOrigin(victim, victim_origin);
LogToGame("\"%N<%d><%s><%s>\" killed \"%N<%d><%s><%s>\" with \"%s\"%s (attacker_position \"%d %d %d\") (victim_position \"%d %d %d\")", attacker, GetClientUserId(attacker), attacker_authid, g_team_list[GetClientTeam(attacker)], victim, GetClientUserId(victim), victim_authid, g_team_list[GetClientTeam(victim)], weapon, properties, RoundFloat(attacker_origin[0]), RoundFloat(attacker_origin[1]), RoundFloat(attacker_origin[2]), RoundFloat(victim_origin[0]), RoundFloat(victim_origin[1]), RoundFloat(victim_origin[2]));
}
else
{
LogToGame("\"%N<%d><%s><%s>\" killed \"%N<%d><%s><%s>\" with \"%s\"%s", attacker, GetClientUserId(attacker), attacker_authid, g_team_list[GetClientTeam(attacker)], victim, GetClientUserId(victim), victim_authid, g_team_list[GetClientTeam(victim)], weapon, properties);
}
}
}
// For Psychostats "KTRAJ" kill trajectory log lines
stock LogPSKillTraj(attacker, victim, const String:weapon[])
{
if (IsValidPlayer(attacker) && IsValidPlayer(victim))
{
decl String:attacker_authid[32];
if (!GetClientAuthId(attacker, AuthId_Steam2, attacker_authid, sizeof(attacker_authid)))
{
strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN");
}
decl String:victim_authid[32];
if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
}
decl Float:attacker_origin[3];
GetClientAbsOrigin(attacker, attacker_origin);
decl Float:victim_origin[3];
GetClientAbsOrigin(victim, victim_origin);
LogToGame("[KTRAJ] \"%N<%d><%s><%s>\" killed \"%N<%d><%s><%s>\" with \"%s\" (attacker_position \"%d %d %d\") (victim_position \"%d %d %d\")", attacker, GetClientUserId(attacker), attacker_authid, g_team_list[GetClientTeam(attacker)], victim, GetClientUserId(victim), victim_authid, g_team_list[GetClientTeam(victim)], weapon, RoundFloat(attacker_origin[0]), RoundFloat(attacker_origin[1]), RoundFloat(attacker_origin[2]), RoundFloat(victim_origin[0]), RoundFloat(victim_origin[1]), RoundFloat(victim_origin[2]));
}
}
// Verb should always be "triggered" for this.
stock LogTeamEvent(team, const String:verb[], const String:event[], const String:properties[] = "")
{
if (team > -1)
{
LogToGame("Team \"%s\" %s \"%s\"%s", g_team_list[team], verb, event, properties);
}
}
stock LogKillLoc(attacker, victim)
{
if (attacker > 0 && victim > 0)
{
decl Float:attacker_origin[3];
GetClientAbsOrigin(attacker, attacker_origin);
decl Float:victim_origin[3];
GetClientAbsOrigin(victim, victim_origin);
LogToGame("World triggered \"killlocation\" (attacker_position \"%d %d %d\") (victim_position \"%d %d %d\")", RoundFloat(attacker_origin[0]), RoundFloat(attacker_origin[1]), RoundFloat(attacker_origin[2]), RoundFloat(victim_origin[0]), RoundFloat(victim_origin[1]), RoundFloat(victim_origin[2]));
}
}
stock LogRoleChange(client, const String:role[], const String:properties[] = "")
{
LogPlayerEvent( client, "changed role to", role, false, properties );
}
stock LogMapLoad()
{
decl String:map[64];
GetCurrentMap(map, sizeof(map));
LogToGame("Loading map \"%s\"", map);
}
stock IsValidPlayer(client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client))
{
return true;
}
return false;
}
+138
View File
@@ -0,0 +1,138 @@
#define HITGROUP_GENERIC 0
#define HITGROUP_HEAD 1
#define HITGROUP_CHEST 2
#define HITGROUP_STOMACH 3
#define HITGROUP_LEFTARM 4
#define HITGROUP_RIGHTARM 5
#define HITGROUP_LEFTLEG 6
#define HITGROUP_RIGHTLEG 7
#define LOG_HIT_OFFSET 7
#define LOG_HIT_SHOTS 0
#define LOG_HIT_HITS 1
#define LOG_HIT_KILLS 2
#define LOG_HIT_HEADSHOTS 3
#define LOG_HIT_TEAMKILLS 4
#define LOG_HIT_DAMAGE 5
#define LOG_HIT_DEATHS 6
#define LOG_HIT_GENERIC 7
#define LOG_HIT_HEAD 8
#define LOG_HIT_CHEST 9
#define LOG_HIT_STOMACH 10
#define LOG_HIT_LEFTARM 11
#define LOG_HIT_RIGHTARM 12
#define LOG_HIT_LEFTLEG 13
#define LOG_HIT_RIGHTLEG 14
new Handle:g_weapon_trie = INVALID_HANDLE;
CreatePopulateWeaponTrie()
{
// Create a Trie
g_weapon_trie = CreateTrie();
// Initial populate
for (new i = 0; i < MAX_LOG_WEAPONS; i++)
{
if (g_weapon_list[i][0] == 0)
{
// some games have a couple blanks as place holders (so array indexes match with weapon ids)
decl String:randomKey[6];
Format(randomKey, sizeof(randomKey), "%c%c%c%c%c%c", GetURandomInt(), GetURandomInt(), GetURandomInt(), GetURandomInt(), GetURandomInt(), GetURandomInt());
SetTrieValue(g_weapon_trie, randomKey, i);
continue;
}
SetTrieValue(g_weapon_trie, g_weapon_list[i], i);
}
}
dump_player_stats(client)
{
if (IsClientInGame(client) && IsClientConnected(client))
{
decl String: player_authid[64];
if (!GetClientAuthString(client, player_authid, sizeof(player_authid)))
{
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
}
new player_team_index = GetClientTeam(client);
new player_userid = GetClientUserId(client);
new is_logged;
for (new i = 0; (i < MAX_LOG_WEAPONS); i++)
{
#if defined INS
if (g_weapon_stats[client][i][LOG_HIT_HITS] > 0)
{
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats\" (weapon \"weapon_%s\") (shots \"%d\") (hits \"%d\") (kills \"%d\") (headshots \"%d\") (tks \"%d\") (damage \"%d\") (deaths \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_list[i], g_weapon_stats[client][i][LOG_HIT_SHOTS], g_weapon_stats[client][i][LOG_HIT_HITS], g_weapon_stats[client][i][LOG_HIT_KILLS], g_weapon_stats[client][i][LOG_HIT_HEADSHOTS], g_weapon_stats[client][i][LOG_HIT_TEAMKILLS], g_weapon_stats[client][i][LOG_HIT_DAMAGE], g_weapon_stats[client][i][LOG_HIT_DEATHS]);
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats2\" (weapon \"weapon_%s\") (head \"%d\") (chest \"%d\") (stomach \"%d\") (leftarm \"%d\") (rightarm \"%d\") (leftleg \"%d\") (rightleg \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_list[i], g_weapon_stats[client][i][LOG_HIT_HEAD], g_weapon_stats[client][i][LOG_HIT_CHEST], g_weapon_stats[client][i][LOG_HIT_STOMACH], g_weapon_stats[client][i][LOG_HIT_LEFTARM], g_weapon_stats[client][i][LOG_HIT_RIGHTARM], g_weapon_stats[client][i][LOG_HIT_LEFTLEG], g_weapon_stats[client][i][LOG_HIT_RIGHTLEG]);
#else
if (g_weapon_stats[client][i][LOG_HIT_SHOTS] > 0)
{
#if defined GES
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats\" (weapon \"weapon_%s\") (shots \"%d\") (hits \"%d\") (kills \"%d\") (headshots \"%d\") (tks \"%d\") (damage \"%d\") (deaths \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_loglist[i], g_weapon_stats[client][i][LOG_HIT_SHOTS], g_weapon_stats[client][i][LOG_HIT_HITS], g_weapon_stats[client][i][LOG_HIT_KILLS], g_weapon_stats[client][i][LOG_HIT_HEADSHOTS], g_weapon_stats[client][i][LOG_HIT_TEAMKILLS], g_weapon_stats[client][i][LOG_HIT_DAMAGE], g_weapon_stats[client][i][LOG_HIT_DEATHS]);
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats2\" (weapon \"weapon_%s\") (head \"%d\") (chest \"%d\") (stomach \"%d\") (leftarm \"%d\") (rightarm \"%d\") (leftleg \"%d\") (rightleg \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_loglist[i], g_weapon_stats[client][i][LOG_HIT_HEAD], g_weapon_stats[client][i][LOG_HIT_CHEST], g_weapon_stats[client][i][LOG_HIT_STOMACH], g_weapon_stats[client][i][LOG_HIT_LEFTARM], g_weapon_stats[client][i][LOG_HIT_RIGHTARM], g_weapon_stats[client][i][LOG_HIT_LEFTLEG], g_weapon_stats[client][i][LOG_HIT_RIGHTLEG]);
#else
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats\" (weapon \"%s\") (shots \"%d\") (hits \"%d\") (kills \"%d\") (headshots \"%d\") (tks \"%d\") (damage \"%d\") (deaths \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_list[i], g_weapon_stats[client][i][LOG_HIT_SHOTS], g_weapon_stats[client][i][LOG_HIT_HITS], g_weapon_stats[client][i][LOG_HIT_KILLS], g_weapon_stats[client][i][LOG_HIT_HEADSHOTS], g_weapon_stats[client][i][LOG_HIT_TEAMKILLS], g_weapon_stats[client][i][LOG_HIT_DAMAGE], g_weapon_stats[client][i][LOG_HIT_DEATHS]);
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats2\" (weapon \"%s\") (head \"%d\") (chest \"%d\") (stomach \"%d\") (leftarm \"%d\") (rightarm \"%d\") (leftleg \"%d\") (rightleg \"%d\")", client, player_userid, player_authid, g_team_list[player_team_index], g_weapon_list[i], g_weapon_stats[client][i][LOG_HIT_HEAD], g_weapon_stats[client][i][LOG_HIT_CHEST], g_weapon_stats[client][i][LOG_HIT_STOMACH], g_weapon_stats[client][i][LOG_HIT_LEFTARM], g_weapon_stats[client][i][LOG_HIT_RIGHTARM], g_weapon_stats[client][i][LOG_HIT_LEFTLEG], g_weapon_stats[client][i][LOG_HIT_RIGHTLEG]);
#endif
#endif
is_logged++;
}
}
if (is_logged > 0)
{
reset_player_stats(client);
}
}
}
reset_player_stats(client)
{
for (new i = 0; (i < MAX_LOG_WEAPONS); i++)
{
g_weapon_stats[client][i][LOG_HIT_SHOTS] = 0;
g_weapon_stats[client][i][LOG_HIT_HITS] = 0;
g_weapon_stats[client][i][LOG_HIT_KILLS] = 0;
g_weapon_stats[client][i][LOG_HIT_HEADSHOTS] = 0;
g_weapon_stats[client][i][LOG_HIT_TEAMKILLS] = 0;
g_weapon_stats[client][i][LOG_HIT_DAMAGE] = 0;
g_weapon_stats[client][i][LOG_HIT_DEATHS] = 0;
g_weapon_stats[client][i][LOG_HIT_GENERIC] = 0;
g_weapon_stats[client][i][LOG_HIT_HEAD] = 0;
g_weapon_stats[client][i][LOG_HIT_CHEST] = 0;
g_weapon_stats[client][i][LOG_HIT_STOMACH] = 0;
g_weapon_stats[client][i][LOG_HIT_LEFTARM] = 0;
g_weapon_stats[client][i][LOG_HIT_RIGHTARM] = 0;
g_weapon_stats[client][i][LOG_HIT_LEFTLEG] = 0;
g_weapon_stats[client][i][LOG_HIT_RIGHTLEG] = 0;
}
}
stock get_weapon_index(const String:weapon_name[])
{
new index = -1;
GetTrieValue(g_weapon_trie, weapon_name, index);
return index;
}
WstatsDumpAll()
{
for (new i = 1; i <= MaxClients; i++)
{
dump_player_stats(i);
}
}
OnPlayerDisconnect(client)
{
if(client > 0 && IsClientInGame(client))
{
dump_player_stats(client);
reset_player_stats(client);
}
}