Hey all,
I have been attempting to do this majority of the night and morning and this is my last resort. After looking at previous work on health, damages, and my own personal issues that I fixed in the past I have come to to other place to look.
I am attempting to make a swep cause 999999 damage to a player if their health is at 20 or lower this is what I have so far:
function SWEP:PrimaryAttack()
local tr = {}
tr.start = self.Owner:GetShootPos()
tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 110 )
tr.filter = self.Owner
tr.mask = MASK_SHOT
local trace = util.TraceLine( tr )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
if ( trace.Hit ) then
if trace.Entity:IsPlayer() or string.find(trace.Entity:GetClass(),"npc") or string.find(trace.Entity:GetClass(),"prop_ragdoll") then
if self:Health()<=20 then
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 1
bullet.Damage = 999999
self.Owner:FireBullets(bullet)
end
elseif trace.Entity:IsPlayer() or string.find(trace.Entity:GetClass(),"npc") or string.find(trace.Entity:GetClass(),"prop_ragdoll") then
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 1
bullet.Damage = self.Primary.Damage
self.Owner:FireBullets(bullet)
else
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 1000
bullet.Damage = self.Primary.Damage
self.Owner:FireBullets(bullet)
self.Weapon:EmitSound( self.WallSound )
util.Decal("ManhackCut", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
end
else
self.Weapon:EmitSound(self.MissSound,100,math.random(90,120))
self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
end
timer.Simple( 0.05, function()
self.Owner:ViewPunch( Angle( 0, 05, 0 ) )
end )
timer.Simple( 0.2, function()
self.Owner:ViewPunch( Angle( 4, -05, 0 ) )
end )
end
I am not getting any errors. When the file is in the server it either causes 249999 or 999999 damage.
Thanks in advance!
if self:Health() <= 20
That tests if the weapon's health is 20 or lower, not the trace hit.
How would I add it to the trace hit?
trace.Entity:Health()
Sorry, you need to Log In to post a reply to this thread.