3D Maneuver Gear script error

After finally getting this working, I found out that it gives off a script errors related to ironsights (common with grapple hook like addons) and another error I am unfamiliar with. Please don’t recommend other addons as I’m looking to get help fixing this. That wont solve the issue at hand.

[ERROR] gamemodes/terrortown/gamemode/weaponry_shd.lua:12: attempt to compare number with string

  1. IsEquipment - gamemodes/terrortown/gamemode/weaponry_shd.lua:12
  2. unknown - gamemodes/terrortown/gamemode/weaponry.lua:24
    3. Give - [C]:-1
    4. GiveEquipmentWeapon - gamemodes/terrortown/gamemode/weaponry.lua:319
    5. unknown - gamemodes/terrortown/gamemode/weaponry.lua:323

[ERROR] gamemodes/terrortown/gamemode/util.lua:107: attempt to index field ‘dt’ (a number value)

  1. GetIronsights - gamemodes/terrortown/gamemode/util.lua:107
  2. unknown - gamemodes/terrortown/gamemode/player.lua:1082

Inside /gamemodes/terrortown/gamemode/entities/weapons/3dgear:

shared.lua

[lua]
SWEP.PrintName = “3D Maneuver Gear”
SWEP.Author = “Darkfortune, OldDeath”
SWEP.Contact = “olddeath1@gmx.net
SWEP.Purpose = “Swinging around and killing Titans.”
SWEP.Instructions = “Leftclick for Grappling Hook and Rightclick for dealing damage.”
SWEP.Category = “Attack on Titan”

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.Base = “weapon_tttbase”
SWEP.ViewModelFlip = false
SWEP.Slot = 6
SWEP.Kind = “WEAPON_EQUIP1”
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = “models/aot/c_aot_model_sword.mdl”
SWEP.WorldModel = “models/aot/w_snk_sword.mdl”
SWEP.Icon = “vgui/entities/3dgear”
SWEP.AutoSwitchTo = true
SWEP.Weight = 100
SWEP.UseHands = true
SWEP.CanBuy = { ROLE_DETECTIVE }
SWEP.Secondary.Damage = 0
SWEP.Secondary.NumShots = -1
SWEP.Secondary.Recoil = 0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.TakeAmmoPerBullet = false
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = “none”

SWEP.WElements = {
[“3dgear”] = { type = “Model”, model = “models/aot/3dgear.mdl”, bone = “ValveBiped.Bip01_Pelvis”, rel = “”, pos = Vector(0, 0, -3), angle = Angle(90, 0, -90), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = “”, skin = 0, bodygroup = {} },
[“left_sword”] = { type = “Model”, model = “models/aot/w_snk_sword.mdl”, bone = “ValveBiped.Bip01_L_Hand”, rel = “”, pos = Vector(0, 2.2, 0), angle = Angle(270, 90, 180), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = “”, skin = 0, bodygroup = {} }
}

local SwingSound = Sound( “weapons/iceaxe/iceaxe_swing1.wav” )
local HitSound = Sound( “physics/flesh/flesh_impact_bullet3.wav” )
local hooksound = Sound( “aot/hookshootsound.wav” )

function SWEP:Initialize()

nextshottime = CurTime()
self:SetWeaponHoldType( "melee" )

if CLIENT then

	// Create a new table for every weapon instance
	self.VElements = table.FullCopy( self.VElements )
	self.WElements = table.FullCopy( self.WElements )
	self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )

	self:CreateModels(self.VElements) // create viewmodels
	self:CreateModels(self.WElements) // create worldmodels
	
	// init view model bone build function
	if IsValid(self.Owner) then
		local vm = self.Owner:GetViewModel()
		if IsValid(vm) then
			self:ResetBonePositions(vm)
			
			// Init viewmodel visibility
			if (self.ShowViewModel == nil or self.ShowViewModel) then
				vm:SetColor(Color(255,255,255,255))
			else
				// we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
				vm:SetColor(Color(255,255,255,1))
				// ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
				// however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing
				vm:SetMaterial("Debug/hsv")			
			end
		end
	end
	
