Grappling hook entity only visible to player who shot it


title does not say it all, is this a bug with grappling hook, or something you want added? or maybe just a statement of fact

This is a bug I’m trying to fix, sorry if that wasn’t clear

You mean, you want us to fix it, and say your users you did it.

What?

Post the SWEP code aswell, most likely ENT:SetEndPos() is not called shared or not properly networked inside the SWEP. Or the whole ENT is only created clientside, I can’t tell without the SWEP code.

He wants help fixing a [single] bug in the addon, so he can “say his users he did it”? How about just not posting.

I didn’t make this addon I’m just trying to fix it

Weapon Code

Server




AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')

-- Distance CVAR
CreateConVar("grapple_distance", -1, false)


Client




include('shared.lua')


function SWEP:CustomAmmoDisplay()

	self.AmmoDisplay = self.AmmoDisplay or {}
	-- attempt to remove ammo display
	self.AmmoDisplay.Draw = false
	
	self.AmmoDisplay.PrimaryClip 	= 1
	self.AmmoDisplay.PrimaryAmmo 	= -1
	self.AmmoDisplay.SecondaryAmmo 	= -1
	
	return self.AmmoDisplay

end

function SWEP:SetWeaponHoldType( t )
	-- Just a fake function so we can define 
	-- weapon holds in shared files without errors
end


Shared



SWEP.Author			= "Hxrmn, HOLOGRAPHICpizza"
SWEP.Contact		= "mcraft@peak15.org"
SWEP.Purpose		= "A Grappling Hook"
SWEP.Instructions	= "Left click to fire"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= false

SWEP.PrintName			= "Grappling Hook"			
SWEP.Slot				= 2
SWEP.SlotPos			= 0
SWEP.DrawAmmo			= false
SWEP.DrawCrosshair		= true
SWEP.ViewModel			= "models/weapons/v_crossbow.mdl"
SWEP.WorldModel			= "models/weapons/w_crossbow.mdl"

local sndPowerUp		= Sound("weapons/crossbow/hit1.wav")
local sndPowerDown		= Sound("Airboat.FireGunRevDown")
local sndTooFar			= Sound("buttons/button10.wav")

JustShot = false

function SWEP:Initialize()

	nextshottime = CurTime()
	self:SetWeaponHoldType( "smg" )
	self.zoomed = false
	
end

function SWEP:Think()

	if (!self.Owner || self.Owner == NULL) then return end
	
	if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
		if JustShot == false then
			self:StartAttack()
		end
	elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
	
		self:UpdateAttack()
		
	elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
		self:EndAttack( true )
	
	end
	
	--Changed from KeyDown to prevent random stuck-in-zoom bug.
	if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
	
		self:Attack2()
		
	end

end

function SWEP:DoTrace( endpos )
	local trace = {}
		trace.start = self.Owner:GetShootPos()
		trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096) --14096 is length modifier.
		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()
	Attacking = true
	timer.Stop("JustShotFalse")
	-- Get begining and end poins of trace.
	local gunPos = self.Owner:GetShootPos() -- Start of distance trace.
	local disTrace = self.Owner:GetEyeTrace() -- Store all results of a trace in disTrace.
	local hitPos = disTrace.HitPos -- Stores Hit Position of disTrace.
	
	-- Calculate Distance
	-- Thanks to rgovostes for this code.
	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);
	
	-- Only latches if distance is less than distance CVAR, or CVAR negative
	local distanceCvar = GetConVarNumber("grapple_distance")
	inRange = false
	if distanceCvar < 0 or distance <= distanceCvar then
		inRange = true
	end
	
	if inRange then
		if (SERVER) then
			
			if (!self.Beam) then -- If the beam does not exist, draw the beam.
				-- grapple_beam
				self.Beam = ents.Create( "trace1" )
					self.Beam:SetPos( self.Owner:GetShootPos() )
				self.Beam:Spawn()
			end
			
			self.Beam:SetParent( self.Owner )
			self.Beam:SetOwner( self.Owner )
		
		end
		
		self:DoTrace()
		self.speed = 1000 -- Rope latch speed. Was 3000.
		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()
		
		self.Weapon:EmitSound( sndPowerDown )
		self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	else
		-- Play a sound
		self.Weapon:EmitSound( sndTooFar )
	end
end

function SWEP:UpdateAttack()
	if Attacking == true then
	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.Weapon:EmitSound( sndPowerUp )
				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)) -- Player speed. DO NOT MESS WITH THIS VALUE!
				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
end

function SWEP:EndAttack( shutdownsound )
	Attacking = false
	if JustShot == false then
		JustShot = true
		timer.Create("JustShotFalse", 5, 1, function()
			JustShot = false
		end)
	end

	self.zoomed = false
	self:ReloadAnimation()

	if ( shutdownsound ) then
		self.Weapon:EmitSound( sndPowerDown )
	end
	
	if ( CLIENT ) then return end
	if ( !self.Beam ) then return end
	
	self.Beam:Remove()
	self.Beam = nil
	
end

function SWEP:Attack2() -- Zoom.
	if self.zoomed then
		self.zoomed = false
		if SERVER then
			self.Owner:SetFOV(0, 0.1)
		end
	else
		self.zoomed = true
		if SERVER then
			self.Owner:SetFOV(30, 0.1)
		end
	end
end

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

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


function SWEP:PrimaryAttack()
end

function SWEP:SecondaryAttack()
end

--[[---------------------------------------------------------
   Name: SWEP:IdleAnimation()
   Desc: Are you seriously too stupid to understand the function by yourself?
---------------------------------------------------------]]--
function SWEP:IdleAnimation(time)
	
	self.IdleApply = true
	self.ActionDelay = CurTime() + time
	self.IdleDelay = CurTime() + time
end

--[[---------------------------------------------------------
   Name: SWEP:Deploy()
   Desc: Whip mine out.
---------------------------------------------------------]]--
function SWEP:Deploy()
	
	self:DeployAnimation()

	if (IsValid(self.Owner) and self.Owner:GetViewModel()) then
		self:IdleAnimation(self.Owner:GetViewModel():SequenceDuration())
	end

	self.Weapon:SetNextPrimaryFire(CurTime() + 5 + 0.05)
	self.Weapon:SetNextSecondaryFire(CurTime() + 5 + 0.05)
	self.ActionDelay = (CurTime() + 5 + 0.05)

	return true
end

--[[---------------------------------------------------------
   Name: SWEP:DeployAnimation()
---------------------------------------------------------]]--
function SWEP:DeployAnimation()

	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
end

--[[---------------------------------------------------------
   Name: SWEP:ReloadAnimation()
---------------------------------------------------------]]--
function SWEP:ReloadAnimation()

	self.Weapon:SendWeaponAnim(ACT_VM_RELOAD)
end

--[[---------------------------------------------------------
   Name: YERP()
---------------------------------------------------------]]--
SWEP.VElements = {
	["bolt"] = { type = "Model", model = "models/props_junk/harpoon002a.mdl", bone = "Crossbow_model.bolt", rel = "", pos = Vector(0, 0.2, 9.199), angle = Angle(90, 0, 0), size = Vector(0.25, 0.25, 0.25), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.ViewModelBoneMods = {
	["Crossbow_model.bolt"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
}