A modded Addon, works great! but...

So, I’m using a modded Stealth Katana Swep for a DarkRP server, and it works… no complaints about its use, but there’s a small issue.

I keep getting an error EVEN THOUGH… it all still works.

Now… depending on wether i switch out of that weapon, or back into, or simply use stealth, i always get a


'DrawWorldModel' (a nil Value)

related error. this addon doesn’t need a fix,
I just want to know how to stop that error from popping up. because as repeatedly stated prior, it works great already.
here’s the code for that file:


if( SERVER ) then
	AddCSLuaFile( "shared.lua" )
resource.AddFile("models/weapons/w_katana.mdl"); 
resource.AddFile("models/weapons/v_katana.mdl"); 
resource.AddFile("materials/models/weapons/v_katana/katana_normal.vtf"); 
resource.AddFile("materials/models/weapons/v_katana/katana.vtf"); 
resource.AddFile("materials/models/weapons/v_katana/katana.vmt");
end
SWEP.Author			= "RogueX100"
SWEP.Instructions	= "LMB to Slash, RMB to Cloak, Use key for Shuriken, and Reload key for Grenade"
SWEP.Contact		= ""
SWEP.Purpose		= ""
SWEP.Category		= "Rogue's Wep's"
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true
SWEP.Thinkdelay           = 0
SWEP.Primary.Delay				= 0.4
SWEP.Primary.Recoil				= 0
SWEP.Primary.Damage		= math.random(28,45)
SWEP.Primary.NumShots			= 1
SWEP.Primary.Cone				= 0
SWEP.Primary.ClipSize			= -1
SWEP.Primary.DefaultClip		= -1
SWEP.Primary.Automatic   		= false
SWEP.Primary.Ammo         		= "none"
SWEP.Cloaked                    = false
SWEP.Secondary.Delay			= 5
SWEP.Secondary.Recoil			= 0
SWEP.Secondary.Damage			= 2
SWEP.Secondary.NumShots			= 1
SWEP.Secondary.Cone				= 0
SWEP.Secondary.ClipSize			= -1
SWEP.Secondary.DefaultClip		= -1
SWEP.Secondary.Automatic  	 	= false
SWEP.GrenadeDelay                 = 0
SWEP.ShurikenDelay                 = 0
SWEP.HoldType = "melee2"
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/v_katana.mdl"
SWEP.WorldModel = "models/weapons/w_katana.mdl"
SWEP.ThrowTimer            = false
SWEP.MeleeRevert             = false

function SWEP:Initialize()
    self:SetWeaponHoldType("melee2")
    self:StatIncrease()

end

function SWEP:StatIncrease()
timer.Simple(0.5, function()
if self:IsValid() and self.Owner:IsValid() then
self.Owner:SetHealth(self.Owner:Health() + 100)
end
end)
end

function SWEP:Holster()
if self:IsValid() and self.Owner:IsValid() then
self.Owner:SetJumpPower(200)
self:SetNetworkedBool( "Katana_View_Cloak", false )
self.Owner:GetViewModel():SetMaterial("")	
if self.Cloaked == true then
if !self.Owner:Alive() then
self.Owner:SetMaterial("")
self.Owner:DrawWorldModel( true ) 
else
timer.Destroy("CloakTime")
	  self.Cloaked = false
		self:EmitSound("npc/dog/dog_idle1.wav")
		 self.Owner:DrawShadow( true ) 
			self.Owner:SetMaterial("")
				self.Owner:DrawWorldModel( true ) 
					self.Owner:SetNoTarget(false)
	end
end
   end
	return true
end

function SWEP:OnRemove()

end

function SWEP:Deploy()
if !self.Owner:IsValid() then return end
self.Owner:DrawWorldModel( true ) 
self.Owner:SetJumpPower(400)
return true
end

function SWEP:SecondaryAttack()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
if self.Cloaked then return end
self.Cloaked = true
self:Cloak()
end

function SWEP:PrimaryAttack()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:EmitSound("weapons/npc_katana/qubodup_sword_swing2.wav")--slash in the wind sound here
timer.Simple(0.2, function()
if self:IsValid() then
	self:Slash()
	end
end)
	self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	end

