From 90d448ef8c8b67707e4d66a1a2527514299a9a53 Mon Sep 17 00:00:00 2001
From: zaCade <zaCade@hotmail.com>
Date: Mon, 15 Oct 2018 21:50:38 +0200
Subject: [PATCH] BossHP-Ranking: Ohai

Hopefully this one doesnt lag. :<
---
 BossHP/scripting/BossHP_Ranking.sp         | 211 +++++++++++++++++
 BossHP_Ranking/scripting/BossHP_Ranking.sp | 258 ---------------------
 2 files changed, 211 insertions(+), 258 deletions(-)
 create mode 100644 BossHP/scripting/BossHP_Ranking.sp
 delete mode 100644 BossHP_Ranking/scripting/BossHP_Ranking.sp

diff --git a/BossHP/scripting/BossHP_Ranking.sp b/BossHP/scripting/BossHP_Ranking.sp
new file mode 100644
index 00000000..5a090757
--- /dev/null
+++ b/BossHP/scripting/BossHP_Ranking.sp
@@ -0,0 +1,211 @@
+#include <sourcemod>
+#include <BossHP>
+
+#include <basic>
+#include "CConfig.inc"
+#include "CBoss.inc"
+
+ArrayList g_hStats[MAXPLAYERS+1];
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public Plugin myinfo =
+{
+	name         = "BossHP - Ranking",
+	author       = "Neon & zaCade",
+	description  = "",
+	version      = "1.0.0",
+};
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public void OnClientPutInServer(int client)
+{
+	g_hStats[client] = new ArrayList(64);
+}
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public void OnClientDisconnect(int client)
+{
+	delete g_hStats[client];
+}
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public void OnBossDamaged(any Boss, int client)
+{
+	if (!IsValidClient(client))
+		return;
+
+	for (int index = 0; index < g_hStats[client].Length; index++)
+	{
+		any BossDamage[2];
+		g_hStats[client].GetArray(index, BossDamage, sizeof(BossDamage));
+
+		if (BossDamage[0] == Boss)
+		{
+			BossDamage[1] += 1;
+
+			g_hStats[client].SetArray(index, BossDamage, sizeof(BossDamage));
+			return;
+		}
+	}
+
+	any BossDamage[2];
+	BossDamage[0] = Boss;
+	BossDamage[1] = 1;
+
+	g_hStats[client].PushArray(BossDamage, sizeof(BossDamage));
+}
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public void OnBossKilled(any Boss, int reason)
+{
+	if (reason != 2)
+	{
+		for (int client = 1; client <= MaxClients; client++)
+		{
+			if (!IsClientInGame(client))
+				continue;
+
+			for (int index = 0; index < g_hStats[client].Length; index++)
+			{
+				any BossDamage[2];
+				g_hStats[client].GetArray(index, BossDamage, sizeof(BossDamage));
+
+				if (BossDamage[0] == Boss)
+				{
+					g_hStats[client].Erase(index);
+					break;
+				}
+			}
+		}
+	}
+	else
+	{
+		int iSortedList[MAXPLAYERS+1][2];
+		int iSortedCount;
+
+		for (int client = 1; client <= MaxClients; client++)
+		{
+			if (!IsClientInGame(client))
+				continue;
+
+			for (int index = 0; index < g_hStats[client].Length; index++)
+			{
+				any BossDamage[2];
+				g_hStats[client].GetArray(index, BossDamage, sizeof(BossDamage));
+
+				if (BossDamage[0] == Boss)
+				{
+					iSortedList[iSortedCount][0] = client;
+					iSortedList[iSortedCount][1] = BossDamage[1];
+					iSortedCount++;
+
+					g_hStats[client].Erase(index);
+					break;
+				}
+			}
+		}
+
+		SortCustom2D(iSortedList, iSortedCount, SortBossHitsList);
+
+		if (iSortedCount)
+		{
+			char sBuffer[512];
+			Format(sBuffer, sizeof(sBuffer), "BOSS DAMAGE:");
+			Format(sBuffer, sizeof(sBuffer), "%s\n*************************", sBuffer);
+
+			if (iSortedList[0][0]) Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d hits", sBuffer, iSortedList[0][0], iSortedList[0][1]);
+			if (iSortedList[1][0]) Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d hits", sBuffer, iSortedList[1][0], iSortedList[1][1]);
+			if (iSortedList[2][0]) Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d hits", sBuffer, iSortedList[2][0], iSortedList[2][1]);
+
+			Format(sBuffer, sizeof(sBuffer), "%s\n*************************", sBuffer);
+
+			Handle hMessage = StartMessageAll("HudMsg");
+			if (hMessage)
+			{
+				if (GetUserMessageType() == UM_Protobuf)
+				{
+					PbSetInt(hMessage, "channel", 50);
+					PbSetInt(hMessage, "effect", 0);
+					PbSetColor(hMessage, "clr1", {255, 255, 255, 255});
+					PbSetColor(hMessage, "clr2", {255, 255, 255, 255});
+					PbSetVector2D(hMessage, "pos", Float:{0.02, 0.45});
+					PbSetFloat(hMessage, "fade_in_time", 0.1);
+					PbSetFloat(hMessage, "fade_out_time", 0.1);
+					PbSetFloat(hMessage, "hold_time", 7.0);
+					PbSetFloat(hMessage, "fx_time", 0.0);
+					PbSetString(hMessage, "text", sBuffer);
+					EndMessage();
+				}
+				else
+				{
+					BfWriteByte(hMessage, 50);
+					BfWriteFloat(hMessage, 0.02);
+					BfWriteFloat(hMessage, 0.25);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 0);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 255);
+					BfWriteByte(hMessage, 0);
+					BfWriteFloat(hMessage, 0.1);
+					BfWriteFloat(hMessage, 0.1);
+					BfWriteFloat(hMessage, 7.0);
+					BfWriteFloat(hMessage, 0.0);
+					BfWriteString(hMessage, sBuffer);
+					EndMessage();
+				}
+			}
+
+			if(GetEngineVersion() == Engine_CSGO)
+			{
+				int iSplits
+				char sSplits[16][512];
+
+				if((iSplits = ExplodeString(sBuffer, "\n", sSplits, sizeof(sSplits), sizeof(sSplits[]))) != 0)
+				{
+					for (int iSplit; iSplit < iSplits; iSplit++)
+					{
+						PrintToChatAll(sSplits[iSplit]);
+					}
+				}
+			}
+			else
+				PrintToChatAll(sBuffer);
+		}
+	}
+}
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+public int SortBossHitsList(int[] elem1, int[] elem2, const int[][] array, Handle hndl)
+{
+	if (elem1[1] > elem2[1]) return -1;
+	if (elem1[1] < elem2[1]) return 1;
+
+	return 0;
+}
+
+//----------------------------------------------------------------------------------------------------
+// Purpose:
+//----------------------------------------------------------------------------------------------------
+stock int IsValidClient(int client, bool nobots = true)
+{
+	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
+		return false;
+
+	return IsClientInGame(client);
+}
diff --git a/BossHP_Ranking/scripting/BossHP_Ranking.sp b/BossHP_Ranking/scripting/BossHP_Ranking.sp
deleted file mode 100644
index d60ca0ca..00000000
--- a/BossHP_Ranking/scripting/BossHP_Ranking.sp
+++ /dev/null
@@ -1,258 +0,0 @@
-#include <sourcemod>
-#include <BossHP>
-
-#include <basic>
-#include "CConfig.inc"
-#include "CBoss.inc"
-
-ArrayList g_hBossHits;
-
-public Plugin:myinfo =
-{
-    name 		= "...",
-	author      = "Neon",
-	description = "",
-	version     = "1.0",
-	url         = "https://steamcommunity.com/id/n3ontm"
-};
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-public OnPluginStart()
-{
-	g_hBossHits = new ArrayList(128);
-}
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-public void OnBossDamaged(any Boss, int activator)
-{
-	if (!IsValidClient(activator))
-		return;
-
-	CBoss _Boss = view_as<CBoss>(Boss);
-
-	int iIdentificationEntity;
-
-	if (_Boss.IsBreakable)
-	{
-		CBossBreakable __Boss = view_as<CBossBreakable>(_Boss);
-		iIdentificationEntity = __Boss.iBreakableEnt;
-		delete __Boss;
-	}
-	else if (_Boss.IsCounter)
-	{
-		CBossCounter __Boss = view_as<CBossCounter>(_Boss);
-		iIdentificationEntity = __Boss.iCounterEnt;
-		delete __Boss;
-	}
-	else if (_Boss.IsHPBar)
-	{
-		CBossHPBar __Boss = view_as<CBossHPBar>(_Boss);
-		iIdentificationEntity = __Boss.iBackupEnt;
-		delete __Boss;
-	}
-
-	int BossHit[2];
-	BossHit[0] = iIdentificationEntity;
-	BossHit[1] = activator;
-	g_hBossHits.PushArray(BossHit, sizeof(BossHit))
-
-	delete _Boss;
-}
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-public void OnBossKilled(any Boss, int reason)
-{
-	char sBossName[64];
-
-	CBoss _Boss = view_as<CBoss>(Boss);
-
-	CConfig Config = _Boss.dConfig;
-	Config.GetName(sBossName, sizeof(sBossName))
-	delete Config;
-
-	int iIdentificationEntity;
-
-	if (_Boss.IsBreakable)
-	{
-		CBossBreakable __Boss = view_as<CBossBreakable>(_Boss);
-		iIdentificationEntity = __Boss.iBreakableEnt;
-
-		delete __Boss;
-	}
-	else if (_Boss.IsCounter)
-	{
-		CBossCounter __Boss = view_as<CBossCounter>(_Boss);
-		iIdentificationEntity = __Boss.iCounterEnt;
-		delete __Boss;
-	}
-	else if (_Boss.IsHPBar)
-	{
-		CBossHPBar __Boss = view_as<CBossHPBar>(_Boss);
-		iIdentificationEntity = __Boss.iBackupEnt;
-		delete __Boss;
-	}
-
-	delete _Boss;
-
-	int iSortedList[MAXPLAYERS+1][2];
-	int iSortedCount;
-	int iBossHits[MAXPLAYERS+1];
-
-	for(int i = 0; i < g_hBossHits.Length; i++)
-	{
-		int BossHit[2];
-		g_hBossHits.GetArray(i, BossHit, sizeof(BossHit));
-
-		if(BossHit[0] == iIdentificationEntity)
-		{
-			iBossHits[BossHit[1]]++;
-		}
-	}
-
-	for(int i = 0; i < g_hBossHits.Length; i++)
-	{
-		int BossHit[2];
-		g_hBossHits.GetArray(i, BossHit, sizeof(BossHit));
-
-		if(BossHit[0] == iIdentificationEntity)
-			g_hBossHits.Erase(i)
-	}
-
-	if (reason != 2)
-		return;
-
-	for (int client = 1; client <= MaxClients; client++)
-	{
-		if (!IsClientInGame(client) || !iBossHits[client])
-			continue;
-
-		iSortedList[iSortedCount][0] = client;
-		iSortedList[iSortedCount][1] = iBossHits[client];
-		iSortedCount++;
-	}
-	SortCustom2D(iSortedList, iSortedCount, SortBossDamageList);
-
-	if (iSortedCount)
-	{
-		char sBuffer[512];
-		Format(sBuffer, sizeof(sBuffer), "BOSS DAMAGE (%s):", sBossName);
-		Format(sBuffer, sizeof(sBuffer), "%s\n*************************", sBuffer);
-
-		if (iSortedList[0][0])
-		{
-			Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d hits", sBuffer, iSortedList[0][0], iSortedList[0][1]);
-		}
-
-		if (iSortedList[1][0])
-		{
-			Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d hits", sBuffer, iSortedList[1][0], iSortedList[1][1]);
-		}
-
-		if (iSortedList[2][0])
-		{
-			Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d hits", sBuffer, iSortedList[2][0], iSortedList[2][1]);
-		}
-
-		Format(sBuffer, sizeof(sBuffer), "%s\n*************************", sBuffer);
-
-		Handle hMessage = StartMessageAll("HudMsg");
-		if (hMessage)
-		{
-			if (GetUserMessageType() == UM_Protobuf)
-			{
-				PbSetInt(hMessage, "channel", 50);
-				PbSetInt(hMessage, "effect", 0);
-				PbSetColor(hMessage, "clr1", {255, 255, 255, 255});
-				PbSetColor(hMessage, "clr2", {255, 255, 255, 255});
-				PbSetVector2D(hMessage, "pos", Float:{0.02, 0.45});
-				PbSetFloat(hMessage, "fade_in_time", 0.1);
-				PbSetFloat(hMessage, "fade_out_time", 0.1);
-				PbSetFloat(hMessage, "hold_time", 7.0);
-				PbSetFloat(hMessage, "fx_time", 0.0);
-				PbSetString(hMessage, "text", sBuffer);
-				EndMessage();
-			}
-			else
-			{
-				BfWriteByte(hMessage, 50);
-				BfWriteFloat(hMessage, 0.02);
-				BfWriteFloat(hMessage, 0.25);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 0);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 255);
-				BfWriteByte(hMessage, 0);
-				BfWriteFloat(hMessage, 0.1);
-				BfWriteFloat(hMessage, 0.1);
-				BfWriteFloat(hMessage, 7.0);
-				BfWriteFloat(hMessage, 0.0);
-				BfWriteString(hMessage, sBuffer);
-				EndMessage();
-			}
-		}
-
-		if(GetEngineVersion() == Engine_CSGO)
-		{
-			int iSplits
-			char sSplits[16][512];
-
-			if((iSplits = ExplodeString(sBuffer, "\n", sSplits, sizeof(sSplits), sizeof(sSplits[]))) != 0)
-			{
-				for (int iSplit; iSplit < iSplits; iSplit++)
-				{
-					PrintToChatAll(sSplits[iSplit]);
-				}
-			}
-		}
-		else
-			PrintToChatAll(sBuffer);
-	}
-}
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-public int SortBossDamageList(int[] elem1, int[] elem2, const int[][] array, Handle hndl)
-{
-	if (elem1[1] > elem2[1]) return -1;
-	if (elem1[1] < elem2[1]) return 1;
-
-	return 0;
-}
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-public void OnClientDisconnect(int client)
-{
-	for(int i = 0; i < g_hBossHits.Length; i++)
-	{
-		int BossHit[2];
-		g_hBossHits.GetArray(i, BossHit, sizeof(BossHit));
-
-		if(BossHit[1] == client)
-			g_hBossHits.Erase(i);
-	}
-}
-
-
-//----------------------------------------------------------------------------------------------------
-// Purpose:
-//----------------------------------------------------------------------------------------------------
-stock int IsValidClient(int client, bool nobots = true)
-{
-	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
-		return false;
-
-	return IsClientInGame(client);
-}
\ No newline at end of file