Raised This Month: $51 Target: $400
 12% 

Solved [CS:GO] trying to give health per kill


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 07-21-2019 , 20:40   [CS:GO] trying to give health per kill
Reply With Quote #1

I was searching the web for a base to write my plugin on and I found this piece of code:
Code:
public Action OnPlayerDeath(Handle event, char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "attacker"));
	int dead = GetClientOfUserId(GetEventInt(event, "userid"));
	if (GetConVarBool(g_Cvar_HealthRegenEnabled))
	{
		if (HasClientFlag(client, ADMFLAG_RESERVATION))
		{
			int OldHealth = GetEntProp(client, Prop_Send, "m_iHealth", 4, 0);
			if (dead != client)
			{
				if (GetClientTeam(client) > 1)
				{				
					g_iHealthRegenedQuantity = GetConVarInt(g_Cvar_HealthRegenedQuantity);
					g_iMaxHealth = GetConVarInt(g_Cvar_MaxHealthQuantity);
					if (g_iHealthRegenedQuantity + OldHealth > g_iMaxHealth)
					{	
						SetEntProp(client, Prop_Send, "m_iHealth", g_iMaxHealth, 4, 0);
					}
					else
					{
						SetEntProp(client, Prop_Send, "m_iHealth", OldHealth + g_iHealthRegenedQuantity, 4, 0);
					}
				}
			}
		}
	}
}
After editing it to my needs, the code looked like this:

Code:
public Action OnPlayerDeath(Handle event, char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "attacker"));
	int dead = GetClientOfUserId(GetEventInt(event, "userid"));
	if (CheckCommandAccess(client, "", ADMFLAG_NEEDED, true))
	{
		int OldHealth = GetEntProp(client, Prop_Send, "m_iHealth", 4, 0);
		if (dead != client)
		{
			if (GetClientTeam(client) > 1)
			{				
				int g_iHealthRegenedQuantity = 10;
				int g_iMaxHealth = 150;
				if (g_iHealthRegenedQuantity + OldHealth > g_iMaxHealth)
				{	
					SetEntProp(client, Prop_Send, "m_iHealth", g_iMaxHealth, 4, 0);
				}
				else
				{
					SetEntProp(client, Prop_Send, "m_iHealth", (OldHealth + g_iHealthRegenedQuantity), 4, 0);
				}
			}
		}
	}
}
My problem is that when someone is killed, the attacker does not get more 10 HP as intended.
Basically, this is the scheme:
- When someone is killed, the attacker gets +10 HP;
- The max health should be 150;

Can anyone explain what am I doing wrong?

Last edited by JoaoRodrigoGamer; 07-22-2019 at 08:57. Reason: Solved
JoaoRodrigoGamer is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode