• Determine which player it hit by SWEP
    7 replies, posted
Basically, I need a function which returns which player was hit. ...That's it. Tell me if I didn't explain it well enough.
[b][url=wiki.garrysmod.com/?title=Gamemode.ScalePlayerDamage]Gamemode.ScalePlayerDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
That tells me which part was hit, not which player. I'm basically creating a gun which lists players who have been shot (as part of a gamemode I'm making).
Use the callback in FireBullets. [lua]bullet.Callback = function( att, tr, dmg ) if tr.Entity:IsValid() then -- tr.Entity is the player hit end end[/lua]
[code]function TracePlayer() trace = util.GetPlayerTrace( self.Entity:GetOwner()) traceRes=util.TraceLine(trace) if traceRes.Entity:IsValid() and traceRes.Entity:IsPlayer() return traceRes.Entity end end[/code]
[QUOTE=raBBish;29653452]Use the callback in FireBullets. [lua]bullet.Callback = function( att, tr, dmg ) if tr.Entity:IsValid() then -- tr.Entity is the player hit end end[/lua][/QUOTE] This or [lua] hook.Add("EntityTakeDamage", "SomeBitchGotHit", function(ent, inflictor, attacker, amount ) if ent:IsPlayer() and ent:Alive() then --ent is your hit player end end)[/lua]
[QUOTE=Feihc;29668567]This or [lua] hook.Add("EntityTakeDamage", function(ent, inflictor, attacker, amount ) if ent:IsPlayer() and ent:Alive() then --ent is your hit player end end)[/lua][/QUOTE] You forgot the hook's unique name argument. :colbert:
[QUOTE=_Kilburn;29669027]You forgot the hook's unique name argument. :colbert:[/QUOTE] Woops. Fixed.
Sorry, you need to Log In to post a reply to this thread.