end

end

SWEP.AttackAnims = { “hitcenter1”, “hitcenter2”, “hitcenter3” }

function SWEP:Think()

if (!self.Owner || self.Owner == NULL) then return end

if ( self.Owner:KeyPressed( IN_ATTACK ) ) then

	self:StartAttack()
	
elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then

	self:UpdateAttack()
	
elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then

	self:EndAttack( true )

end

if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then

	self:Attack2()
	
end

--[[
if !self.Owner:OnGround() then
	if  SERVER then
		if( self.Owner:KeyDown( IN_SPEED ) ) then
			self.Owner:SetVelocity(Angle(-25,self.Owner:EyeAngles().y,0):Forward()*15)
		end
	end
end
if !self.Owner:OnGround() then
	if  SERVER then
		if( self.Owner:KeyDown( IN_SPEED ) ) then
			self.Owner:EmitSound(Sound( "ambient/levels/canals/dam_water_loop2.wav" ))
			else
			self.Owner:StopSound(Sound( "ambient/levels/canals/dam_water_loop2.wav" ))
		end
	end
end]]

end

function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }

self.Tr = nil
self.Tr = util.TraceLine( trace )

end

function SWEP:StartAttack()
local gunPos = self.Owner:GetShootPos()
local disTrace = self.Owner:GetEyeTrace()
local hitPos = disTrace.HitPos

local x = (gunPos.x - hitPos.x)^2;
local y = (gunPos.y - hitPos.y)^2;
local z = (gunPos.z - hitPos.z)^2;
local distance = math.sqrt(x + y + z);

local distanceCvar = GetConVarNumber("aot_rope_distance")
inRange = false
if distance <= distanceCvar then
	inRange = true
end

if inRange then 
	if (SERVER) then
		
		if (!self.Beam) then
			self.Beam = ents.Create( "aot_rope" )
				self.Beam:SetPos( self.Owner:GetShootPos() )
			self.Beam:Spawn()
		end
		
		
		self.Beam:SetParent( self.Owner )
		self.Beam:SetOwner( self.Owner )
		self.Owner:EmitSound( hooksound )
	end
	
	self:DoTrace()
	self.speed = 10000
	self.startTime = CurTime()
	self.endTime = CurTime() + self.speed
	self.dt = -1
	
	if (SERVER && self.Beam) then
		self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
	end
	
	self:UpdateAttack()
	
else
end

end

function SWEP:UpdateAttack()

self.Owner:LagCompensation( true )

if (!endpos) then endpos = self.Tr.HitPos end

if (SERVER && self.Beam) then
	self.Beam:GetTable():SetEndPos( endpos )
end

lastpos = endpos


		if ( self.Tr.Entity:IsValid() ) then
		
				endpos = self.Tr.Entity:GetPos()
				if ( SERVER ) then
				self.Beam:GetTable():SetEndPos( endpos )
				end
		
		end
		
		local vVel = (endpos - self.Owner:GetPos())
		local Distance = endpos:Distance(self.Owner:GetPos())
		
		local et = (self.startTime + (Distance/self.speed))
		if(self.dt != 0) then
			self.dt = (et - CurTime()) / (et - self.startTime)
		end
		if(self.dt < 0) then
			self.dt = 0
		end
		
		if(self.dt == 0) then
		zVel = self.Owner:GetVelocity().z
		vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
			if( SERVER ) then
			local gravity = GetConVarNumber("sv_Gravity")
			vVel:Add(Vector(0,0,(gravity/100)*1.5))
			if(zVel < 0) then
				vVel:Sub(Vector(0,0,zVel/100))
			end
			self.Owner:SetVelocity(vVel)
			end
		end

endpos = nil

self.Owner:LagCompensation( false )

end

function SWEP:EndAttack( shutdownsound )

if ( CLIENT ) then return end
if ( !self.Beam ) then return end

self.Beam:Remove()
self.Beam = nil

end

function SWEP:Attack2()

end

function SWEP:Holster()

