Raised This Month: $ Target: $400
 0% 

[TF2] Both max and current health stops adding after taking damage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nursik
Senior Member
Join Date: Jul 2016
Location: In TF2
Old 04-24-2018 , 08:47   [TF2] Both max and current health stops adding after taking damage
Reply With Quote #1

I was making a custom attribute to gain max and current health for backstabs until 11 kills, but the attribute just stops working when you take damage. I can't seem to understand why it happens, but when you go to resupply you can start gaining max health and heal again. The stock below is a TakeDamage SDKHook.

Code:
stock Action:Attribute_SpyGetSouls_OnTakeDamage(victim, &attacker, slot, &Float:damage, &damagetype, Float:damageForce[3], Float:damagePosition[3], damageCustom, &weapon, bool:bBuilding)
{
	if(!IsValidClient(attacker) || !IsValidClient(victim) || slot == -1 || damage <= 0.0) return Plugin_Continue;
	
	if(!m_bHasAttribute[attacker][slot] || !SpyGetSouls[attacker][slot]) return Plugin_Continue;
	
	if(BackstabsForSoulsKills[attacker][slot] > 11)
	{
		BackstabsForSoulsKills[attacker][slot] = 11;
	}
	if(damageCustom == TF_CUSTOM_BACKSTAB && !GetHasBackstabShield(victim) && IsValidClient(attacker))
	{
		BackstabsForSoulsKills[attacker][slot] += 1;
		new Handle:dataPack;
		CreateDataTimer(0.001, Timer_GiveHealth, dataPack);
		WritePackCell(dataPack, attacker);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 1 && IsValidEntity(weapon))
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 25.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] > 1)
	{
		TF2Attrib_RemoveByName(weapon, "max health additive bonus");
		new Handle:dataPack2;
		CreateDataTimer(0.00001, Timer_GiveMaxHealth, dataPack2);
		WritePackCell(dataPack2, attacker);
		WritePackCell(dataPack2, slot);
		WritePackCell(dataPack2, weapon);
	}
	return Plugin_Continue;
}

public Action:Timer_GiveHealth(Handle:timer, Handle: dataPack)
{
	new attacker;
	
	ResetPack(dataPack);
	attacker = ReadPackCell(dataPack);

	TF2_HealPlayer(attacker, 25, true, true);
}

public Action:Timer_GiveMaxHealth(Handle:timer, any: dataPack2)
{
	new attacker, slot, weapon;
	
	ResetPack(dataPack2);
	attacker = ReadPackCell(dataPack2);
	slot = ReadPackCell(dataPack2);
	weapon = ReadPackCell(dataPack2);
	
	if (BackstabsForSoulsKills[attacker][slot] == 2)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 50.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 3)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 75.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 4)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 100.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 5)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 125.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 6)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 150.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 7)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 175.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 8)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 200.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 9)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 225.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 10)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 250.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] == 11)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 275.0);
	}
	if (BackstabsForSoulsKills[attacker][slot] > 11)
	{
		TF2Attrib_SetByName(weapon, "max health additive bonus", 275.0);
		KillTimer(timer);
	}
}
Nursik is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-24-2018 , 12:13   Re: [TF2] Both max and current health stops adding after taking damage
Reply With Quote #2

Attributes are reset when you touch a resupply (if the weapon is reapplied, anyways).

Can't really do any further debugging without a full plugin (or at least a minimal one that shows the same results), but that is definitely not a TakeDamage SDKHook callback (it doesn't have slots, nor a bool for buildings).

If you're doing kills though, I'd recommend doing all your checks in a player_death event.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 04-24-2018 at 12:28.
nosoop is offline
Nursik
Senior Member
Join Date: Jul 2016
Location: In TF2
Old 04-24-2018 , 13:08   Re: [TF2] Both max and current health stops adding after taking damage
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
Attributes are reset when you touch a resupply (if the weapon is reapplied, anyways).

Can't really do any further debugging without a full plugin (or at least a minimal one that shows the same results), but that is definitely not a TakeDamage SDKHook callback (it doesn't have slots, nor a bool for buildings).

If you're doing kills though, I'd recommend doing all your checks in a player_death event.
I know that, that's not the issue. I mean, the knife is supposed to give you max health and heal you for 25 hp for a backstab, but when you take damage, the attribute just stops working until you touch a resupply, die, etc.

The plugin is for CW3. I'm not including slots or bool for buildings, because I'm not uisng those for the attribute.

I found SDKHooks easier to code with. Also, I tried player_death event, but the attribute didn't work at all, even though it compiled with no errors or warnings.

I'll show the whole plugin tomorrow, because it's late for me right now.
Nursik is offline
Reply


Thread Tools
Display Modes

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 16:17.


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