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

[TF2] %Lifesteal problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rcki
Junior Member
Join Date: Oct 2015
Old 07-03-2018 , 18:30   [TF2] %Lifesteal problems
Reply With Quote #1

So, I have this small problem with my % lifesteal code:
I want it to heal 10% of damage done, with a maximum overheal of 250 hp. The code works if I want to heal a flat amount (for example 10 health per hit), but for some reason it heals me instantly to max overheal if I try to heal a certain % of damage dealt.
Am I just stupid or what is wrong with this?

Code:
public OnClientPutInServer(client) {
	SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(client, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3], damagecustom){
	new heal = damage * 0.1;
	AddPlayerHealth(attacker, heal, 250, true);
	return Plugin_Continue;
}

stock AddPlayerHealth(iClient, iAdd, iOverheal = 0, bStaticMax = false)
{
	new iHealth = GetClientHealth(iClient);
	new iNewHealth = iHealth + iAdd;
	new iMax = bStaticMax ? iOverheal : GetEntProp(iClient, Prop_Data, "m_iMaxHealth") + iOverheal;
	if (iHealth < iMax)
	{
		iNewHealth = min(iNewHealth, iMax);
		SetEntityHealth(iClient, iNewHealth);
	}
}
(This is not the full plugin, I have taken away the parts that do not affect this certain behaviour)
Sorry for being a noob and thanks in advance !
Rcki is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-03-2018 , 19:50   Re: [TF2] %Lifesteal problems
Reply With Quote #2

First thing I noticed out of place "new heal = damage * 0.1;" Should be Float.
mug1wara is offline
Rcki
Junior Member
Join Date: Oct 2015
Old 07-03-2018 , 20:50   Re: [TF2] %Lifesteal problems
Reply With Quote #3

You mean like: new Float:heal? Tried it out, didn't make a difference. I also tried directly healing the damage dealt, which also resulted in the same problem. Like this:
Code:
public Action:OnTakeDamage(client, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3], damagecustom){
	//new Float:heal = damage * 0.1;
	AddPlayerHealth(attacker, damage, 250, true);
	return Plugin_Continue;
}
(I dealt 65 damage, which means I should be getting healed for 65 health, instead I got instantly healed up to 250 health.)
Any ideas?
Rcki is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-04-2018 , 01:11   Re: [TF2] %Lifesteal problems
Reply With Quote #4

The damage parameter in OnTakeDamage() is a Float.

also, eww old syntax
__________________

Last edited by ddhoward; 07-04-2018 at 01:12.
ddhoward is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 07-04-2018 , 01:21   Re: [TF2] %Lifesteal problems
Reply With Quote #5

The issue is obviously coming from the stock function. Since you pass it the correct values, it must be interpreting it incorrectly. GetClientHealth() undoubtedly works and your logic for setting a maximum health seems correct. iNewHealth must initially be an unexpected value which I can only assume to be the fault of iAdd. It is probably being interpreted incorrectly. (Maybe the data passed is being read as an integer rather than a float and changing the numerical value) Try changing to this:

Code:
stock AddPlayerHealth(iClient, Float:iAdd, Float:iOverheal = 0.0, bStaticMax = false)
{
	new Float:iHealth = float(GetClientHealth(iClient));
	new Float:iNewHealth = iHealth + iAdd;
	new Float:iMax = bStaticMax ? iOverheal : GetEntProp(iClient, Prop_Data, "m_iMaxHealth") + iOverheal;
	if (iHealth < iMax)
	{
		iNewHealth = min(iNewHealth, iMax);
		SetEntityHealth(iClient, iNewHealth);
	}
}

Last edited by thecount; 07-04-2018 at 01:22.
thecount is offline
Rcki
Junior Member
Join Date: Oct 2015
Old 07-04-2018 , 08:18   Re: [TF2] %Lifesteal problems
Reply With Quote #6

Quote:
Originally Posted by ddhoward View Post
The damage parameter in OnTakeDamage() is a Float.

also, eww old syntax
The syntax might be old because I started this plugin back in 2013 or something. I had a long break from sourcepawn coding since then.

Quote:
Originally Posted by thecount View Post
The issue is obviously coming from the stock function. Since you pass it the correct values, it must be interpreting it incorrectly. GetClientHealth() undoubtedly works and your logic for setting a maximum health seems correct. iNewHealth must initially be an unexpected value which I can only assume to be the fault of iAdd. It is probably being interpreted incorrectly. (Maybe the data passed is being read as an integer rather than a float and changing the numerical value) Try changing to this:

Code:
stock AddPlayerHealth(iClient, Float:iAdd, Float:iOverheal = 0.0, bStaticMax = false)
{
	new Float:iHealth = float(GetClientHealth(iClient));
	new Float:iNewHealth = iHealth + iAdd;
	new Float:iMax = bStaticMax ? iOverheal : GetEntProp(iClient, Prop_Data, "m_iMaxHealth") + iOverheal;
	if (iHealth < iMax)
	{
		iNewHealth = min(iNewHealth, iMax);
		SetEntityHealth(iClient, iNewHealth);
	}
}
Well, I tried and now the function doesn't heal at all (Not even with a flat value, or a flat float). Hmmm, it doesn't seem to work with Floats at all. This is getting really problematic.
Rcki is offline
Reply



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 10:52.


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