if CLIENT and IsValid(self.Owner) then
	local vm = self.Owner:GetViewModel()
	if IsValid(vm) then
		self:ResetBonePositions(vm)
	end
end
self:EndAttack( false )

return true

end

function SWEP:OnRemove()
self:Holster()
self:EndAttack( false )
return true
end

if CLIENT then

SWEP.vRenderOrder = nil
function SWEP:ViewModelDrawn()
	
	local vm = self.Owner:GetViewModel()
	if !IsValid(vm) then return end
	
	if (!self.VElements) then return end
	
	self:UpdateBonePositions(vm)

	if (!self.vRenderOrder) then
		
		// we build a render order because sprites need to be drawn after models
		self.vRenderOrder = {}

		for k, v in pairs( self.VElements ) do
			if (v.type == "Model") then
				table.insert(self.vRenderOrder, 1, k)
			elseif (v.type == "Sprite" or v.type == "Quad") then
				table.insert(self.vRenderOrder, k)
			end
		end
		
	end

	for k, name in ipairs( self.vRenderOrder ) do
	
		local v = self.VElements[name]
		if (!v) then self.vRenderOrder = nil break end
		if (v.hide) then continue end
		
		local model = v.modelEnt
		local sprite = v.spriteMaterial
		
		if (!v.bone) then continue end
		
		local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
		
		if (!pos) then continue end
		
		if (v.type == "Model" and IsValid(model)) then

			model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
			ang:RotateAroundAxis(ang:Up(), v.angle.y)
			ang:RotateAroundAxis(ang:Right(), v.angle.p)
			ang:RotateAroundAxis(ang:Forward(), v.angle.r)

			model:SetAngles(ang)
			//model:SetModelScale(v.size)
			local matrix = Matrix()
			matrix:Scale(v.size)
			model:EnableMatrix( "RenderMultiply", matrix )
			
			if (v.material == "") then
				model:SetMaterial("")
			elseif (model:GetMaterial() != v.material) then
				model:SetMaterial( v.material )
			end
			
			if (v.skin and v.skin != model:GetSkin()) then
				model:SetSkin(v.skin)
			end
			
			if (v.bodygroup) then
				for k, v in pairs( v.bodygroup ) do
					if (model:GetBodygroup(k) != v) then
						model:SetBodygroup(k, v)
					end
				end
			end
			
			if (v.surpresslightning) then
				render.SuppressEngineLighting(true)
			end
			
			render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
			render.SetBlend(v.color.a/255)
			model:DrawModel()
			render.SetBlend(1)
			render.SetColorModulation(1, 1, 1)
			
			if (v.surpresslightning) then
				render.SuppressEngineLighting(false)
			end
			
		elseif (v.type == "Sprite" and sprite) then
			
			local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
			render.SetMaterial(sprite)
			render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
			
		elseif (v.type == "Quad" and v.draw_func) then
			
			local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
			ang:RotateAroundAxis(ang:Up(), v.angle.y)
			ang:RotateAroundAxis(ang:Right(), v.angle.p)
			ang:RotateAroundAxis(ang:Forward(), v.angle.r)
			
			cam.Start3D2D(drawpos, ang, v.size)
				v.draw_func( self )
			cam.End3D2D()

		end
		
	end
	
end