function SWEP:Slash()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
	pos = self.Owner:GetShootPos()
	ang = self.Owner:GetAimVector()
	damagedice = math.Rand(0.9,1.50)
	pain = self.Primary.Damage * damagedice
				if SERVER and IsValid(self.Owner) then
						local slash = {}
						slash.start = pos
						slash.endpos = pos + (ang * 70)
						slash.filter = self.Owner
						slash.mins = Vector(-5, -5, 0)
						slash.maxs = Vector(5, 5, 5)
						local slashtrace = util.TraceHull(slash)
						if slashtrace.Hit then
							targ = slashtrace.Entity
							if targ:IsPlayer() or targ:IsNPC() then
									self.Owner:EmitSound("weapons/npc_katana/SQUIB_KNIFE_IMPACT_FLESH_02.wav")								
								paininfo = DamageInfo()
								paininfo:SetDamage(pain)
								paininfo:SetDamageType(DMG_SLASH)
								paininfo:SetAttacker(self.Owner)
								paininfo:SetInflictor(self.Weapon)
						  local RandomForce = math.random(1000,20000)
								paininfo:SetDamageForce(slashtrace.Normal * RandomForce)
								if targ:IsPlayer() then
								targ:ViewPunch( Angle( -10, -20, 0 ) )
								end
							local blood = targ:GetBloodColor()	
						   local fleshimpact		= EffectData()
								fleshimpact:SetEntity(self.Weapon)
								fleshimpact:SetOrigin(slashtrace.HitPos)
								fleshimpact:SetNormal(slashtrace.HitPos)
								if blood >= 0 then
								fleshimpact:SetColor(blood)
								util.Effect("BloodImpact", fleshimpact)	
                                 end								
								if SERVER then targ:TakeDamageInfo(paininfo) end
							else						
								look = self.Owner:GetEyeTrace()
								util.Decal("ManhackCut", look.HitPos + look.HitNormal, look.HitPos - look.HitNormal )
							end
						end
					end
	end
-----------------------------------Credit for this part goes to RobotBoy655, Just rewritten so I can learn it for myself and altered to my liking-----------------------------------	
hook.Add( "ShouldDrawLocalPlayer", "stealth_katana_draw", function()
	if (  LocalPlayer():IsValid() and  LocalPlayer():GetActiveWeapon():IsValid() and LocalPlayer():GetActiveWeapon():GetClass() == "stealth_katana_swep" and !LocalPlayer():InVehicle() and LocalPlayer():Alive() and LocalPlayer():GetViewEntity() == LocalPlayer() and GetConVar( "RSK_1st_Person" ):GetInt() == 0 ) then return true end
end )

function SWEP:CalcView( ply, pos, angle, fov )
	if ( !ply:IsValid() or !ply:Alive() or ply:InVehicle() or ply:GetViewEntity() != ply or GetConVar( "RSK_1st_Person" ):GetInt() == 1 ) then return end

	local trace = util.TraceLine( {
		start = pos,
		endpos = pos - angle:Forward() * 124,
		filter = { ply:GetActiveWeapon(), ply }
	} )

	if ( trace.Hit ) then pos = trace.HitPos + angle:Forward() * 24 elseif 
	!self.Owner:Crouching() then pos = pos - angle:Forward() * 110 + angle:Up()*8
	elseif self.Owner:Crouching() then pos = pos - angle:Forward() * 110 + angle:Up()*25
	end

	return pos, angle, fov
end
-----------------------------------------------------------------------------------------------------------------------------------------------	
function SWEP:Think()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
	if self:GetNetworkedBool("GrenadeHoldType") == true then
		self:SetWeaponHoldType("grenade")
	end
	if self:GetNetworkedBool("GrenadeHoldType") == false then
		self:SetWeaponHoldType("melee2")
	end
	if self:GetNetworkedBool("KatanaJump") == true then
		self:SetWeaponHoldType("melee")
	end
	if self:GetNetworkedBool("Katana_View_Cloak") == true then
		self.Owner:GetViewModel():SetMaterial("sprites/heatwave")
		 else
		self.Owner:GetViewModel():SetMaterial("")	
	end
		self.Owner:RemoveAllDecals()
if ( CurTime() >= self.GrenadeDelay ) and self.ThrowTimer == false then
if self.Owner:KeyPressed( IN_RELOAD ) then
self.ThrowTimer = true
self:ThrowGrenade()
self.GrenadeDelay = CurTime() + GetConVar( "RSK_Grenade_Cooldown" ):GetInt()
end
end
if ( CurTime() >= self.ShurikenDelay ) and self.ThrowTimer == false then
if self.Owner:KeyPressed( IN_USE ) then
self.ThrowTimer = true
self:ThrowShuriken()
self.ShurikenDelay = CurTime() + GetConVar( "RSK_Shuriken_Cooldown" ):GetInt()
end
end
if !self.Owner:OnGround() then
self:SetNetworkedBool( "KatanaJump", true )
else
self:SetNetworkedBool( "KatanaJump", false )
end
if self.Cloaked == true then

