DefenderMoney: lets try dis

This commit is contained in:
dogan 2020-07-30 00:15:59 +02:00
parent 50fa7b068a
commit c80360ba7f

View File

@ -18,12 +18,14 @@ ConVar g_cvarDamageMultiplier = null;
bool g_bZRLoaded; bool g_bZRLoaded;
int g_iCash[MAXPLAYERS + 1];
public Plugin myinfo = public Plugin myinfo =
{ {
name = "Defender Money", name = "Defender Money",
author = "Obus", author = "Obus + Dogan",
description = "", description = "",
version = "0.0.1", version = "1.0.0",
url = "" url = ""
}; };
@ -37,6 +39,8 @@ public void OnPluginStart()
HookEvent("player_hurt", EventHook_PlayerHurt, EventHookMode_Pre); HookEvent("player_hurt", EventHook_PlayerHurt, EventHookMode_Pre);
HookEvent("player_death", EventHook_PlayerDeath, 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() public void OnAllPluginsLoaded()
@ -56,6 +60,28 @@ public void OnLibraryRemoved(const char[] sName)
g_bZRLoaded = false; 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) public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{ {
if(!g_bZRLoaded) if(!g_bZRLoaded)
@ -78,6 +104,9 @@ public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool b
if(!strncmp(sWeapon, "knife", 5)) if(!strncmp(sWeapon, "knife", 5))
return Plugin_Continue; return Plugin_Continue;
if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= 65000)
return Plugin_Continue;
#if defined DMGINSTEADOFHITS #if defined DMGINSTEADOFHITS
float fDamage = float(hEvent.GetInt("dmg_health")); float fDamage = float(hEvent.GetInt("dmg_health"));
@ -91,27 +120,21 @@ public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool b
public Action EventHook_PlayerDeath(Event hEvent, const char[] sEventName, bool bDontBroadcast) public Action EventHook_PlayerDeath(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{ {
if (!g_bZRLoaded) int client = GetClientOfUserId(hEvent.GetInt("userid"));
return Plugin_Continue;
int iAttacker = GetClientOfUserId(hEvent.GetInt("attacker")); g_iCash[client] = GetEntProp(client, Prop_Send, "m_iAccount");
if (!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker))
return Plugin_Continue;
int iPacked = (iAttacker<<16) | (GetEntProp(iAttacker, Prop_Send, "m_iAccount")&0xFFFF);
RequestFrame(RequestFrame_Callback, iPacked);
return Plugin_Continue; return Plugin_Continue;
} }
void RequestFrame_Callback(int iPacked) public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{ {
int iOldCash = iPacked&0xFFFF; int client = GetClientOfUserId(hEvent.GetInt("userid"));
int iAttacker = iPacked>>16;
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) stock bool IsValidClient(int client)