SWEP.wRenderOrder = nil
function SWEP:DrawWorldModel()
	
	if (self.ShowWorldModel == nil or self.ShowWorldModel) then
		self:DrawModel()
	end
	
	if (!self.WElements) then return end
	
	if (!self.wRenderOrder) then

		self.wRenderOrder = {}

		for k, v in pairs( self.WElements ) do
			if (v.type == "Model") then
				table.insert(self.wRenderOrder, 1, k)
			elseif (v.type == "Sprite" or v.type == "Quad") then
				table.insert(self.wRenderOrder, k)
			end
		end

	end
	
	if (IsValid(self.Owner)) then
		bone_ent = self.Owner
	else
		// when the weapon is dropped
		bone_ent = self
	end
	
	for k, name in pairs( self.wRenderOrder ) do
	
		local v = self.WElements[name]
		if (!v) then self.wRenderOrder = nil break end
		if (v.hide) then continue end
		
		local pos, ang
		
		if (v.bone) then
			pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
		else
			pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
		end
		
		if (!pos) then continue end
		
		local model = v.modelEnt
		local sprite = v.spriteMaterial
		
		if (v.type == "Model" and IsValid(model)) then

			model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
			ang:RotateAroundAxis(ang:Up(), v.angle.y)
			ang:RotateAroundAxis(ang:Right(), v.angle.p)
			ang:RotateAroundAxis(ang:Forward(), v.angle.r)

			model:SetAngles(ang)
			//model:SetModelScale(v.size)
			local matrix = Matrix()
			matrix:Scale(v.size)
			model:EnableMatrix( "RenderMultiply", matrix )
			
			if (v.material == "") then
				model:SetMaterial("")
			elseif (model:GetMaterial() != v.material) then
				model:SetMaterial( v.material )
			end
			
			if (v.skin and v.skin != model:GetSkin()) then
				model:SetSkin(v.skin)
			end
			
			if (v.bodygroup) then
				for k, v in pairs( v.bodygroup ) do
					if (model:GetBodygroup(k) != v) then
						model:SetBodygroup(k, v)
					end
				end
			end
			
			if (v.surpresslightning) then
				render.SuppressEngineLighting(true)
			end
			
			render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
			render.SetBlend(v.color.a/255)
			model:DrawModel()
			render.SetBlend(1)
			render.SetColorModulation(1, 1, 1)
			
			if (v.surpresslightning) then
				render.SuppressEngineLighting(false)
			end
			
		elseif (v.type == "Sprite" and sprite) then
			
			local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
			render.SetMaterial(sprite)
			render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
			
		elseif (v.type == "Quad" and v.draw_func) then
			
			local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
			ang:RotateAroundAxis(ang:Up(), v.angle.y)
			ang:RotateAroundAxis(ang:Right(), v.angle.p)
			ang:RotateAroundAxis(ang:Forward(), v.angle.r)
			
			cam.Start3D2D(drawpos, ang, v.size)
				v.draw_func( self )
			cam.End3D2D()

		end
		
	end
	
end

function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
	
	local bone, pos, ang
	if (tab.rel and tab.rel != "") then
		
		local v = basetab[tab.rel]
		
		if (!v) then return end
		
		// Technically, if there exists an element with the same name as a bone
		// you can get in an infinite loop. Let's just hope nobody's that stupid.
		pos, ang = self:GetBoneOrientation( basetab, v, ent )
		
		if (!pos) then return end
		
		pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
		ang:RotateAroundAxis(ang:Up(), v.angle.y)
		ang:RotateAroundAxis(ang:Right(), v.angle.p)
		ang:RotateAroundAxis(ang:Forward(), v.angle.r)
			
	else
	
		bone = ent:LookupBone(bone_override or tab.bone)

		if (!bone) then return end
		
		pos, ang = Vector(0,0,0), Angle(0,0,0)
		local m = ent:GetBoneMatrix(bone)
		if (m) then
			pos, ang = m:GetTranslation(), m:GetAngles()
		end
		
		if (IsValid(self.Owner) and self.Owner:IsPlayer() and 
			ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
			ang.r = -ang.r // Fixes mirrored models
		end
	
	end
	
	return pos, ang
end

function SWEP:CreateModels( tab )

	if (!tab) then return end

	// Create the clientside models here because Garry says we can't do it in the render hook
	for k, v in pairs( tab ) do
		if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and 
				string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
			
			v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
			if (IsValid(v.modelEnt)) then
				v.modelEnt:SetPos(self:GetPos())
				v.modelEnt:SetAngles(self:GetAngles())
				v.modelEnt:SetParent(self)
				v.modelEnt:SetNoDraw(true)
				v.createdModel = v.model
			else
				v.modelEnt = nil
			end
			
		elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite) 
			and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
			
			local name = v.sprite.."-"
			local params = { ["$basetexture"] = v.sprite }
			// make sure we create a unique name based on the selected options
			local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
			for i, j in pairs( tocheck ) do
				if (v[j]) then
					params["$"..j] = 1
					name = name.."1"
				else
					name = name.."0"
				end
			end

			v.createdSprite = v.sprite
			v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
			
		end
	end
	
