| alasfourom |
08-11-2022 07:36 |
Re: How to print all players/highest player kills at the end of the round?
Its working fine, but I'm not sure is this the right method, and if there is for example 0 kills, how to make it display "None"
PHP Code:
#include <sourcemod> #include <sdktools>
#pragma semicolon 1 #pragma newdecls required
#define PLUGIN_VERSION "1.0"
bool g_bRoundEnd;
int SI_KillCount [MAXPLAYERS+1]; int Boss_KillCount [MAXPLAYERS+1];
public void OnPluginStart() { HookEvent("round_start", Event_RoundStart); HookEvent("round_end", Event_RoundEnd); HookEvent("player_death", EVENT_OnSpecialDeath); HookEvent("tank_killed", EVENT_OnTankDeath); HookEvent("witch_killed", EVENT_OnWitchDeath); }
/* =============================================================================================================== * * Round Start * *================================================================================================================ */
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) { g_bRoundEnd = false; for (int i = 1; i <= MaxClients; i++) { if (IsClientInGame(i)) { SI_KillCount [i] = 0; Boss_KillCount [i] = 0; } } }
/* =============================================================================================================== * * MVP: SI Kills * *================================================================================================================ */
public void EVENT_OnSpecialDeath(Event event, const char[] name, bool dontBroadcast) { int victim = GetClientOfUserId(event.GetInt("userid")); if (!victim || !IsClientInGame(victim) || IsTank(victim)) return; int attacker = GetClientOfUserId(event.GetInt("attacker")); if (!attacker || !IsClientInGame(attacker)) return; if(attacker != victim && GetClientTeam(attacker) == 2) { SI_KillCount[attacker]++; if (SI_KillCount[attacker] > 0) PrintHintText(attacker, "Special Kills: %d", SI_KillCount[attacker]); } }
/* =============================================================================================================== * * MVP: Boss Kills * *================================================================================================================ */
public void EVENT_OnWitchDeath(Event event, const char[] name, bool dontBroadcast) { int attacker = GetClientOfUserId(event.GetInt("userid")); if (!attacker || !IsClientInGame(attacker)) return; if(GetClientTeam(attacker) == 2) { Boss_KillCount[attacker]++; if (Boss_KillCount[attacker] > 0) PrintHintText(attacker, "Boss Kills: %d", Boss_KillCount[attacker]); } }
public void EVENT_OnTankDeath(Event event, const char[] name, bool dontBroadcast) { int tank = GetClientOfUserId(event.GetInt("userid")); if (!tank || !IsClientInGame(tank)) return; int attacker = GetClientOfUserId(event.GetInt("attacker")); if (!attacker || !IsClientInGame(attacker)) return; if(attacker != tank && GetClientTeam(attacker) == 2) { Boss_KillCount[attacker]++; if (Boss_KillCount[attacker] > 0) PrintHintText(attacker, "Boss Kills: %d", Boss_KillCount[attacker]); } }
/* =============================================================================================================== * * Round End * *================================================================================================================ */
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) { if(!g_bRoundEnd) { MVP_Display(); //Display Players With MVP g_bRoundEnd = true; } return Plugin_Handled; }
/* =============================================================================================================== * * MVP Display * *================================================================================================================ */
void MVP_Display() { int client; int players = 0; int[] players_clients = new int[MaxClients+1]; int SI_KillCount_MVP, Boss_KillCount_MVP; for (client = 1; client <= MaxClients; client++) { if (!IsClientInGame(client) || GetClientTeam(client) == 3) continue; players_clients[players] = client; players++; } SortCustom1D(players_clients, players, SortDescending); { client = players_clients [0]; SI_KillCount_MVP = SI_KillCount [client]; PrintToChatAll("MVP SI Kills: %N (%d)", client, SI_KillCount_MVP); } SortCustom1D(players_clients, players, SortDescending); { client = players_clients [0]; Boss_KillCount_MVP = Boss_KillCount [client]; PrintToChatAll("MVP Boss Kills: %N (%d)", client, Boss_KillCount_MVP); } }
public int SortDescending(int elem1, int elem2, const int[] array, Handle hndl) { if (SI_KillCount[elem1] > SI_KillCount[elem2]) return -1; else if (Boss_KillCount[elem1] > Boss_KillCount[elem2]) return -1; else if (SI_KillCount[elem2] > SI_KillCount[elem1]) return 1; else if (Boss_KillCount[elem2] > Boss_KillCount[elem1]) return 1; else if (elem1 > elem2) return -1; else if (elem2 > elem1) return 1; return 0; }
/* =============================================================================================================== * * Check Tank * *================================================================================================================ */
stock bool IsTank(int client) { return (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3 && GetEntProp(client, Prop_Send, "m_zombieClass") == 8); }
|