• GM:PlayerHurt, attacker:TakeDamage not working?
    4 replies, posted
[code]hook.Add("PlayerHurt", "traitortest", function(victim, attacker) if (inuse) then if attacker == self.Owner and victim:GetRole() == ROLE_TRAITOR then victim:TakeDamage(200, attacker, self) elseif attacker == self.Owner and victim:GetRole() != ROLE_TRAITOR then attacker:TakeDamage(200, attacker, self) end end end)[/code] if i kill a traitor, they take the damage like they're supposed but if i kill an innocent, the same thing happens and they also die (when by the above code, i should die, not them) the weapon also does only 1 damage so it's not the weapon.
You are trying to use self outside a SWEP function, it doesn't work that way. You could instead do something like this [code]hook.Add("PlayerHurt", "traitortest", function(victim, attacker) if (inuse) and IsValid(attacker:GetActiveWeapon()) and attacker:GetActiveWeapon():GetClass() == "what ever class it is" then if victim:GetRole() == ROLE_TRAITOR then victim:TakeDamage(200, attacker, self) elseif victim:GetRole() != ROLE_TRAITOR then attacker:TakeDamage(200, attacker, self) end end end)[/code]
now it's doing absolutely nothing and damaging everyone for 1 dmg regardless of who they are [code]hook.Add("PlayerHurt", "traitortest", function(victim, attacker) if (inuse) and IsValid(attacker:GetActiveWeapon()) and attacker:GetActiveWeapon():GetClass() == "weapon_ttt_oneshot" then if attacker == self.Owner and victim:GetRole() == ROLE_TRAITOR then victim:TakeDamage(200, attacker, self) elseif attacker == self.Owner and victim:GetRole() != ROLE_TRAITOR then attacker:TakeDamage(200, attacker, self) end end end)[/code] (also i just switched weapon bases from default to TTT but that doesn't change the fact that it doesn't work) [editline]13th October 2015[/editline] so uh i fixed it and did this [code]hook.Add("PlayerHurt", "traitortest", function(victim, attacker) if (inuse) and IsValid(attacker:GetActiveWeapon()) and attacker:GetActiveWeapon():GetClass() == "weapon_ttt_oneshot" then if victim:GetRole() == ROLE_TRAITOR then victim:TakeDamage(200, attacker, self) elseif victim:GetRole() != ROLE_TRAITOR then attacker:TakeDamage(200, attacker, self) end end end)[/code] and my server disconnnected me with [code]Disconnect: de_stroyer overflowed reliable buffer [/code] when i shot someone
That's because its causing an indefinite loop. TakeDamage fires the PlayerHurt hook. If you looking to simply kill the player you could try using:Kill(). Or you can try overriding what ever function shoots the bullets and apply the damage in the bullet callback function [url]http://wiki.garrysmod.com/page/Entity/FireBullets[/url]
got it working using ply:Kill, thanks.
Sorry, you need to Log In to post a reply to this thread.