Need help understanding a part of lua!

Ok.

My goal is to make a sledge hammer that when it hits an object it removes all of its constraints.
I already have a sledge hammer weapon base but I need to add the remove constraints.

The part of the code I’m focusing on is this:



-- function SWEP:Reload() --To do when reloading
-- end 
 
function SWEP:Think() -- Called every frame
end

function SWEP:Initialize()
util.PrecacheSound("")
end

function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + .4)

local trace = self.Owner:GetEyeTrace()

if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 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 = 25
self.Owner:FireBullets(bullet) 
self.Weapon:EmitSound("")
else
self.Weapon:EmitSound("" .. math.random( 1, 4 ) .. ".wav")
	self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
end

end


I want to add the remove constraints to the primary attack and secondary but I assume that adding it to the primary is the same as secondary.

I know that the code for remove constraints is:


 constraint.RemoveConstraints 

But what I don’t know is where to add it to the current code and if necessary tell it that it happens to the object that is hit by the weapon (in case that is required).


(User was banned for this post ("Wrong section / undescriptive thread title" - mahalis))

Did you really need to post this twice?

[editline]09:58PM[/editline]

[lua]for _, ent in ipairs(ents.FindInSphere(tr.HitPos, 75)) do
if (ent and ent:IsValid( )) then
constraint.RemoveAll(ent)
end
end[/lua]

Try placing this in your PrimaryAttack function after ***self.Owner:FireBullets(bullet)


Thanks Ill try that out but if I put the “ends” at the end of your code wont that cut off the rest of primary fire?

And sorry when I went to post it the first time facepunch went down for a minute or two and it didn’t show up. I re-posted but I guess it eventually showed up too.

Those ends are for the for loop and the if statement, it will not end your primary attack function.