Raised This Month: $ Target: $400
 0% 

[TF2] Getting a weapon's index during player_hurt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-27-2013 , 20:48   [TF2] Getting a weapon's index during player_hurt
Reply With Quote #1

PHP Code:
new wepindex = (weapon MaxClients && IsValidEdict(weapon) ? GetEntProp(weaponProp_Send"m_iItemDefinitionIndex"):-1);
    new 
sydamage = (wepindex == 203) ? RoundToCeil(float(damage)/2.0) : damage;   //Sydney Sleeper generates half the usual rage to Hale

    
HaleHealth -= damage;
    
HaleRage += sydamage;

    
Damage[attacker] += damage
This is during player_hurt.

What effects does this have?

Simple having

PHP Code:
new wepindex = (weapon MaxClients && IsValidEdict(weapon) ? GetEntProp(weaponProp_Send"m_iItemDefinitionIndex"):-1); 
In that event, it makes it so that all "non-default" weapons do absolutely no damage. Even if I comment out sydamage and change HaleRage += sydamage; to += damage;

What do I mean by non-default weapons?

https://wiki.alliedmods.net/Team_For...nition_Indexes

These do damage properly which is properly tracked by the Hale plugin accumulatively:
tf_weapon_sniperrifle
tf_weapon_rocketlauncher
tf_weapon_scattergun

These appear to do damage via TF2 hitmarkers above the enemy's head, but for some reason their damage is not tracked by the Hale plugin:
tf_weapon_compound_bow
tf_weapon_sniperrifle_decap
tf_weapon_rocketlauncher_directhit
tf_weapon_particle_cannon
tf_weapon_handgun_scout_primary
tf_weapon_soda_popper

Simply commenting out the new wepindex = line fixes all the damage tracking issues.

Furthermore, in OnTakeDamage, and everywhere else in the Hale plugin, it seems to be no problem to get a weapon's index with the exact same code.

PHP Code:
new buffindex = (IsValidEntity(buffweapon) && buffweapon MaxClients GetEntProp(buffweaponProp_Send"m_iItemDefinitionIndex"):-1);

new 
wepindie = (medigun MaxClients && IsValidEdict(medigun) ? GetEntProp(medigunProp_Send"m_iItemDefinitionIndex"):-1);

new 
wepindex = (IsValidEntity(weapon) && weapon MaxClients GetEntProp(weaponProp_Send"m_iItemDefinitionIndex"):-1); 
^This is all on separate lines far apart from each other of course.


Why does simply declaring that variable in player_hurt, break so many [nondefault] weapons, even if it isn't used at all?

Not to mention, if I shoot a rocket from something such as the direct hit or cow mangler, but then (before the rocket makes contact) switch to my melee or shotgun (which are tf_weapon_shovel and tf_weapon_shotgun_soldier respectively which makes them "defaults", then the rocket that was shot by the DH/CM does register its damage properly by the Hale plugin. Only having the weapons out makes them not register. (Because your active weapon is a nondefault, whereas if you switch to the shotgun/escape plan/market gardener, you just switched to defaults).



As a side note, why can player_hurt detect (custom == TF_CUSTOM_PLASMA) and act upon it properly, whereas OnTakeDamage cannot detect (damagecustom == TF_CUSTOM_PLASMA)? OnTakeDamage is able to detect TF_CUSTOM_BACKSTAB, TF_CUSTOM_BOOTS_STOMP, TF_CUSTOM_TELEFRAG, TF_CUSTOM_HEADSHOT -- all just fine with damagecustom. But not TF_CUSTOM_PLASMA? What's the issue here?

It also can't detect TF_CUSTOM_PLASMA_CHARGED which is the cow mangler charge shot. (TF_CUSTOM_PLASMA being an uncharged shot).

I mean, I could probably change the damage bonus I wanted to give charge shots, over to player_hurt, but idk, what gives? Why dis happen?

Edit: It may a not be that it can't detect "plasma", but that it cannot detect that the cow mangler's index is "441". In which case... I really dunno what's wrong. It can detect other weapons by index just fine, such as the short circuit check directly below it.
__________________

Last edited by Chdata; 11-27-2013 at 20:54.
Chdata is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 11-27-2013 , 22:29   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #2

Well from what I can see, you left out the damage definition line. So I can't tell you what is doing that. It appears the problem lies elsewhere. Can you supply more code?
NIGathan is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-27-2013 , 23:33   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #3

Here is everything that should be relevant:

(This is condensed from saxtonhale.sp)

PHP Code:
new Hale = -1;
new 
HaleHealth;
new 
HaleRage;
new 
RageDMG 1900;
new 
Damage[MAXPLAYERS 1];
new 
Handle:cvarRageDMG;

//The variables above are set/changed in many other places in saxtonhale.sp and work fine.

public OnPluginStart()
{
    
HookEvent("player_hurt"event_hurtEventHookMode_Pre);
}

public 
Action:event_hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!
Enabled) return Plugin_Continue;

    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
damage GetEventInt(event"damageamount");
    new 
custom GetEventInt(event"custom");
    new 
