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

[TF2] Heal players, optionally with green numerical popups


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 10-28-2015 , 10:25   [TF2] Heal players, optionally with green numerical popups
Reply With Quote #1

Here's just a set of stocks I use all the time for anything related to healing players.

PHP Code:
/*
    Example usage: Blutsauger heals 50 hp via an attribute.
    But you want it to add to overheal via AddPlayerHealth because the attribute doesn't do so.
    You can't just call AddPlayerHealth when he's less than MaxHealth because you'd see 10hp +50 +50 = 110 instead of stopping at 60
    You can't just check if his health is >= MaxHealth because if it's a scout at 100/125 hp, in that scenario he only heals 25 hp instead of 50, before being able to gain overheal.

    In the 100/125 scenario, this will return true to say we should use AddPlayerHealth. AddPlayerHealth will set the player's hp to 150/125 and thus prevent the attribute from doing anything.
    ... In OnTakeDamage. Dunno about player_hurt... UNTESTED


    Edit: This is now technically useless due to the ShowHealthGain() function I added - you can just remove the attribute, and always use AddPlayerHealth for every hit
*/
stock bool:ReadyToOverheal(iClientiAdd 0bool:bAdd false)
{
    return (
bAdd) ? ((TF2_GetMaxHealth(iClient) - GetClientHealth(iClient)) < iAdd) : (GetClientHealth(iClient) >= TF2_GetMaxHealth(iClient));
}

/*
    Adds health to a player until they reach a certain amount of overheal.

    Does not go above the overheal amount.

    Defaults to normal medigun overheal amount.
*/
stock AddPlayerHealth(iClientiAddFloat:flOverheal 1.5bAdditive falsebool:bEvent false)
{
    new 
iHealth GetClientHealth(iClient);
    new 
iNewHealth iHealth iAdd;
    new 
iMax bAdditive ? (TF2_GetMaxHealth(iClient) + RoundFloat(flOverheal)) : TF2_GetMaxOverHeal(iClientflOverheal);
    if (
iHealth iMax)
    {
        
iNewHealth min(iNewHealthiMax);
        if (
bEvent)
        {
            
ShowHealthGain(iClientiNewHealth-iHealth);
        }
        
SetEntityHealth(iClientiNewHealth);
    }
}

stock ShowHealthGain(iPatientiHealthiHealer = -1)
{
    new 
iUserId GetClientUserId(iPatient);
    new 
Handle:hEvent CreateEvent("player_healed"true);
    
SetEventBool(hEvent"sourcemod"true);
    
SetEventInt(hEvent"patient"iUserId);
    
SetEventInt(hEvent"healer"IsValidClient(iHealer) ? GetClientUserId(iHealer) : iUserId);
    
SetEventInt(hEvent"amount"iHealth);
    
FireEvent(hEvent);

    
hEvent CreateEvent("player_healonhit"true);
    
SetEventBool(hEvent"sourcemod"true);
    
SetEventInt(hEvent"amount"iHealth);
    
SetEventInt(hEvent"entindex"iPatient);
    
FireEvent(hEvent);
}

stock TF2_GetMaxHealth(iClient)
{
    new 
maxhealth GetEntProp(GetPlayerResourceEntity(), Prop_Send"m_iMaxHealth"_iClient);
    return ((
maxhealth == -|| maxhealth == 80896) ? GetEntProp(iClientProp_Data"m_iMaxHealth") : maxhealth);
}

// Returns a client's max health if fully overhealed
stock TF2_GetMaxOverHeal(iClientFloat:flOverHeal 1.5// Quick-Fix would be 1.25
{
    return 
RoundFloat(float(TF2_GetMaxHealth(iClient)) * flOverHeal);
}

// Returns the amount of overheal a client can receive
stock TF2_GetOverHeal(iClientFloat:flOverHeal 1.5)
{
    return 
RoundFloat(float(TF2_GetMaxHealth(iClient)) * (flOverHeal-1.0));
}

// SetEntityHealth works the same
stock TF2_SetHealth(iClientNewHealth)
{
    
SetEntProp(iClientProp_Send"m_iHealth"NewHealth);
    
SetEntProp(iClientProp_Data"m_iHealth"NewHealth);

__________________

Last edited by Chdata; 10-28-2015 at 10:37.
Chdata 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 00:53.


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