Rope Owner Checker

Simple little addon that overrides the default rope tool to allow you to check the owner of ropes

A weapon that prints the owner of the rope’s nickname to chat

Feel free to suggest changes if you find any issues let me know

Tried about 5 different ways to do this without having to override the default rope tool for 4 lines… Could not get any of them to work properly

Enjoy

You should PR the owner change to the main GMod repo. Also, your rope checker tool does a lot of pointless loops and checks, and you have a syntax error. You can shorten it to:


SWEP.SearchRadius = 5

-- You could even expand this to be a general entity search tool
SWEP.SearchEntities = {
	keyframe_rope = true,
	phys_lengthconstraint = true
}

function SWEP:PrimaryAttack()	
	self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
	local pPlayer = self:GetOwner()
	
	if pPlayer == NULL then
		return false
	end
	
	-- Why exclude the cursor?
	-- Will always return a table. Checking if it's nil is pointless
	-- Also, the trace table will always have a Vector in HitPos
	local entities = ents.FindInSphere(self.Owner:GetEyeTrace().HitPos, self.SearchRadius)
	
	-- No need to use a pairs loop since the keys are numbers
	-- You could use ipairs as well. Comes down to personal preference
	for i = 1, #entities do
		-- v:GetClass() == ("blah" or "blah2")
		-- Is not valid syntax.
		local pRope = entities*
		local sClass = pRope:GetClass()
		
		if self.SearchEntities[sClass] then
			local pOwner = pRope:GetOwner()
			
			-- IsPlayer will return false for NULL
			pPlayer:ChatPrint(pOwner:IsPlayer() and string.format("%q owns this %s", pOwner:Nick(), sClass)
				or "This rope has no owner!")
		end
	end
	
	return true
end

Thanks man, i really need to get out of the habit of using pairs loops as i know there are much better ways to do this XD

Added to repo.

As for PRing to the main GMod repo, rope tool has not set the ropes owner EVER figured there was a reason for that

[editline]25th September 2016[/editline]

put in a pull request on rope.lua

Never hurts to try i guess

If this works, then that is VERY useful for many server owners