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?
Thanks!
I'm pretty new, so I'll just say make sure you are doing ==
I'd try
[code][lua]
function owies(victim, attacker, health, damage)
if victim:IsPlayer() and attacker:GetName() == "trigger_hurt" then
--enter code here
end
end
hook.add("PlayerHurt", "TriggerHurtStuff", owies)
[/lua][/code]
edit: oops forgot correct lua tags :P
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".
[QUOTE=yumi_cheese;28269164]I'm pretty new, so I'll just say make sure you are doing ==
I'd try
[code][lua]
function owies(victim, attacker, health, damage)
if victim:IsPlayer() and attacker:GetName() == "trigger_hurt" then
--enter code here
end
end
hook.add("PlayerHurt", "TriggerHurtStuff", owies)
[/lua][/code]
edit: oops forgot correct lua tags :P[/QUOTE]
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.
[QUOTE=Monomiro;28269657]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.[/QUOTE]
That was actually very beneficial to finding this out, so thank you.
[QUOTE=Drew P. Richard;28270323]Try hooking to EntityTakeDamage, check if attacker:GetClass() == "trigger_hurt".[/QUOTE]
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?
[QUOTE=Drew P. Richard;28270503]So, does trying to get the class of the inflictor work?[/QUOTE]
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 [url]http://wiki.garrysmod.com/?title=Lua_run_(entity)[/url] 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
[lua]
if ACTIVATOR:IsPlayer() then TriggerHurtPlayer( ACTIVATOR ) end
[/lua]
which will run the function
[lua]
function TiggerHurtPlayer( ply )
--Code here to do stuff to player
end
[/lua]
When a player enters the trigger hurt. You can also use the other outputs on the trigger_hurt [url] http://developer.valvesoftware.com/wiki/Trigger_hurt [/url] to do other stuff the same way.
Sorry, you need to Log In to post a reply to this thread.