AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] Both max and current health stops adding after taking damage (https://forums.alliedmods.net/showthread.php?t=307041)

Nursik 04-24-2018 08:47

[TF2] Both max and current health stops adding after taking damage
 
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);
        }
}


nosoop 04-24-2018 12:13

Re: [TF2] Both max and current health stops adding after taking damage
 
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.

Nursik 04-24-2018 13:08

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

Originally Posted by nosoop (Post 2589178)
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.


All times are GMT -4. The time now is 11:21.

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