weapon GetEventInt(event"weaponid");

    if (
client != Hale || !IsValidClient(attacker) || !IsValidClient(client) || client == attacker || custom == TF_CUSTOM_BACKSTAB)
    {
        return 
Plugin_Continue;
    }

    if (
custom == TF_CUSTOM_TELEFRAGdamage = (IsPlayerAlive(attacker) ? 9001:1);

    if (
GetEventBool(event"minicrit") && GetEventBool(event"allseecrit"))
    {
        
SetEventBool(event"allseecrit"false);
    }

    
//new wepindex = (weapon > MaxClients && IsValidEdict(weapon) ? GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"):-1);
    //new sydamage = (wepindex == 203) ? RoundToCeil(float(damage)/2.0) : damage;   //Sydney Sleeper generates half the usual rage to Hale

    
HaleHealth -= damage;
    
HaleRage += damage;

    if (
custom == TF_CUSTOM_TELEFRAGSetEventInt(event"damageamount"damage);

    
Damage[attacker] += damage;

    new 
healers[MAXPLAYERS];
    new 
healercount 0;

    for (new 
1<= MaxClientsi++)
    {
        if (
IsValidClient(i) && IsPlayerAlive(i) && (GetHealingTarget(i) == attacker))
        {
            
healers[healercount] = i;
            
healercount++;
        }
    }

    for (new 
0healercounti++)
    {
        if (
IsValidClient(healers[i]) && IsPlayerAlive(healers[i]))
        {
            if (
damage 10 || uberTarget[healers[i]] == attacker)
            {
                
Damage[healers[i]] += damage;
            }
            else
            {
                
Damage[healers[i]] += damage / (healercount 1);
            }
        }
    }

    if (
HaleRage RageDMG)
    {
        
HaleRage RageDMG;
    }

    return 
Plugin_Continue;

There is no perceivable way that the damage variable is the issue here. It all works fine if I don't define wepindex.

Literally, if I uncomment the line that defines wepindex, weapon damage breaks in the manner that I mentioned, even if wepindex isn't even used at all anywhere -- it only has to be defined.
__________________

Last edited by Chdata; 11-27-2013 at 23:45.
Chdata is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 11-28-2013 , 01:03   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #4

Try returning Plugin_Changed; after changing anything with the SetEvent* functions.

Also, try adding some PrintToServer() debug printing the value of wepindex, maybe it isn't functioning properly

Last edited by NIGathan; 11-28-2013 at 01:11.
NIGathan is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-28-2013 , 01:57   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #5

I doubt it's Plugin_Changed, as if (custom == TF_CUSTOM_TELEFRAG) SetEventInt(event, "damageamount", damage); still works regardless.
__________________
Chdata is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-28-2013 , 02:10   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #6

Events are just reporting things that have already happened on the server. In other words, changing the damage in player_hurt does absolutely nothing and instead just lies to other plugins as to how much damage happened.

If you want to change the amount of damage done, you must do it in an SDKHooks OnTakeDamage hook. Which is what VSH does.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 11-28-2013 at 02:12.
Powerlord is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-28-2013 , 02:30   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #7

Well, the default VSH mod actually does some really weird stuff with telefrags in OnTakeDamage.

It'll set your damage to 15 if hale's hp is > 9001 and set it to Hale's hp + 80 if it's less than 9001.

And then in player_hurt it tells the plugin that the damage was 9001 anyway which overrides the ontakedamage thing in the case of VSH. I got rid of the ontakedamage crap in vsh for my server though and just made the ontakedamage do a static 9001 anyway. That reminds me, I need to make it account for minicrits. A minicrit telefrag can probably still KO Hales with less than 12000 hp and more than 9001. Though I suppose that was the purpose of the "weird interactions" VSH had for telefrags in OnTakeDamage.

The thing is, changing damage in player_hurt or lying to other plugins doesn't explain why trying to get the index of weapons makes it so the damage of various weapons more or less breaks.

Anyway,

CPrintToChatAll("%i",wepindex); (don't ask why I used printtochat ;o)

For the broken weapons, it doesn't say anything in chat; doesn't activate.

For weapons that do damage properly, it prints -1.

So uh... is it possible to get the item index of weapons during player_hurt?
__________________

Last edited by Chdata; 11-28-2013 at 02:36.
Chdata is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 11-28-2013 , 02:43   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #8

Try this instead:
Code:
new wepindex = (weapon > MaxClients && IsValidEntity(weapon) ? GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex"):-1);
NIGathan is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-28-2013 , 02:52   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #9

That didn't change it (aside from crashing the server), but I just noticed that this was producing error logs the entire time.

PHP Code:
L 11/28/2013 02:28:31: [SMNative "GetEntProp" reportedProperty "m_iItemDefinitionIndex" not found (entity 65/info_particle_system)
L 11/28/2013 02:28:31: [SMDisplaying call stack trace for plugin "saxtonhale.smx":
L 11/28/2013 02:28:31: [SM]   [0]  Line 6171saxtonhale.sp::event_hurt() 
Line 6171 being

PHP Code:
new wepindex = (weapon MaxClients && IsValidEntity(weapon) ? GetEntProp(weaponProp_Send"m_iItemDefinitionIndex"):-1); 
__________________

Last edited by Chdata; 11-28-2013 at 02:54.
Chdata is offline
rswallen
SourceMod Donor
Join Date: Jun 2013
Location: 127.0.0.1
Old 11-28-2013 , 03:22   Re: [TF2] Getting a weapon's index during player_hurt
Reply With Quote #10

weaponid is not an entity in player_hurt.
it identifies the type of weapon (EG TF_WEAPON_REVOLVER).
the full list of weaponids can be found in tf2_stocks.inc
rswallen 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:37.


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