• A SWEP to minus players health?
    3 replies, posted
I'm making a small custom SWEP for a fairly useless mini-project of mine, and this is what I have. [lua]function SWEP:PrimaryAttack() local tr = self.Owner:GetEyeTrace().Entity if not tr:IsValid() then return end if tr:IsPlayer() then else return end if tr:GetPos():Distance( self.Owner:GetPos() ) > self.Primary.Distance then return end if SERVER then self.Owner:EmitSound( self.Primary.Sound, 75, 160 ) tr:SetHealth( tr:Health - 5 ) --Damages Player for 5 HP end end[/lua] I'm trying to make it so that when a player is within distance in eyetrace, it removes 5HP and plays a sound. [b]Problem 1:[/b]The sound works but it refuses to make the victim's HP minus 5. [b]Problem 2:[/b]How can I go about making a small 'nudge' effect you see on other SWEPs, where the victim takes pain and it nudges him a little in the opposite direction? Thanks in advance for any help/info guys, I appreciate it.
tr:Health() It's a function, you forgot the () to get the player's initial health.
[QUOTE=James0roll;39420619]tr:Health() It's a function, you forgot the () to get the player's initial health.[/QUOTE] Thank you, it now takes 5 HP every time a player is clicked! However, at 5HP it sets HP to 0 and the player doesn't die. Any way to make it DAMAGE the player rather than just setting HP? [editline]31st January 2013[/editline] Fixed it. Replace: tr:SetHealth( tr:SetHealth() -5 ) With: ply:TakeDamage (5)
Yeah, but to help you anyways you would of put this after the player takes damage: [lua] if ply:Health() <= 0 then ply:Kill() end [/lua]
Sorry, you need to Log In to post a reply to this thread.