sm-plugins/_DefenderMoney/scripting/DefenderMoney.sp

143 lines
3.4 KiB
SourcePawn
Raw Normal View History

2018-08-07 22:29:47 +02:00
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#undef REQUIRE_PLUGIN
#tryinclude <zombiereloaded>
#define REQUIRE_PLUGIN
#pragma newdecls required
#define DMGINSTEADOFHITS
#define CASHPERHIT 4
#if defined DMGINSTEADOFHITS
ConVar g_cvarDamageMultiplier = null;
#endif
bool g_bZRLoaded;
2020-07-30 00:15:59 +02:00
int g_iCash[MAXPLAYERS + 1];
2018-08-07 22:29:47 +02:00
public Plugin myinfo =
{
name = "Defender Money",
2020-07-30 00:15:59 +02:00
author = "Obus + Dogan",
2018-08-07 22:29:47 +02:00
description = "",
2020-07-30 00:15:59 +02:00
version = "1.0.0",
2018-08-07 22:29:47 +02:00
url = ""
};
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");
AutoExecConfig(true, "plugin.DefenderMoney");
#endif
HookEvent("player_hurt", EventHook_PlayerHurt, EventHookMode_Pre);
HookEvent("player_death", EventHook_PlayerDeath, EventHookMode_Pre);
2020-07-30 00:15:59 +02:00
HookEvent("player_spawn", EventHook_PlayerSpawn, EventHookMode_Post);
HookEvent("round_end", EventHook_RoundEnd, EventHookMode_Pre);
2018-08-07 22:29:47 +02:00
}
public void OnAllPluginsLoaded()
{
g_bZRLoaded = LibraryExists("zombiereloaded");
}
public void OnLibraryAdded(const char[] sName)
{
2020-07-30 00:15:59 +02:00
if(strcmp(sName, "zombiereloaded", false) == 0)
2018-08-07 22:29:47 +02:00
g_bZRLoaded = true;
}
public void OnLibraryRemoved(const char[] sName)
{
2020-07-30 00:15:59 +02:00
if(strcmp(sName, "zombiereloaded", false) == 0)
2018-08-07 22:29:47 +02:00
g_bZRLoaded = false;
}
2020-07-30 00:15:59 +02:00
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");
}
}
2018-08-07 22:29:47 +02:00
public Action EventHook_PlayerHurt(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
2020-07-30 00:15:59 +02:00
if(!g_bZRLoaded)
2018-08-07 22:29:47 +02:00
return Plugin_Continue;
int iAttacker = GetClientOfUserId(hEvent.GetInt("attacker"));
2020-07-30 00:15:59 +02:00
if(!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker))
2018-08-07 22:29:47 +02:00
return Plugin_Continue;
int iVictim = GetClientOfUserId(hEvent.GetInt("userid"));
2020-07-30 00:15:59 +02:00
if(!IsValidClient(iVictim) || !ZR_IsClientZombie(iVictim))
2018-08-07 22:29:47 +02:00
return Plugin_Continue;
char sWeapon[16];
hEvent.GetString("weapon", sWeapon, sizeof(sWeapon));
2020-07-30 00:15:59 +02:00
if(!strncmp(sWeapon, "knife", 5))
return Plugin_Continue;
if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= 65000)
2018-08-07 22:29:47 +02:00
return Plugin_Continue;
#if defined DMGINSTEADOFHITS
float fDamage = float(hEvent.GetInt("dmg_health"));
SetEntProp(iAttacker, Prop_Send, "m_iAccount", GetEntProp(iAttacker, Prop_Send, "m_iAccount") + RoundToNearest(fDamage > 0.0 ? fDamage * g_cvarDamageMultiplier.FloatValue : 1.0));
#else
SetEntProp(iAttacker, Prop_Send, "m_iAccount", GetEntProp(iAttacker, Prop_Send, "m_iAccount") + CASHPERHIT);
#endif
return Plugin_Continue;
}
public Action EventHook_PlayerDeath(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
2020-07-30 00:15:59 +02:00
int client = GetClientOfUserId(hEvent.GetInt("userid"));
2018-08-07 22:29:47 +02:00
2020-07-30 00:15:59 +02:00
g_iCash[client] = GetEntProp(client, Prop_Send, "m_iAccount");
2018-08-07 22:29:47 +02:00
return Plugin_Continue;
}
2020-07-30 00:15:59 +02:00
public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool bDontBroadcast)
2018-08-07 22:29:47 +02:00
{
2020-07-30 00:15:59 +02:00
int client = GetClientOfUserId(hEvent.GetInt("userid"));
if(g_iCash[client] > 0)
SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]);
2018-08-07 22:29:47 +02:00
2020-07-30 00:15:59 +02:00
return Plugin_Continue;
2018-08-07 22:29:47 +02:00
}
stock bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client));
2020-07-30 00:15:59 +02:00
}