Hey guys,

Making a script that runs a command when a player gets hurt by a trigger_hurt function in a map.

I’ve tried using GM:PlayerShouldTakeDamage and GM:ScalePlayerDamage, then doing a if attacker = “trigger_hurt” then execute command, and it doesn’t work.

I’m assuming the reason why it isn’t working, is because there is a special way to target entity attackers than a normal player.

Anyone want to throw in their two cents?


I’m pretty new, so I’ll just say make sure you are doing ==

I’d try

function owies(victim, attacker, health, damage)
  if victim:IsPlayer() and attacker:GetName() == "trigger_hurt" then
    --enter code here

hook.add("PlayerHurt", "TriggerHurtStuff", owies)

edit: oops forgot correct lua tags :stuck_out_tongue:

I’m not a lua coder but I know a fair deal about level design and trigger_hurt is a class, not the entity’s name, I hope that helps.

Try hooking to EntityTakeDamage, check if attacker:GetClass() == “trigger_hurt”.

That is actually what I was originally doing and it wasn’t working, since technically the attacker isn’t a player I assume, but thanks.

That was actually very beneficial to finding this out, so thank you.

Thanks, you actually got my on the right track with the hook. However, that didn’t work, assuming again no attacker since it is the map.

Combining both Monomiro’s and Drew’s responses, I came up with the idea of using dmginfo:GetInflictor():GetClass() and that will equal trigger hurt.

Thanks all for your responses, I really appreciate it.

So, does trying to get the class of the inflictor work?

It does, dmginfo:GetInflictor():GetClass() will get trigger_hurt. Sorry if I was not clear.

Thanks again for the help.

Awesome, by helping you I learned something too.

If it’s a map you are making, add a lua_run entity to the map and give it a name, then on the trigger_hurt set the output for StartTouch to activated the lua_run RunPassedCode input and set the value to
if ACTIVATOR:IsPlayer() then TriggerHurtPlayer( ACTIVATOR ) end
which will run the function
function TiggerHurtPlayer( ply )
–Code here to do stuff to player

When a player enters the trigger hurt. You can also use the other outputs on the trigger_hurt to do other stuff the same way.