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

How to detect if a player is being healed/standing next to a dispenser in TF2?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jasonfrog
Senior Member
Join Date: Mar 2008
Old 03-18-2013 , 11:52   How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #1

Any ideas on how it might be possible to detect if a player is either being healed by, or standing next to, a dispenser in TF2?
jasonfrog is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 03-19-2013 , 07:38   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #2

Check m_nNumHealers netprop on the player, if it's non-zero, loop through all obj_dispenser entities, filtering them out of they're more than 400(?) Hammer units away.

For a more precise (maybe) check hooking sounds for weapons/dispenser_heal.wav might work. If so, then you could just loop through all players and see who's close enough to it.
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
jasonfrog
Senior Member
Join Date: Mar 2008
Old 03-21-2013 , 15:04   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #3

Thanks for your suggestion, knowing about m_nNumHealers made all the difference.

This is what I ended up doing.
PHP Code:
new healers GetEntProp(clientProp_Send"m_nNumHealers");
if (
healers 0)
{
    
// player is being healed
    
new String:classname[64];
    new 
medics 0;
    
    for (new 
1MAXPLAYERSi++)
    {
        if (
IsValidClient(i))
        {
            
TF2_GetCurrentWeaponClass(iclassnamesizeof(classname));
            if(
StrEqual(classname"CWeaponMedigun"))
            {
                new 
index GetEntPropEnt(iProp_Send"m_hActiveWeapon");
                if(
GetEntProp(indexProp_Send"m_bHealing") == 1)
                {
                    if (
client == GetEntPropEnt(indexProp_Send"m_hHealingTarget"))
                    {
                        
// player is being healed by a medic
                        
medics++;
                    }
                }
            }
        }
    }
    if (
healers medics)
    {
        
// player is being healed by something other than a medic
        
DoStuff(client);
    }
}

stock bool:IsValidClient(client)
{
    if (
client <= || client MaxClients) return false;
    if (!
IsClientInGame(client)) return false;
    if (
IsClientSourceTV(client) || IsClientReplay(client)) return false;
    return 
true;


Last edited by jasonfrog; 03-21-2013 at 15:09.
jasonfrog is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-21-2013 , 16:09   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #4

Quote:
Originally Posted by jasonfrog View Post
Thanks for your suggestion, knowing about m_nNumHealers made all the difference.

This is what I ended up doing.
PHP Code:
new healers GetEntProp(clientProp_Send"m_nNumHealers");
if (
healers 0)
{
    
// player is being healed
    
new String:classname[64];
    new 
medics 0;
    
    for (new 
1MAXPLAYERSi++)
    {
        if (
IsValidClient(i))
        {
            
TF2_GetCurrentWeaponClass(iclassnamesizeof(classname));
            if(
StrEqual(classname"CWeaponMedigun"))
            {
                new 
index GetEntPropEnt(iProp_Send"m_hActiveWeapon");
                if(
GetEntProp(indexProp_Send"m_bHealing") == 1)
                {
                    if (
client == GetEntPropEnt(indexProp_Send"m_hHealingTarget"))
                    {
                        
// player is being healed by a medic
                        
medics++;
                    }
                }
            }
        }
    }
    if (
healers medics)
    {
        
// player is being healed by something other than a medic
        
DoStuff(client);
    }
}

stock bool:IsValidClient(client)
{
    if (
client <= || client MaxClients) return false;
    if (!
IsClientInGame(client)) return false;
    if (
IsClientSourceTV(client) || IsClientReplay(client)) return false;
    return 
true;

TF2_GetCurrentWeaponClass? I don't recall seeing such a function in the tf2 or tf2_stocks includes. Or did you mean GetClientWeapon, which would return "tf_weapon_medigun" not "CWeaponMedigun"?

For that matter, I'm not sure if things like Medicating Melody (Amputator taunt), Mad Milk, Black Box, and other non-Medigun healing methods affect the m_nNumHealers count.

Edit: Oh, and you seem to have forgotten to check if a player is on BLU or RED as opposed to Spectator or Unassigned.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-21-2013 at 16:12.
Powerlord is offline
jasonfrog
Senior Member
Join Date: Mar 2008
Old 03-21-2013 , 16:45   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #5

Ah yes, sorry I forgot include the stock I was using in the code above.
PHP Code:
stock TF2_GetCurrentWeaponClass(clientString:name[], maxlength)
{
    if( 
client )
    {
        new 
index GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if (
index 0)
            
GetEntityNetClass(indexnamemaxlength);
    }

I didn't check for team, because, for example, a red medic could be healing a blue sniper.

Good point about the other items.

Last edited by jasonfrog; 03-21-2013 at 16:46.
jasonfrog is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-21-2013 , 16:53   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #6

Quote:
Originally Posted by jasonfrog View Post
Ah yes, sorry I forgot include the stock I was using in the code above.
PHP Code:
stock TF2_GetCurrentWeaponClass(clientString:name[], maxlength)
{
    if( 
client )
    {
        new 
index GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if (
index 0)
            
GetEntityNetClass(indexnamemaxlength);
    }

I didn't check for team, because, for example, a red medic could be healing a blue sniper.

Good point about the other items.
Just check that the team is > _:TFTeam_Spectator
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-22-2013 , 06:23   Re: How to detect if a player is being healed/standing next to a dispenser in TF2?
Reply With Quote #7

Do any of the events work? player_healed would be great if it did.

player_healed
Name: player_healed
Structure:
short patient
short healer
short amount

player_healedbymedic
Name: player_healedbymedic
Structure:
byte medic

player_healonhit
Name: player_healonhit
Structure:
short amount
byte entindex
friagram 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 14:05.


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