DefenderMoney: more fixes and features

This commit is contained in:
dogan 2020-07-30 13:28:59 +02:00
parent d539c84c3e
commit 42be4648d6

View File

@ -16,6 +16,9 @@
ConVar g_cvarDamageMultiplier = null;
#endif
ConVar g_cvarInfectionGain;
ConVar g_cvarHumanWinGain;
bool g_bZRLoaded;
bool g_bMapEnd;
@ -36,6 +39,8 @@ public void OnPluginStart()
{
#if defined DMGINSTEADOFHITS
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");
AutoExecConfig(true, "plugin.DefenderMoney");
#endif
@ -43,7 +48,7 @@ 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);
HookEvent("round_end", EventHook_RoundEnd, EventHookMode_Post);
g_bMapEnd = false;
}
@ -113,7 +118,7 @@ public Action MessageReconnect(Handle timer, int client)
public void OnClientDisconnect(int client)
{
if(IsFakeClient(client))
if(IsFakeClient(client) || !IsClientInGame(client))
return;
int iSteamID = GetSteamAccountID(client);
@ -140,12 +145,30 @@ public void OnClientDisconnect(int client)
g_iCash[client] = 0;
}
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
if(!motherInfect && IsValidClient(attacker))
SetEntProp(attacker, Prop_Send, "m_iAccount", GetEntProp(attacker, Prop_Send, "m_iAccount") + g_cvarInfectionGain.IntValue);
}
public Action EventHook_RoundEnd(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
bool bAwardHumans = hEvent.GetInt("winner") == CS_TEAM_CT;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
if(!IsValidClient(i))
continue;
if(ZR_IsClientHuman(i) && bAwardHumans)
{
SetEntProp(i, Prop_Send, "m_iAccount", GetEntProp(i, Prop_Send, "m_iAccount") + g_cvarHumanWinGain.IntValue);
g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
}
else
{
g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
}
}
}
@ -198,12 +221,17 @@ public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool
{
int client = GetClientOfUserId(hEvent.GetInt("userid"));
if(g_iCash[client] > 0)
SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]);
RequestFrame(RequestFrame_Callback, client);
return Plugin_Continue;
}
public void RequestFrame_Callback(int client)
{
if(g_iCash[client] > 0)
SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]);
}
stock bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client));