From 726d5b5c8a3600be5d7bc3872dccddfe433237b1 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 8 Aug 2018 23:26:48 +0200 Subject: [PATCH] TopDefenders: gfl version --- TopDefenders/scripting/TopDefenders.sp | 180 +++---------------------- 1 file changed, 21 insertions(+), 159 deletions(-) diff --git a/TopDefenders/scripting/TopDefenders.sp b/TopDefenders/scripting/TopDefenders.sp index c53ee1df..f46e01c6 100644 --- a/TopDefenders/scripting/TopDefenders.sp +++ b/TopDefenders/scripting/TopDefenders.sp @@ -4,40 +4,33 @@ #include #include +#include "loghelper.inc" + #define SPECMODE_NONE 0 #define SPECMODE_FIRSTPERSON 4 #define SPECMODE_THIRDPERSON 5 #define SPECMODE_FREELOOK 6 -/* BOOLS */ bool g_bHideCrown[MAXPLAYERS+1]; bool g_bHideDialog[MAXPLAYERS+1]; bool g_bProtection[MAXPLAYERS+1]; -/* COOKIES */ Handle g_hCookie_HideCrown; Handle g_hCookie_HideDialog; Handle g_hCookie_Protection; -/* FORWARD */ -Handle g_hForward_OnRoundEndingWithTopDefenders; - -/* CONVARS */ ConVar g_hCVar_Protection; ConVar g_hCVar_ProtectionMinimal1; ConVar g_hCVar_ProtectionMinimal2; ConVar g_hCVar_ProtectionMinimal3; -/* INTERGERS */ int g_iCrownEntity = -1; int g_iDialogLevel = 100000; int g_iPlayerWinner[3]; int g_iPlayerDamage[MAXPLAYERS+1]; +int g_iPlayerDamageFrom1K[MAXPLAYERS+1]; -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "Top Defenders", @@ -46,17 +39,6 @@ public Plugin myinfo = version = "1.0.0" }; -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) -{ - CreateNative("TopDefenders_GetClientDamage", Native_GetClientDamage); -} - -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnPluginStart() { LoadTranslations("plugin.topdefenders.phrases"); @@ -70,8 +52,6 @@ public void OnPluginStart() g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private); g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private); - g_hForward_OnRoundEndingWithTopDefenders = CreateGlobalForward("TopDefenders_OnRoundEnd", ET_Ignore, Param_Array, Param_Array); - CreateTimer(0.1, UpdateScoreboard, INVALID_HANDLE, TIMER_REPEAT); CreateTimer(0.1, UpdateDialog, INVALID_HANDLE, TIMER_REPEAT); @@ -88,36 +68,24 @@ public void OnPluginStart() SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Top Defenders"); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action OnToggleCrown(int client, int args) { ToggleCrown(client); return Plugin_Handled; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action OnToggleDialog(int client, int args) { ToggleDialog(client); return Plugin_Handled; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action OnToggleImmunity(int client, int args) { ToggleImmunity(client); return Plugin_Handled; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void ToggleCrown(int client) { g_bHideCrown[client] = !g_bHideCrown[client]; @@ -127,9 +95,6 @@ public void ToggleCrown(int client) CPrintToChat(client, "{cyan}%t {white}%t", "Chat Prefix", g_bHideCrown[client] ? "Crown Disabled" : "Crown Enabled"); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void ToggleDialog(int client) { g_bHideDialog[client] = !g_bHideDialog[client]; @@ -139,9 +104,6 @@ public void ToggleDialog(int client) CPrintToChat(client, "{cyan}%t {white}%t", "Chat Prefix", g_bHideDialog[client] ? "Dialog Disabled" : "Dialog Enabled"); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void ToggleImmunity(int client) { g_bProtection[client] = !g_bProtection[client]; @@ -151,9 +113,6 @@ public void ToggleImmunity(int client) CPrintToChat(client, "{cyan}%t {white}%t", "Chat Prefix", g_bProtection[client] ? "Immunity Disabled" : "Immunity Enabled"); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void ShowSettingsMenu(int client) { Menu menu = new Menu(MenuHandler_MainMenu); @@ -169,9 +128,6 @@ public void ShowSettingsMenu(int client) menu.Display(client, MENU_TIME_FOREVER); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) { switch(action) @@ -187,9 +143,6 @@ public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection) { switch(action) @@ -216,9 +169,6 @@ public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int se } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnMapStart() { PrecacheSound("unloze/holy.wav"); @@ -236,11 +186,10 @@ public void OnMapStart() AddFileToDownloadsTable("materials/models/unloze/crown/crown_bump.vtf"); AddFileToDownloadsTable("materials/models/unloze/crown/crown_detail.vtf"); AddFileToDownloadsTable("materials/models/unloze/crown/crown_lightwarp.vtf"); + + GetTeams(); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnClientCookiesCached(int client) { char sBuffer[4]; @@ -266,9 +215,6 @@ public void OnClientCookiesCached(int client) g_bProtection[client] = false; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { g_iPlayerDamage[client] = 0; @@ -278,9 +224,6 @@ public void OnClientDisconnect(int client) g_bProtection[client] = false; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public int SortDefendersList(int[] elem1, int[] elem2, const int[][] array, Handle hndl) { if (elem1[1] > elem2[1]) return -1; @@ -289,9 +232,6 @@ public int SortDefendersList(int[] elem1, int[] elem2, const int[][] array, Hand return 0; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action UpdateScoreboard(Handle timer) { int iSortedList[MAXPLAYERS+1][2]; @@ -320,9 +260,6 @@ public Action UpdateScoreboard(Handle timer) } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action UpdateDialog(Handle timer) { if (g_iDialogLevel <= 0) @@ -356,9 +293,6 @@ public Action UpdateDialog(Handle timer) g_iDialogLevel--; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) { g_iDialogLevel = 100000; @@ -366,12 +300,10 @@ public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) for (int client = 1; client <= MaxClients; client++) { g_iPlayerDamage[client] = 0; + g_iPlayerDamageFrom1K[client] = 0; } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast) { g_iPlayerWinner = {-1, -1, -1}; @@ -398,15 +330,6 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast if (iSortedCount) { - int iPlayers[MAXPLAYERS+1]; - int iDamage[MAXPLAYERS+1]; - - for (int rank = 0; rank < iSortedCount; rank++) - { - iPlayers[rank] = iSortedList[rank][0]; - iDamage[rank] = iSortedList[rank][1]; - } - char sBuffer[512]; Format(sBuffer, sizeof(sBuffer), "TOP DEFENDERS:"); Format(sBuffer, sizeof(sBuffer), "%s\n*************************", sBuffer); @@ -414,6 +337,7 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast if (iSortedList[0][0]) { Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d DMG", sBuffer, iSortedList[0][0], iSortedList[0][1]); + LogPlayerEvent(iSortedList[0][0], "triggered", "top_defender"); g_iPlayerWinner[0] = GetSteamAccountID(iSortedList[0][0]); } @@ -421,6 +345,7 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast if (iSortedList[1][0]) { Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d DMG", sBuffer, iSortedList[1][0], iSortedList[1][1]); + LogPlayerEvent(iSortedList[1][0], "triggered", "second_defender"); g_iPlayerWinner[1] = GetSteamAccountID(iSortedList[1][0]); } @@ -428,6 +353,7 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast if (iSortedList[2][0]) { Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d DMG", sBuffer, iSortedList[2][0], iSortedList[2][1]); + LogPlayerEvent(iSortedList[2][0], "triggered", "third_defender"); g_iPlayerWinner[2] = GetSteamAccountID(iSortedList[2][0]); } @@ -474,29 +400,10 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast } } - 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); - - TopDefenders_OnRoundEnd(iPlayers, iDamage); + PrintToChatAll(sBuffer); } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast) { int client = GetClientOfUserId(hEvent.GetInt("attacker")); @@ -508,12 +415,18 @@ public void OnClientHurt(Event hEvent, const char[] sEvent, bool bDontBroadcast) if (client == victim || (IsPlayerAlive(client) && ZR_IsClientZombie(client))) return; - g_iPlayerDamage[client] += hEvent.GetInt("dmg_health"); + int iDamage = hEvent.GetInt("dmg_health"); + + g_iPlayerDamage[client] += iDamage; + g_iPlayerDamageFrom1K[client] += iDamage; + + if (g_iPlayerDamageFrom1K[client] >= 1000) + { + g_iPlayerDamageFrom1K[client] -= 1000; + LogPlayerEvent(client, "triggered", "damage_zombie"); + } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast) { int client = GetClientOfUserId(hEvent.GetInt("userid")); @@ -524,9 +437,6 @@ public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action OnClientSpawnPost(Handle timer, int client) { if (!IsClientInGame(client) || IsFakeClient(client) || !IsPlayerAlive(client)) @@ -566,9 +476,6 @@ public Action OnClientSpawnPost(Handle timer, int client) AcceptEntityInput(g_iCrownEntity, "SetParent", client); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast) { int client = GetClientOfUserId(hEvent.GetInt("userid")); @@ -582,9 +489,6 @@ public void OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBroadcast } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action ZR_OnClientInfect(&client, &attacker, &bool:motherInfect, &bool:respawnOverride, &bool:respawn) { if (g_hCVar_Protection.BoolValue && motherInfect && !g_bProtection[client]) @@ -642,39 +546,6 @@ public Action ZR_OnClientInfect(&client, &attacker, &bool:motherInfect, &bool:re return Plugin_Continue; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -bool TopDefenders_OnRoundEnd(int iPlayers[MAXPLAYERS+1], int iDamage[MAXPLAYERS+1]) -{ - Call_StartForward(g_hForward_OnRoundEndingWithTopDefenders); - Call_PushArray(iPlayers, sizeof(iPlayers)); - Call_PushArray(iDamage, sizeof(iDamage)); - Call_Finish(); -} - -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public int Native_GetClientDamage(Handle hPlugin, int numParams) -{ - int client = GetNativeCell(1); - if (client < 1 || client > MaxClients) - { - return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client); - } - - if (!IsClientInGame(client)) - { - return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in game", client); - } - - return g_iPlayerDamage[client]; -} - -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- void AddMenuItemTranslated(Menu menu, const char[] info, const char[] display, any ...) { char buffer[128]; @@ -683,9 +554,6 @@ void AddMenuItemTranslated(Menu menu, const char[] info, const char[] display, a menu.AddItem(info, buffer); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- void SendDialog(int client, const char[] display, const int level, const int time, any ...) { char buffer[128]; @@ -718,18 +586,12 @@ void SendDialog(int client, const char[] display, const int level, const int tim delete kv; } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- int GetClientSpectatorMode(int client) { return GetEntProp(client, Prop_Send, "m_iObserverMode"); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- int GetClientSpectatorTarget(int client) { return GetEntPropEnt(client, Prop_Send, "m_hObserverTarget"); -} \ No newline at end of file +}