sm-plugins/CashManager/scripting/CashManager.sp

385 lines
11 KiB
SourcePawn
Raw Normal View History

2018-08-07 22:29:47 +02:00
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <sdkhooks>
#include <sdktools>
2020-08-17 16:13:21 +02:00
#include <multicolors>
2018-08-07 22:29:47 +02:00
#undef REQUIRE_PLUGIN
#tryinclude <zombiereloaded>
#define REQUIRE_PLUGIN
#pragma newdecls required
#define DMGINSTEADOFHITS
#define CASHPERHIT 4
#if defined DMGINSTEADOFHITS
ConVar g_cvarDamageMultiplier = null;
#endif
2020-07-30 13:28:59 +02:00
ConVar g_cvarInfectionGain;
2020-08-01 13:44:12 +02:00
ConVar g_cvarMotherZombieWinGain;
2020-07-30 13:28:59 +02:00
ConVar g_cvarHumanWinGain;
ConVar g_cvarHumanTriggerGain;
ConVar g_cvarRoundStartCash;
ConVar g_cvarMapStartCash;
2020-07-30 16:53:31 +02:00
ConVar g_cvarMaxCash;
2020-07-30 13:28:59 +02:00
2018-08-07 22:29:47 +02:00
bool g_bZRLoaded;
2020-07-30 02:10:43 +02:00
bool g_bMapEnd;
bool g_bTriggerCooldown;
bool g_bDisabled[2048];
2018-08-07 22:29:47 +02:00
2020-08-01 13:44:12 +02:00
bool g_bMotherZombie[MAXPLAYERS + 1];
2020-07-30 00:15:59 +02:00
int g_iCash[MAXPLAYERS + 1];
2020-07-30 02:10:43 +02:00
int g_iCashReconnect[256];
int g_iSteamID[256];
2020-07-30 00:15:59 +02:00
2018-08-07 22:29:47 +02:00
public Plugin myinfo =
{
2020-07-30 16:53:31 +02:00
name = "Cash Manager",
2020-07-30 00:15:59 +02:00
author = "Obus + Dogan",
2020-07-30 16:53:31 +02:00
description = "Manage Cash with additional gains and limits",
2020-08-17 16:13:21 +02:00
version = "2.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");
2020-07-30 13:28:59 +02:00
g_cvarInfectionGain = CreateConVar("sm_infectioncashgain", "500", "Cash a client shall receive upon infection");
2020-08-01 13:44:12 +02:00
g_cvarMotherZombieWinGain = CreateConVar("sm_motherzombiecashgain", "2500", "Cash a client shall receive upon zombie win while being motherzombie");
2020-07-30 13:28:59 +02:00
g_cvarHumanWinGain = CreateConVar("sm_humanwincashgain", "2500", "Cash a human shall receive upon human win");
g_cvarHumanTriggerGain = CreateConVar("sm_humantriggercashgain", "200", "Cash a human shall receive upon triggering");
g_cvarRoundStartCash = CreateConVar("sm_roundstartcash", "2500", "Minimum cash a client starts the round");
g_cvarMapStartCash = CreateConVar("sm_mapstartcash", "12500", "Cash a client starts the map");
2020-07-30 16:53:31 +02:00
g_cvarMaxCash = CreateConVar("sm_maxcash", "45000", "Max cash you can store");
2018-08-07 22:29:47 +02:00
2020-07-30 16:53:31 +02:00
AutoExecConfig(true, "plugin.CashManager");
2018-08-07 22:29:47 +02:00
#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);
2020-07-30 13:28:59 +02:00
HookEvent("round_end", EventHook_RoundEnd, EventHookMode_Post);
HookEvent("round_start", EventHook_RoundStart, EventHookMode_Post);
HookEntityOutput("trigger_once", "OnStartTouch", OnStartTouch);
HookEntityOutput("func_button", "OnPressed", OnPressed);
2020-07-30 02:10:43 +02:00
g_bMapEnd = false;
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()
{
2020-07-30 02:10:43 +02:00
for(int i = 0; i < 256; i++)
{
g_iSteamID[i] = 0;
g_iCashReconnect[i] = -1;
2020-07-30 02:10:43 +02:00
}
2020-07-30 00:15:59 +02:00
for(int i = 1; i <= MaxClients; i++)
g_iCash[i] = -1;
2020-07-30 02:10:43 +02:00
g_bMapEnd = false;
}
public void OnMapEnd()
{
g_bMapEnd = true;
}
public void OnClientPutInServer(int client)
{
if(IsFakeClient(client) || g_bMapEnd)
return;
int iSteamID = GetSteamAccountID(client);
g_iCash[client] = g_cvarMapStartCash.IntValue;
SetEntProp(client, Prop_Send, "m_iAccount", g_cvarMapStartCash.IntValue);
2020-07-30 02:10:43 +02:00
for(int i = 0; i < 256; i++)
{
if(iSteamID == g_iSteamID[i])
{
g_iCash[client] = g_iCashReconnect[i];
SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]);
2020-07-30 02:10:43 +02:00
CreateTimer(3.0, MessageReconnect, client);
break;
}
}
}
public Action MessageReconnect(Handle timer, int client)
{
2020-07-30 16:53:31 +02:00
if(!IsClientInGame(client))
return Plugin_Handled;
2020-08-17 16:13:21 +02:00
CPrintToChat(client, "{cyan}[UNLOZE CashManager] {white}Restored your cash: {yellow}$%d{white}.", g_iCash[client]);
2020-07-30 02:10:43 +02:00
return Plugin_Handled;
2020-07-30 00:15:59 +02:00
}
public void OnClientDisconnect(int client)
{
2020-07-30 13:28:59 +02:00
if(IsFakeClient(client) || !IsClientInGame(client))
2020-07-30 02:10:43 +02:00
return;
int iSteamID = GetSteamAccountID(client);
for(int i = 0; i < 256; i++)
{
if(iSteamID == g_iSteamID[i])
{
g_iCashReconnect[i] = GetEntProp(client, Prop_Send, "m_iAccount");
return;
}
}
for(int i = 0; i < 256; i++)
{
if(g_iSteamID[i] == 0)
{
g_iSteamID[i] = iSteamID;
g_iCashReconnect[i] = GetEntProp(client, Prop_Send, "m_iAccount");
break;
}
}
g_iCash[client] = -1;
2020-08-01 13:44:12 +02:00
g_bMotherZombie[client] = false;
2020-07-30 00:15:59 +02:00
}
2020-07-30 13:28:59 +02:00
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
2020-08-01 13:44:12 +02:00
g_bMotherZombie[client] = motherInfect;
2020-07-30 16:53:31 +02:00
if(!motherInfect && IsValidClient(attacker) && !(GetEntProp(attacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue))
2020-08-17 16:13:21 +02:00
{
2020-07-30 13:28:59 +02:00
SetEntProp(attacker, Prop_Send, "m_iAccount", GetEntProp(attacker, Prop_Send, "m_iAccount") + g_cvarInfectionGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(attacker, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for infecting an Human.", g_cvarInfectionGain.IntValue);
}
2020-07-30 13:28:59 +02:00
}
public void OnStartTouch(const char[] sOutput, int iCaller, int iActivator, float fDelay)
{
if (!IsValidClient(iActivator))
return;
if (g_bDisabled[iCaller] || g_bTriggerCooldown)
return;
if (!(ZR_IsClientHuman(iActivator)))
return;
g_bDisabled[iCaller] = true;
g_bTriggerCooldown = true;
float fTriggerCD = GetConVarFloat(FindConVar("sm_trigger_reward_cd"));
CreateTimer(fTriggerCD, ResetTriggerCD);
if(!(GetEntProp(iActivator, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue))
2020-08-17 16:13:21 +02:00
{
SetEntProp(iActivator, Prop_Send, "m_iAccount", GetEntProp(iActivator, Prop_Send, "m_iAccount") + g_cvarHumanTriggerGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(iActivator, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for getting a Trigger.", g_cvarHumanTriggerGain.IntValue);
}
}
public void OnPressed(const char[] sOutput, int iCaller, int iActivator, float fDelay)
{
if(!IsValidClient(iActivator))
return;
if (g_bDisabled[iCaller] || g_bTriggerCooldown)
return;
if (!(ZR_IsClientHuman(iActivator)))
return;
int iParent = INVALID_ENT_REFERENCE;
if ((iParent = GetEntPropEnt(iCaller, Prop_Data, "m_hMoveParent")) != INVALID_ENT_REFERENCE)
{
char sClassname[64];
GetEdictClassname(iParent, sClassname, sizeof(sClassname));
if (strncmp(sClassname, "weapon_", 7, false) == 0)
return;
}
g_bDisabled[iCaller] = true;
g_bTriggerCooldown= true;
float fTriggerCD = GetConVarFloat(FindConVar("sm_trigger_reward_cd"));
CreateTimer(fTriggerCD, ResetTriggerCD);
if(!(GetEntProp(iActivator, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue))
2020-08-17 16:13:21 +02:00
{
SetEntProp(iActivator, Prop_Send, "m_iAccount", GetEntProp(iActivator, Prop_Send, "m_iAccount") + g_cvarHumanTriggerGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(iActivator, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for getting a Trigger.", g_cvarHumanTriggerGain.IntValue);
}
}
public Action ResetTriggerCD(Handle timer)
{
g_bTriggerCooldown = false;
}
2020-07-30 00:15:59 +02:00
public Action EventHook_RoundEnd(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
2020-08-01 13:44:12 +02:00
bool bAwardHumans = (hEvent.GetInt("winner") == CS_TEAM_CT);
bool bAwardZombies = (hEvent.GetInt("winner") == CS_TEAM_T);
2020-07-30 13:28:59 +02:00
2020-07-30 00:15:59 +02:00
for(int i = 1; i <= MaxClients; i++)
{
2020-07-30 13:28:59 +02:00
if(!IsValidClient(i))
continue;
2020-08-01 13:44:12 +02:00
if(GetClientTeam(i) == CS_TEAM_CT && bAwardHumans && !(GetEntProp(i, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue))
2020-07-30 13:28:59 +02:00
{
SetEntProp(i, Prop_Send, "m_iAccount", GetEntProp(i, Prop_Send, "m_iAccount") + g_cvarHumanWinGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(i, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for winning as Human.", g_cvarHumanWinGain.IntValue);
2020-07-30 13:28:59 +02:00
g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
}
else if(GetClientTeam(i) == CS_TEAM_T && bAwardZombies && g_bMotherZombie[i] && !(GetEntProp(i, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue))
2020-08-01 13:44:12 +02:00
{
SetEntProp(i, Prop_Send, "m_iAccount", GetEntProp(i, Prop_Send, "m_iAccount") + g_cvarMotherZombieWinGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(i, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for winning as MotherZombie.", g_cvarMotherZombieWinGain.IntValue);
2020-08-01 13:44:12 +02:00
g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
}
2020-07-30 13:28:59 +02:00
else
{
2020-07-30 00:15:59 +02:00
g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
2020-07-30 13:28:59 +02:00
}
2020-07-30 00:15:59 +02:00
}
}
2020-07-30 16:53:31 +02:00
public Action EventHook_RoundStart(Event hEvent, const char[] sEventName, bool bDontBroadcast)
{
for(int i = 1; i <= MaxClients; i++)
2020-08-01 13:44:12 +02:00
g_bMotherZombie[i] = false;
for(int i = 0; i < 2048; i++)
g_bDisabled[i] = false;
2020-07-30 16:53:31 +02:00
}
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;
2020-07-30 16:53:31 +02:00
if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)
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"));
int attacker = GetClientOfUserId(hEvent.GetInt("attacker"));
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
2020-07-31 16:26:54 +02:00
char sWeapon[16];
hEvent.GetString("weapon", sWeapon, sizeof(sWeapon));
if(!IsValidClient(attacker))
return Plugin_Continue;
if(ZR_IsClientZombie(attacker) && StrEqual(sWeapon, "knife", true) && !(GetEntProp(attacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)) //nemesis kill
2020-08-17 16:13:21 +02:00
{
2020-07-31 16:26:54 +02:00
SetEntProp(attacker, Prop_Send, "m_iAccount", GetEntProp(attacker, Prop_Send, "m_iAccount") + g_cvarInfectionGain.IntValue);
2020-08-17 16:13:21 +02:00
CPrintToChat(attacker, "{cyan}[UNLOZE CashManager] {white}Gained {yellow}$%d{white} for killing an Human.", g_cvarInfectionGain.IntValue);
}
2020-07-31 16:26:54 +02:00
else if(ZR_IsClientZombie(attacker)) // regular infection
2020-08-17 16:13:21 +02:00
{
return Plugin_Continue;
2020-08-17 16:13:21 +02:00
}
int iPacked = (attacker<<16) | (GetEntProp(attacker, Prop_Send, "m_iAccount")&0xFFFF);
RequestFrame(RequestFrame_Callback2, iPacked);
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"));
2020-07-30 13:28:59 +02:00
RequestFrame(RequestFrame_Callback, 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
}
2020-07-30 13:28:59 +02:00
public void RequestFrame_Callback(int client)
{
if(g_iCash[client] >= 0 && g_iCash[client] < g_cvarRoundStartCash.IntValue) //Player is (almost) broke
SetEntProp(client, Prop_Send, "m_iAccount", g_cvarRoundStartCash.IntValue);
else if(g_iCash[client] >= 0 && g_iCash[client] < g_cvarMaxCash.IntValue) //Player isn't broke
2020-07-30 13:28:59 +02:00
SetEntProp(client, Prop_Send, "m_iAccount", g_iCash[client]);
else if(g_iCash[client] >= 0 && g_iCash[client] >= g_cvarMaxCash.IntValue) //Player hit limit
2020-07-30 16:53:31 +02:00
SetEntProp(client, Prop_Send, "m_iAccount", g_cvarMaxCash.IntValue);
2020-07-30 13:28:59 +02:00
}
public void RequestFrame_Callback2(int iPacked)
{
int iOldCash = iPacked&0xFFFF;
int iAttacker = iPacked>>16;
SetEntProp(iAttacker, Prop_Send, "m_iAccount", iOldCash);
}
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
}