end
end

function SWEP:ThrowGrenade()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
self:SetNetworkedBool( "GrenadeHoldType", true )
timer.Simple(0.2, function()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
  self.Owner:SetAnimation( PLAYER_ATTACK1 )
  self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
	aim = self.Owner:GetAimVector()
	side = aim:Cross(Vector(0,0,1))
	up = side:Cross(aim)
	pos = self.Owner:GetShootPos() + side * 5 + up * -1
	if SERVER then
	local rocket = ents.Create("npc_grenade_frag")
	if !rocket:IsValid() then return false end
	rocket:Fire("SetTimer", 1)  
	rocket:SetAngles(aim:Angle()+Angle(90,0,0))
	rocket:SetPos(pos)
	rocket:SetOwner(self.Owner)
	rocket:Spawn()
	local phys = rocket:GetPhysicsObject()
	phys:ApplyForceCenter(self.Owner:GetAimVector() * 1000)
	self.ThrowTimer = false
	timer.Simple(0.5, function()
	if !self:IsValid() or !self.Owner:IsValid() then return;end 
	self:SetNetworkedBool( "GrenadeHoldType", false )
		end)
	end
	end)
end

function SWEP:ThrowShuriken()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
self:SetNetworkedBool( "GrenadeHoldType", true )
timer.Simple(0.2, function()
if !self:IsValid() or !self.Owner:IsValid() then return;end 
self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
	self.Weapon:EmitSound("weapons/shuriken/throw4.wav")	
	aim = self.Owner:GetAimVector()
	side = aim:Cross(Vector(0,0,1))
	up = side:Cross(aim)
	pos = self.Owner:GetShootPos() + side * 5 + up * -1
	if SERVER then
	local rocket = ents.Create("npc_shuriken")
	if !rocket:IsValid() then return false end
	rocket:SetAngles(aim:Angle()+Angle(90,90,0))
	rocket:SetPos(pos)
	rocket:SetOwner(self.Owner)
	rocket:Spawn()
	local phys = rocket:GetPhysicsObject()

	phys:ApplyForceCenter(self.Owner:GetAimVector() * 10000)
		self.ThrowTimer = false
	timer.Simple(0.5, function()
	if !self:IsValid() or !self.Owner:IsValid() then return;end 
	self:SetNetworkedBool( "GrenadeHoldType", false )
		end)
	end
	end)
end

function SWEP:Cloak()
    self.Cloaked = true
	self:SetNetworkedBool( "Katana_View_Cloak", true )
	self:EmitSound("npc/dog/dog_idle2.wav")
	self.Owner:DrawShadow( false ) 
	self.Owner:SetMaterial("sprites/heatwave")
	self.Owner:DrawWorldModel( false ) 
	self.StealthTimer = true
    self.Owner:SetNoTarget(true)
	timer.Create("CloakTime",GetConVar( "RSK_Cloak_Duration" ):GetInt(), 1, function()
if !self:IsValid() or !self.Owner:IsValid() then return end
	self.Weapon:SetNextSecondaryFire( CurTime() + GetConVar( "RSK_Cloak_Cooldown" ):GetInt() )
		self:EmitSound("npc/dog/dog_idle1.wav")
		 self.Owner:DrawShadow( true ) 
			self.Owner:SetMaterial("")
					self.Owner:SetNoTarget(false)
						self.Owner:DrawWorldModel( true ) 
				self:SetNetworkedBool( "Katana_View_Cloak", false )		
				self.Cloaked = false
	end)

end

What is line 288? What are a few lines before line 288, and a few lines after?

Also paste a few lines before, and after for line 97 too.

You could of pasted it into Notepad Acecool, c’mon.

[lua]
self.Owner:DrawWorldModel( false )
[/lua]

That needs to be replaced with:

[lua]
if SERVER then self.Owner:DrawWorldModel( false ) end
[/lua]

It’s a server side only function as far as I know, so your probably getting an error on the client because it doesn’t exist, but it then runs fine on the server version.

Also, you should add IsValid( self.Owner ) check.

wow this really worked like a charm, although… as soon as I saw the answer I smacked my forehead. :stuck_out_tongue: Thanks guys. Your the best.