end

local allbones
local hasGarryFixedBoneScalingYet = false

function SWEP:UpdateBonePositions(vm)
	
	if self.ViewModelBoneMods then
		
		if (!vm:GetBoneCount()) then return end
		
		// !! WORKAROUND !! //
		// We need to check all model names :/
		local loopthrough = self.ViewModelBoneMods
		if (!hasGarryFixedBoneScalingYet) then
			allbones = {}
			for i=0, vm:GetBoneCount() do
				local bonename = vm:GetBoneName(i)
				if (self.ViewModelBoneMods[bonename]) then 
					allbones[bonename] = self.ViewModelBoneMods[bonename]
				else
					allbones[bonename] = { 
						scale = Vector(1,1,1),
						pos = Vector(0,0,0),
						angle = Angle(0,0,0)
					}
				end
			end
			
			loopthrough = allbones
		end
		// !! ----------- !! //
		
		for k, v in pairs( loopthrough ) do
			local bone = vm:LookupBone(k)
			if (!bone) then continue end
			
			// !! WORKAROUND !! //
			local s = Vector(v.scale.x,v.scale.y,v.scale.z)
			local p = Vector(v.pos.x,v.pos.y,v.pos.z)
			local ms = Vector(1,1,1)
			if (!hasGarryFixedBoneScalingYet) then
				local cur = vm:GetBoneParent(bone)
				while(cur >= 0) do
					local pscale = loopthrough[vm:GetBoneName(cur)].scale
					ms = ms * pscale
					cur = vm:GetBoneParent(cur)
				end
			end
			
			s = s * ms
			// !! ----------- !! //
			
			if vm:GetManipulateBoneScale(bone) != s then
				vm:ManipulateBoneScale( bone, s )
			end
			if vm:GetManipulateBoneAngles(bone) != v.angle then
				vm:ManipulateBoneAngles( bone, v.angle )
			end
			if vm:GetManipulateBonePosition(bone) != p then
				vm:ManipulateBonePosition( bone, p )
			end
		end
	else
		self:ResetBonePositions(vm)
	end
	   
end
 
function SWEP:ResetBonePositions(vm)
	
	if (!vm:GetBoneCount()) then return end
	for i=0, vm:GetBoneCount() do
		vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
		vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
		vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
	end
	
end

/**************************
	Global utility code
**************************/

// Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
// Does not copy entities of course, only copies their reference.
// WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
function table.FullCopy( tab )

	if (!tab) then return nil end
	
	local res = {}
	for k, v in pairs( tab ) do
		if (type(v) == "table") then
			res[k] = table.FullCopy(v) // recursion ho!
		elseif (type(v) == "Vector") then
			res[k] = Vector(v.x, v.y, v.z)
		elseif (type(v) == "Angle") then
			res[k] = Angle(v.p, v.y, v.r)
		else
			res[k] = v
		end
	end
	
	return res
	
end

end

function SWEP:PrimaryAttack()

end

function SWEP:SecondaryAttack()
self:SetNextSecondaryFire( CurTime() + 0.7 )

self.Owner:SetAnimation( PLAYER_ATTACK1 )

if ( !SERVER ) then return end

local vm = self.Owner:GetViewModel()
vm:ResetSequence( vm:LookupSequence( "idle01" ) )

