From ac19bed49c249e6deeccd45d057a021257731555 Mon Sep 17 00:00:00 2001 From: dogan Date: Thu, 30 Jul 2020 16:53:31 +0200 Subject: [PATCH] DefenderMoney --> CashManager --- .../scripting/CashManager.sp | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) rename _DefenderMoney/scripting/DefenderMoney.sp => CashManager/scripting/CashManager.sp (81%) diff --git a/_DefenderMoney/scripting/DefenderMoney.sp b/CashManager/scripting/CashManager.sp similarity index 81% rename from _DefenderMoney/scripting/DefenderMoney.sp rename to CashManager/scripting/CashManager.sp index a48b2ccb..33e4d5b1 100644 --- a/_DefenderMoney/scripting/DefenderMoney.sp +++ b/CashManager/scripting/CashManager.sp @@ -18,6 +18,8 @@ ConVar g_cvarDamageMultiplier = null; ConVar g_cvarInfectionGain; ConVar g_cvarHumanWinGain; +ConVar g_cvarRoundStartGain; +ConVar g_cvarMaxCash; bool g_bZRLoaded; bool g_bMapEnd; @@ -28,9 +30,9 @@ int g_iSteamID[256]; public Plugin myinfo = { - name = "Defender Money", + name = "Cash Manager", author = "Obus + Dogan", - description = "Reward Humans with cash for shooting Zombies", + description = "Manage Cash with additional gains and limits", version = "1.1.0", url = "" }; @@ -41,14 +43,17 @@ public void OnPluginStart() g_cvarDamageMultiplier = CreateConVar("sm_damagecashmultiplier", "1.0", "Multiplier that decides how much cash a client shall receive upon dealing damage"); g_cvarInfectionGain = CreateConVar("sm_infectioncashgain", "500", "Cash a client shall receive upon infection"); g_cvarHumanWinGain = CreateConVar("sm_humanwincashgain", "2500", "Cash a human shall receive upon human win"); + g_cvarRoundStartGain = CreateConVar("sm_roundstartcashgain", "2500", "Cash everyone shall receive upon round start"); + g_cvarMaxCash = CreateConVar("sm_maxcash", "45000", "Max cash you can store"); - AutoExecConfig(true, "plugin.DefenderMoney"); + AutoExecConfig(true, "plugin.CashManager"); #endif 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_Post); + HookEvent("round_start", EventHook_RoundStart, EventHookMode_Pre); g_bMapEnd = false; } @@ -111,6 +116,9 @@ public void OnClientPutInServer(int client) public Action MessageReconnect(Handle timer, int client) { + if(!IsClientInGame(client)) + return Plugin_Handled; + PrintToChat(client, "[SM] Restored your cash: $%d.", g_iCash[client]); return Plugin_Handled; @@ -147,7 +155,7 @@ public void OnClientDisconnect(int client) public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) { - if(!motherInfect && IsValidClient(attacker)) + if(!motherInfect && IsValidClient(attacker) && !(GetEntProp(attacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)) SetEntProp(attacker, Prop_Send, "m_iAccount", GetEntProp(attacker, Prop_Send, "m_iAccount") + g_cvarInfectionGain.IntValue); } @@ -160,7 +168,7 @@ public Action EventHook_RoundEnd(Event hEvent, const char[] sEventName, bool bDo if(!IsValidClient(i)) continue; - if(ZR_IsClientHuman(i) && bAwardHumans) + if(ZR_IsClientHuman(i) && bAwardHumans && !(GetEntProp(i, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)) { SetEntProp(i, Prop_Send, "m_iAccount", GetEntProp(i, Prop_Send, "m_iAccount") + g_cvarHumanWinGain.IntValue); g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount"); @@ -172,6 +180,15 @@ public Action EventHook_RoundEnd(Event hEvent, const char[] sEventName, bool bDo } } +public Action EventHook_RoundStart(Event hEvent, const char[] sEventName, bool bDontBroadcast) +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsValidClient(i) && !(GetEntProp(i, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)) + g_iCash[i] = g_iCash[i] + g_cvarRoundStartGain.IntValue; + } +} + public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool bDontBroadcast) { if(!g_bZRLoaded) @@ -194,7 +211,7 @@ public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool b if(!strncmp(sWeapon, "knife", 5)) return Plugin_Continue; - if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= 65000) + if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue) return Plugin_Continue; #if defined DMGINSTEADOFHITS @@ -236,8 +253,10 @@ public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool public void RequestFrame_Callback(int client) { - if(g_iCash[client] > 0) + if(g_iCash[client] > 0 && g_iCash[client] < g_cvarMaxCash.IntValue) SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]); + else if(g_iCash[client] > 0 && g_iCash[client] >= g_cvarMaxCash.IntValue) + SetEntProp(client, Prop_Send, "m_iAccount", g_cvarMaxCash.IntValue); } public void RequestFrame_Callback2(int iPacked)