From 65fe0f846b44a76083d2739b1334aec9922adc28 Mon Sep 17 00:00:00 2001 From: dogan Date: Thu, 30 Jul 2020 00:15:59 +0200 Subject: [PATCH] DefenderMoney: lets try dis --- _DefenderMoney/scripting/DefenderMoney.sp | 69 +++++++++++++++-------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/_DefenderMoney/scripting/DefenderMoney.sp b/_DefenderMoney/scripting/DefenderMoney.sp index a71c1811..9f75f01d 100644 --- a/_DefenderMoney/scripting/DefenderMoney.sp +++ b/_DefenderMoney/scripting/DefenderMoney.sp @@ -18,12 +18,14 @@ ConVar g_cvarDamageMultiplier = null; bool g_bZRLoaded; +int g_iCash[MAXPLAYERS + 1]; + public Plugin myinfo = { name = "Defender Money", - author = "Obus", + author = "Obus + Dogan", description = "", - version = "0.0.1", + version = "1.0.0", url = "" }; @@ -37,6 +39,8 @@ public void OnPluginStart() HookEvent("player_hurt", EventHook_PlayerHurt, EventHookMode_Pre); HookEvent("player_death", EventHook_PlayerDeath, EventHookMode_Pre); + HookEvent("player_spawn", EventHook_PlayerSpawn, EventHookMode_Post); + HookEvent("round_end", EventHook_RoundEnd, EventHookMode_Pre); } public void OnAllPluginsLoaded() @@ -46,36 +50,61 @@ public void OnAllPluginsLoaded() public void OnLibraryAdded(const char[] sName) { - if (strcmp(sName, "zombiereloaded", false) == 0) + if(strcmp(sName, "zombiereloaded", false) == 0) g_bZRLoaded = true; } public void OnLibraryRemoved(const char[] sName) { - if (strcmp(sName, "zombiereloaded", false) == 0) + if(strcmp(sName, "zombiereloaded", false) == 0) g_bZRLoaded = false; } +public void OnMapStart() +{ + for(int i = 1; i <= MaxClients; i++) + { + g_iCash[i] = 0; + } +} + +public void OnClientDisconnect(int client) +{ + g_iCash[client] = 0; +} + +public Action EventHook_RoundEnd(Event hEvent, const char[] sEventName, bool bDontBroadcast) +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsValidClient(i)) + g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount"); + } +} + public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool bDontBroadcast) { - if (!g_bZRLoaded) + if(!g_bZRLoaded) return Plugin_Continue; int iAttacker = GetClientOfUserId(hEvent.GetInt("attacker")); - if (!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker)) + if(!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker)) return Plugin_Continue; int iVictim = GetClientOfUserId(hEvent.GetInt("userid")); - if (!IsValidClient(iVictim) || !ZR_IsClientZombie(iVictim)) + if(!IsValidClient(iVictim) || !ZR_IsClientZombie(iVictim)) return Plugin_Continue; char sWeapon[16]; hEvent.GetString("weapon", sWeapon, sizeof(sWeapon)); - if (!strncmp(sWeapon, "knife", 5)) + if(!strncmp(sWeapon, "knife", 5)) + return Plugin_Continue; + + if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= 65000) return Plugin_Continue; #if defined DMGINSTEADOFHITS @@ -91,30 +120,24 @@ public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool b public Action EventHook_PlayerDeath(Event hEvent, const char[] sEventName, bool bDontBroadcast) { - if (!g_bZRLoaded) - return Plugin_Continue; + int client = GetClientOfUserId(hEvent.GetInt("userid")); - int iAttacker = GetClientOfUserId(hEvent.GetInt("attacker")); - - if (!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker)) - return Plugin_Continue; - - int iPacked = (iAttacker<<16) | (GetEntProp(iAttacker, Prop_Send, "m_iAccount")&0xFFFF); - - RequestFrame(RequestFrame_Callback, iPacked); + g_iCash[client] = GetEntProp(client, Prop_Send, "m_iAccount"); return Plugin_Continue; } -void RequestFrame_Callback(int iPacked) +public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool bDontBroadcast) { - int iOldCash = iPacked&0xFFFF; - int iAttacker = iPacked>>16; + int client = GetClientOfUserId(hEvent.GetInt("userid")); - SetEntProp(iAttacker, Prop_Send, "m_iAccount", iOldCash); + if(g_iCash[client] > 0) + SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]); + + return Plugin_Continue; } stock bool IsValidClient(int client) { return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client)); -} +} \ No newline at end of file