local anim = self.AttackAnims[ math.random( 1, #self.AttackAnims ) ]

timer.Simple( 0, function()
	if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end

	local vm = self.Owner:GetViewModel()
	vm:ResetSequence( vm:LookupSequence( anim ) )

	self:Idle()
end )

timer.Simple( 0.05, function()
	if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
	if ( anim == "hitcenter1" ) then
		self.Owner:ViewPunch( Angle( 5, 20, 0 ) )
	elseif ( anim == "hitcenter2" ) then
		self.Owner:ViewPunch( Angle( 5, -20, 0 ) )
	elseif ( anim == "hitcenter3" ) then
		self.Owner:ViewPunch( Angle( 20, 0, 0 ) )
	end
end )

timer.Simple( 0.2, function()
	if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
	if ( anim == "hitcenter1" ) then
		self.Owner:ViewPunch( Angle( 2, 10, 0 ) )
	elseif ( anim == "hitcenter2" ) then
		self.Owner:ViewPunch( Angle( 2, -10, 0 ) )
	elseif ( anim == "hitcenter3" ) then
		self.Owner:ViewPunch( Angle( 10, 0, 0 ) )
	end
	
end )

	local gunPos = self.Owner:GetShootPos()
	local disTrace = self.Owner:GetEyeTrace()
	local hitPos = disTrace.HitPos

	local x = (gunPos.x - hitPos.x)^2;
	local y = (gunPos.y - hitPos.y)^2;
	local z = (gunPos.z - hitPos.z)^2;
	local distance = math.sqrt(x + y + z);

local distanceCvar = GetConVarNumber("aot_hit_distance")
local inRange = false
	if distance <= distanceCvar then
	inRange = true
end

if inRange==false then
self.Owner:EmitSound( SwingSound )
end

if inRange==false then return
end



self.Owner:EmitSound( HitSound )
local bullet = {}	-- Set up the shot
	bullet.Num = self.Primary.NumShots
	bullet.Src = self.Owner:GetShootPos()
	bullet.Dir = self.Owner:GetAimVector()
	bullet.Tracer = self.Primary.Tracer
	bullet.Force = self.Primary.Force
	bullet.Damage = self.Secondary.Damage
	bullet.AmmoType = self.Primary.Ammo
	self.Owner:FireBullets( bullet )
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self:TakePrimaryAmmo(0)

end

function SWEP:Idle()

local vm = self.Owner:GetViewModel()
timer.Create( "idle" .. self:EntIndex(), vm:SequenceDuration(), 1, function()
	vm:ResetSequence( vm:LookupSequence( "idle0" .. math.random( 1, 2 ) ) )
end )

end
[/lua]
cl_init.lua
[lua]
include(‘shared.lua’)

SWEP.WepSelectIcon = surface.GetTextureID("vgui/entities/snk_sword_icon") 

function SWEP:CustomAmmoDisplay()

self.AmmoDisplay = self.AmmoDisplay or {}
self.AmmoDisplay.Draw = false

self.AmmoDisplay.PrimaryClip 	= 1
self.AmmoDisplay.PrimaryAmmo 	= -1
self.AmmoDisplay.SecondaryAmmo 	= -1

return self.AmmoDisplay

end
[/lua]
init.lua
[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)

CreateConVar(“aot_rope_distance”, 4000, false)
CreateConVar(“aot_hit_distance”, 150, false)
[/lua]

Inside Inside /gamemodes/terrortown/gamemode/entities/entities/aot_rope:

shared.lua

[lua]ENT.Type = “anim”

/---------------------------------------------------------
---------------------------------------------------------
/
function ENT:SetEndPos( endpos )

self.Entity:SetNetworkedVector( 0, endpos )	
self.Entity:SetCollisionBoundsWS( self.Entity:GetPos(), endpos, Vector() * 0.25 )

end

/---------------------------------------------------------
---------------------------------------------------------
/
function ENT:GetEndPos()
return self.Entity:GetNetworkedVector( 0 )
end
[/lua]

init.lua

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

/---------------------------------------------------------
Name: Initialize
---------------------------------------------------------
/
function ENT:Initialize()

self.Entity:DrawShadow( false )
self.Entity:SetSolid( SOLID_NONE )

end

function ENT:Think()
end
[/lua]

cl_init.lua

[lua]

include(‘shared.lua’)

local matBeam = Material( “cable/cable” )

/---------------------------------------------------------
Name: Initialize
---------------------------------------------------------
/
function ENT:Initialize()

self.Size = 0
self.MainStart = self.Entity:GetPos()
self.MainEnd = self:GetEndPos()
self.dAng = (self.MainEnd - self.MainStart):Angle()
self.speed = 10000
self.startTime = CurTime()
self.endTime = CurTime() + self.speed
self.dt = -1

end

function ENT:Think()

self.Entity:SetRenderBoundsWS( self:GetEndPos(), self.Entity:GetPos(), Vector()*8 )

self.Size = math.Approach( self.Size, 1, 10*FrameTime() )

end

function ENT:DrawMainBeam( StartPos, EndPos, dt, dist )

local TexOffset = 0

local ca = Color(255,255,255,255)

EndPos = StartPos + (self.dAng * ((1 - dt)*dist))

-- Beam effect
render.SetMaterial( matBeam )
render.DrawBeam( EndPos, StartPos, 
				2, 
				TexOffset*-0.4, TexOffset*-0.4 + StartPos:Distance(EndPos) / 256, 
				ca )

end

function ENT:DrawMainBeam2( StartPos2, EndPos, dt, dist )

local TexOffset = 0

local ca = Color(255,255,255,255)

EndPos = StartPos2 + (self.dAng * ((1 - dt)*dist))

-- Beam effect
render.SetMaterial( matBeam )
render.DrawBeam( EndPos, StartPos2, 
				2, 
				TexOffset*-0.4, TexOffset*-0.4 + StartPos2:Distance(EndPos) / 256, 
				ca )

end

function ENT:Draw()

local Owner = self.Entity:GetOwner()
if (!Owner || Owner == NULL) then return end

local StartPos 		= self.Entity:GetPos()
local EndPos 		= self:GetEndPos()
local ViewModel 	= Owner == LocalPlayer()

if (EndPos == Vector(0,0,0)) then return end

if ( ViewModel ) then

	local vm = Owner:GetViewModel()
	if (!vm || vm == NULL) then return end
	local attachment = vm:GetAttachment( 1 )
	StartPos = attachment.Pos

else

	local vm = Owner:GetActiveWeapon()
	if (!vm || vm == NULL) then return end
	local attachment = vm:GetAttachment( 1 )
	StartPos = attachment.Pos

end

	if ( ViewModel ) then

	local vm = Owner:GetViewModel()
	if (!vm || vm == NULL) then return end
	local attachment = vm:GetAttachment( 2 )
	StartPos2 = attachment.Pos

else

	local vm = Owner:GetActiveWeapon()
	if (!vm || vm == NULL) then return end
	local attachment = vm:GetAttachment( 2 )
	StartPos2 = attachment.Pos

end


local TexOffset = CurTime() * -2

local Distance = EndPos:Distance( StartPos ) * self.Size

local et = (self.startTime + (Distance/self.speed))
if(self.dt != 0) then
	self.dt = (et - CurTime()) / (et - self.startTime)
end
if(self.dt < 0) then
	self.dt = 0
end
self.dAng = (EndPos - StartPos):Angle():Forward()

gbAngle = (EndPos - StartPos):Angle()
local Normal 	= gbAngle:Forward()

self:DrawMainBeam( StartPos, StartPos + Normal * Distance, self.dt, Distance )
self:DrawMainBeam2( StartPos2, StartPos2 + Normal * Distance, self.dt, Distance )

end

/---------------------------------------------------------
Name: IsTranslucent
---------------------------------------------------------
/
function ENT:IsTranslucent()
return true
end
[/lua]

Thanks in advance for any help :stuck_out_tongue:

Why are you constantly comparing values to “keyword operator?”

That’s the forum messing stuff up.

I remember seeing another thread where this happened and said the same thing. I was told that it’s apparently an issue with Facepunch, so while it makes the code very messy to read, I don’t think it means anything

Oh, it’s been copy/pasted AFTER the forum messed it up.

[editline]11th March 2014[/editline]

My automerge :frowning:

I have no idea what the error is :stuck_out_tongue: I myself cannot see it. Anyhow, back to the issue at hand :slight_smile:

Bumping for actual help