ULX

Author Topic: Identifying the weapon dealing damage  (Read 2075 times)

0 Members and 1 Guest are viewing this topic.

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Identifying the weapon dealing damage
« on: February 02, 2015, 12:06:13 PM »
I kinda remember this from my TFC days, but was hoping perhaps things had improved a bit.  Is there a straightforward (or not so straightforward) way of identifying what weapon and mode (primary or secondary) is responsible for non-lethal damage?  It looks like the inflictor value within EntityTakeDamage rarely shows the actual weapon, but rather the player.

I realize I could identify what weapon the player had currently active and try to attack the problem that way, but was hoping for something a little more clean.

Thanks,
M

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Identifying the weapon dealing damage
« Reply #1 on: February 02, 2015, 04:05:01 PM »
Not sure there's really any clean way, but, I've not done gamemode coding either.
Found this - http://wiki.garrysmod.com/page/Category:CTakeDamageInfo regarding the object passed to most of the damage hooks.
Perhaps something more could be gleaned from it. See also GetDamageType and IsDamageType (as listed from that page)

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Identifying the weapon dealing damage
« Reply #2 on: February 03, 2015, 07:29:42 AM »
Thanks.  Yeah, CTakeDamageInfo generally returns the player both as attacker and inflictor unless it's a thrown weapon. DamageType is a little too generic to ID the specific weapon  (for example, was it a m9k spas12, and if so was it from +attack1 or +attack2).

For context, what I'm trying to do is build a generic damage modifier addon, so that admins can modify over or underpowered weapons without having to edit the underlying swep code. (Could even be extended to allow different damage modifiers for specific teams).

Classic example: the glaive, which deals 5000 points of damage. Totally OP, and what I envision is being able to tell the damage modifier (DamMod) to "adjust swep_glaive to an absolute 500 points of damage per attack".    Seems easier to do this at the time damage is inflicted, except for the fact that I can't actually ID the weapon unless the attack resulted in a death.

« Last Edit: February 03, 2015, 07:31:18 AM by Buzzkill-THABB »

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Identifying the weapon dealing damage
« Reply #3 on: February 03, 2015, 09:02:17 AM »
It looks like the inflictor value within EntityTakeDamage rarely shows the actual weapon, but rather the player.

Looking at this: http://wiki.garrysmod.com/page/Entity/TakeDamage

If its actually returning player userdata and not just the name (which I'd assume it does not.), then you could also (if you're only trying to get the weapon name) do this

Code: [Select]
function GM:EntityTakeDamage( ply_damaged, weapon )
MsgN(ply_damaged:Nick())
if weapon:IsWeapon() == true then
MsgN(weapon:GetClass())
elseif weapon:IsPlayer() == true then
MsgN(weapon:GetActiveWeapon():GetClass())
else
MsgN("idk what else it could be")
end
end
« Last Edit: February 04, 2015, 09:04:12 AM by Bite That Apple »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Identifying the weapon dealing damage
« Reply #4 on: February 03, 2015, 04:51:18 PM »
Thanks.  Nine times out of ten, the attacker and inflictor inside the dmginfo in EntityTakeDamage is a player.  Yes, I could interrogate the player and ID the active weapon.  The problem is that many weapons deliver different levels of damage depending on which attack was used (primary v. secondary).  A classic example is a double-bld shotgun, where attack1 fires one barrel and attack2 fires both.  If I wanted to modify one or the other independently, I'd need to understand exactly which weapon and which attack was executed.

Not saying it's doable -- just sniffing around for crumbs. 

Thanks.