273 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			SourcePawn
		
	
	
	
	
	
			
		
		
	
	
			273 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			SourcePawn
		
	
	
	
	
	
| #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
 | |
| 
 | |
| ConVar g_cvarInfectionGain;
 | |
| ConVar g_cvarHumanWinGain;
 | |
| ConVar g_cvarRoundStartGain;
 | |
| ConVar g_cvarMaxCash;
 | |
| 
 | |
| bool g_bZRLoaded;
 | |
| bool g_bMapEnd;
 | |
| 
 | |
| int g_iCash[MAXPLAYERS + 1];
 | |
| int g_iCashReconnect[256];
 | |
| int g_iSteamID[256];
 | |
| 
 | |
| public Plugin myinfo =
 | |
| {
 | |
| 	name = "Cash Manager",
 | |
| 	author = "Obus + Dogan",
 | |
| 	description = "Manage Cash with additional gains and limits",
 | |
| 	version = "1.1.0",
 | |
| 	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");
 | |
| 	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.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;
 | |
| }
 | |
| 
 | |
| public void OnAllPluginsLoaded()
 | |
| {
 | |
| 	g_bZRLoaded = LibraryExists("zombiereloaded");
 | |
| }
 | |
| 
 | |
| public void OnLibraryAdded(const char[] sName)
 | |
| {
 | |
| 	if(strcmp(sName, "zombiereloaded", false) == 0)
 | |
| 		g_bZRLoaded = true;
 | |
| }
 | |
| 
 | |
| public void OnLibraryRemoved(const char[] sName)
 | |
| {
 | |
| 	if(strcmp(sName, "zombiereloaded", false) == 0)
 | |
| 		g_bZRLoaded = false;
 | |
| }
 | |
| 
 | |
| public void OnMapStart()
 | |
| {
 | |
| 	for(int i = 0; i < 256; i++)
 | |
| 	{
 | |
| 		g_iSteamID[i] = 0;
 | |
| 		g_iCashReconnect[i] = 0;
 | |
| 	}
 | |
| 
 | |
| 	for(int i = 1; i <= MaxClients; i++)
 | |
| 	{
 | |
| 		g_iCash[i] = 0;
 | |
| 	}
 | |
| 
 | |
| 	g_bMapEnd = false;
 | |
| }
 | |
| 
 | |
| public void OnMapEnd()
 | |
| {
 | |
| 	g_bMapEnd = true;
 | |
| }
 | |
| 
 | |
| public void OnClientPutInServer(int client)
 | |
| {
 | |
| 	if(IsFakeClient(client) || g_bMapEnd)
 | |
| 		return;
 | |
| 
 | |
| 	int iSteamID = GetSteamAccountID(client);
 | |
| 
 | |
| 	for(int i = 0; i < 256; i++)
 | |
| 	{
 | |
| 		if(iSteamID == g_iSteamID[i])
 | |
| 		{
 | |
| 			g_iCash[client] = g_iCashReconnect[i];
 | |
| 			CreateTimer(3.0, MessageReconnect, client);
 | |
| 			break;
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 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;
 | |
| }
 | |
| 
 | |
| public void OnClientDisconnect(int client)
 | |
| {
 | |
| 	if(IsFakeClient(client) || !IsClientInGame(client))
 | |
| 		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] = 0;
 | |
| }
 | |
| 
 | |
| public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
 | |
| {
 | |
| 	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);
 | |
| }
 | |
| 
 | |
| 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))
 | |
| 			continue;
 | |
| 
 | |
| 		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");
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			g_iCash[i] = GetEntProp(i, Prop_Send, "m_iAccount");
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 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)
 | |
| 		return Plugin_Continue;
 | |
| 
 | |
| 	int iAttacker = GetClientOfUserId(hEvent.GetInt("attacker"));
 | |
| 
 | |
| 	if(!IsValidClient(iAttacker) || !ZR_IsClientHuman(iAttacker))
 | |
| 		return Plugin_Continue;
 | |
| 
 | |
| 	int iVictim = GetClientOfUserId(hEvent.GetInt("userid"));
 | |
| 
 | |
| 	if(!IsValidClient(iVictim) || !ZR_IsClientZombie(iVictim))
 | |
| 		return Plugin_Continue;
 | |
| 
 | |
| 	char sWeapon[16];
 | |
| 
 | |
| 	hEvent.GetString("weapon", sWeapon, sizeof(sWeapon));
 | |
| 
 | |
| 	if(!strncmp(sWeapon, "knife", 5))
 | |
| 		return Plugin_Continue;
 | |
| 
 | |
| 	if(GetEntProp(iAttacker, Prop_Send, "m_iAccount") >= g_cvarMaxCash.IntValue)
 | |
| 		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)
 | |
| {
 | |
| 	int client = GetClientOfUserId(hEvent.GetInt("userid"));
 | |
| 	int attacker = GetClientOfUserId(hEvent.GetInt("attacker"));
 | |
| 
 | |
| 	g_iCash[client] = GetEntProp(client, Prop_Send, "m_iAccount");
 | |
| 
 | |
| 	if (!IsValidClient(attacker) || !ZR_IsClientHuman(attacker))
 | |
| 		return Plugin_Continue;
 | |
| 
 | |
| 	int iPacked = (attacker<<16) | (GetEntProp(attacker, Prop_Send, "m_iAccount")&0xFFFF);
 | |
| 
 | |
| 	RequestFrame(RequestFrame_Callback2, iPacked);
 | |
| 
 | |
| 	return Plugin_Continue;
 | |
| }
 | |
| 
 | |
| public Action EventHook_PlayerSpawn(Event hEvent, const char[] sEventName, bool bDontBroadcast)
 | |
| {
 | |
| 	int client = GetClientOfUserId(hEvent.GetInt("userid"));
 | |
| 
 | |
| 	RequestFrame(RequestFrame_Callback, client);
 | |
| 
 | |
| 	return Plugin_Continue;
 | |
| }
 | |
| 
 | |
| public void RequestFrame_Callback(int client)
 | |
| {
 | |
| 	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)
 | |
| {
 | |
| 	int iOldCash = iPacked&0xFFFF;
 | |
| 	int iAttacker = iPacked>>16;
 | |
| 
 | |
| 	SetEntProp(iAttacker, Prop_Send, "m_iAccount", iOldCash);
 | |
| }
 | |
| 
 | |
| stock bool IsValidClient(int client)
 | |
| {
 | |
| 	return (client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client));
 | |
| } |