HL2MP player_hurt damage dealt/attacker weapon/hitgroup?

Please post any questions about developing your plugin here. Please use the search function before posting!
statik
Junior Member
Posts: 5
Joined: Fri Feb 19, 2016 7:33 am

HL2MP player_hurt damage dealt/attacker weapon/hitgroup?

Postby statik » Wed Feb 24, 2016 9:06 am

Hello,

Code: Select all

@Event('player_hurt')
def on_player_hurt(e):
    print(e.variables.as_dict())


Shows me:
{'userid': 2, 'health': 87, 'attacker': 2, 'priority': 5}

Which seems sparse. Is there more I'm missing? I would like to also get the victim's health/armor lost, their hitgroup, and the attacker's weapon. I saw someone else's code where they were getting the requested info, but it was a PreEvent (which did not seem to trigger on HL2MP at all), and also I'm guessing was aimed at a different game.

Is there any other way to get this information via SP for HL2MP on player_hurt? Sadly, most plugin interfaces (and admin addons) have seemed to ignore this game a lot throughout its life, and i"m sure it will be even worse now that it is getting very old. I remember on EventScripts, I eventually was able to crudely detect headshots with the magnum by measuring the damage dealt if the attacker's weapon was the 357, but I have not been able to work out even that much yet with SP....

...OR is there a way to modify the damage output of the hitscan weapons? My ultimate goal here (the reason for asking these questions) is to reduce the headshot damage of the shotgun. Looking through the module reference, I didn't see anything promising, so I was going to just detect the headshot, then give the victim back a certain percetage of the damage dealt via PreEvent, but again: not having much success.

Any help is appreciated!

Thanks,
Statik

EDIT: My secondary goal (after I figure out the above) is to recreate Keeper's streak sound plugin for HL2MP. Can anyone clue me in on additional challenges I may face, or is SP even capable in its current state?

EDIT2: Also, I tried creating Player objects for each of the attacker and userid indexes, but the weapon indexes seem nonsensical. The primary and secondary are always the same, and they change from map to map...I'm very confuzzled D:
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Feb 24, 2016 12:24 pm

Unfortunately, those event variables are not provided in HL2MP. The best way to do what you are looking to do is to use an OnTakeDamage pre-hook and modify the damage dealt there. This is untested, so let us know if it works:

Syntax: Select all

from entities import TakeDamageInfo
from entities.helpers import index_from_inthandle
from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
from memory import make_object
from players.constants import HitGroup
from players.entity import Player
from weapons.entity import Weapon


@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(stack_data):
# Was this a headshot?
victim = make_object(Player, stack_data[0])
if victim.hitgroup != HitGroup.HEADSHOT:
return

info = make_object(TakeDamageInfo, stack_data[1])

# Was a projectile used?
# The attacker and inflictor are the same if a non-projectile is used
if info.attacker != info.inflictor:
return

# Was a shotgun used?
attacker = Player(info.attacker)
weapon = Weapon(index_from_inthandle(attacker.active_weapon))
if weapon.classname != 'weapon_shotgun':
return

# Modify the damage before returning
info.damage -= 40


As to your question in your first edit, of course SP is fully capable in its current state. There isn't a whole lot SP cannot do. And, if SP cannot do it, it is because of the limitations within the game/engine itself.
Image
statik
Junior Member
Posts: 5
Joined: Fri Feb 19, 2016 7:33 am

Postby statik » Wed Feb 24, 2016 1:04 pm

Thanks for the reply! I will give that code a try asap and will post any changes I may need to make to make it work.... It definitely points me in the right direction.

Can you (or anyone) recommend some core concepts I should learn about Source engine? I have a fairly strong knowledge, because I've dabbled in Eventscripts as well as mapping, but getting down to the levels of hooks and whatnot, I get lost. I will most certainly do some googling on my own but if anyone knows some good resources or can give me a good place to start, that would be great too!

Thanks,
Statik`
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Feb 24, 2016 1:33 pm

You might check out this thread:
http://forums.sourcepython.com/showthread.php?972

It shows how people add data to SP's data for things like entity hooks. That should also help you get started in knowing what entity hooks are currently available. If you find anything HL2MP specific you wish for us to add, feel free to post it here on the forums or as a pull request to our GitHub repository. We would prefer the latter of the 2, but it is ok to use the former until you get familiar with GitHub and pull requests.

Also, click the Wiki icon along the top bar of the forums to take you to our Wiki. It isn't complete, but it should help get you started on knowing what is available to you from our plugin's perspective.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 17 guests