Models not attaching to SWEP in spectator mode

Hello, I have currently designed a very basic model to use on a gun.

It works flawlessly apart from when you spectate someone holding it, here is a screenshot;

I downloaded the P.E.B SWEP from the workshop and used that as my base code, here is the code I currently use;

[lua]
SWEP.ViewModel = “models/weapons/c_rpg.mdl”
SWEP.WorldModel = “models/weapons/w_357.mdl”
SWEP.Base = “weapon_tttbase”

SWEP.Primary.Sound = Sound(“buttons/combine_button3.wav”)
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 5
SWEP.Primary.Force = 100
SWEP.Primary.NumShots = 1
SWEP.Primary.Delay = 0.2
SWEP.Primary.Ammo = “357”

SWEP.Primary.ClipSize = 9999999
SWEP.Primary.DefaultClip = 999999
SWEP.Primary.Automatic = true

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

SWEP.UseHands = true
SWEP.IronSightsPos = Vector(-5.613, -3.77, 2.559)
SWEP.IronSightsAng = Vector(0, 0, 0)

SWEP.RestoreSound = Sound( “buttons/combine_button3.wav” )
SWEP.LastPrimaryAttack = 0

function SWEP:Initialize()

self:SetWeaponHoldType(self.HoldType)
self.Weapon:SetNetworkedBool( "Ironsights", false )

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
    
    self.MoveDis = 0.4
    //self.VElements["switch"].orig_x = self.VElements["switch"].pos.x
    //self.VElements["switchr"].orig_x = self.VElements["switchr"].pos.x
end

end

function SWEP:SetupDataTables()

self:DTVar( "Entity", 0, "laser" )

end

function SWEP:Think()

if (CLIENT and IsValid(self.Owner)) then

    if (self.LastPrimaryAttack < CurTime() - 1 ) then
    
        //local x1 = self.VElements["switch"].pos.x
        //local x2 = self.VElements["switchr"].pos.x
        //local t1 = self.VElements["switch"].orig_x
        //local t2 = self.VElements["switchr"].orig_x
        
        //self.VElements["switch"].pos.x = math.Approach(x1, t1, FrameTime()*self.MoveDis)
        //self.VElements["switchr"].pos.x = math.Approach(x2, t2, FrameTime()*self.MoveDis)
        
    end
    
    local laser = self:GetLaser()
    if (IsValid(laser) and laser.CorrectBeamStart) then
        laser:CorrectBeamStart( self.LastBeamStart )
    end
    
end

end

function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
if not self:CanPrimaryAttack() then return end

self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:SetAnimation(PLAYER_ATTACK1)

self:EmitSound( self.Primary.Sound )
self:TakePrimaryAmmo( 1 )
self:Recoil()
//self.LastPrimaryAttack = CurTime()

self:ReloadCheck()

if (SERVER) then
    local laser = ents.Create( "rc_laser" )
    if (IsValid(laser)) then
        laser:SetPos(self.Owner:GetShootPos())
        laser:Spawn()
        laser:SetOwner(self.Owner)
        laser:SetParent(self.Owner)
        laser:SetWeapon( self )
        laser:SetLaserProperties( "sprites/laserbeam", self.Primary.Damage, 8, Color(0,255,0) )
        
        self.dt.laser = laser
    end
    
    self.Owner:SendLua( "LocalPlayer():GetActiveWeapon():ClientPrimary()" )
end

end

function SWEP:ClientPrimary()

self.LastPrimaryAttack = CurTime()

/*local vm = self.Owner:GetViewModel()
if (IsValid(vm)) then
    local attachment = vm:GetAttachment( 1 )
    self.LastBeamStart = attachment.Pos
end*/ // somehow totally fucked, while it worked in multiplayer

local angles = self.Owner:EyeAngles()
local pos = self.Owner:GetShootPos()
    
if (self:GetNWBool("Ironsights", false)) then
    pos = pos + angles:Forward()*15
else
    pos = pos + angles:Right()*3
    pos = pos + angles:Up()*-1.8
    pos = pos + angles:Forward()*15
end

self.LastBeamStart = pos

//self.VElements["switch"].pos.x = self.VElements["switch"].orig_x + self.MoveDis
//self.VElements["switchr"].pos.x = self.VElements["switchr"].orig_x - self.MoveDis

timer.Simple( 1, function()
    if (IsValid(self)) then self:EmitSound( self.RestoreSound ) end
end)

// make the bullets disappear
timer.Simple(0.1, function()
    if (!IsValid(self)) then return end
    local pred = self:Clip1()
    if (pred == 0) then
        //self.VElements["bullet1"].hide = true
        //self.VElements["glow"].hide = true
    else
        for i = 1, (6 - pred) do
            //self.VElements["bullet1"..string.rep("+",i)].hide = true
            //self.VElements["glow"..string.rep("+",i)].hide = true
        end
    end
end)

end

function SWEP:Recoil()

//local recoil = self.Primary.Recoil
//local recoilAng = Angle(math.Rand(-0.25,-0.2) * recoil, math.Rand(-0.1,0.1) * recoil, math.Rand(-0.07, 0.07) * recoil)
//self.Owner:ViewPunch(recoilAng)

end

function SWEP:Reload()

//self.Weapon:DefaultReload( ACT_VM_RELOAD )
self.Weapon:DefaultReload( ACT_VM_IDLE )
self:SetIronsights( false )

self:OnReloadStart()

if (!IsValid(self.Owner)) then return end
if (SERVER) then
    self.Owner:SendLua( "Entity("..self:EntIndex().."):OnReloadStart()" )
end

local animTime = self.Owner:GetViewModel():SequenceDuration()
timer.Simple( animTime, function()
    if (!IsValid(self)) then return end
    self:SendWeaponAnim( ACT_VM_IDLE )
end)

end

function SWEP:OnReloadStart()

if CLIENT then
    timer.Simple( 2, function()
        if !IsValid(self) then return end
        //self.VElements["bullet1"].hide = false
        //self.VElements["glow"].hide = false
        for i = 1, math.min(5, self.Owner:GetAmmoCount(self:GetPrimaryAmmoType())-1) do
            //self.VElements["bullet1"..string.rep("+",5-(i-1))].hide = false
            //self.VElements["glow"..string.rep("+",5-(i-1))].hide = false
        end
    end)
end

end

function SWEP:GetLaser()
local laser = self.dt.laser
if (!IsValid(laser)) then return nil
else return laser end
end

function SWEP:ReloadCheck()

timer.Destroy("reloadcheck"..self:EntIndex())
timer.Create("reloadcheck"..self:EntIndex(),0.5,1,function()
    if (IsValid(self) and IsValid(self.Owner) and self:Clip1() == 0) then
        self:SetIronsights(false)
        self:Reload()
    end
end)

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

return true

end

function SWEP:OnRemove()
self:Holster()
end

/---------------------------------------------------------
onRestore
Loaded a saved game (or changelevel)
---------------------------------------------------------
/
function SWEP:OnRestore()

self.NextSecondaryAttack = 0
self:SetIronsights( false )

end

local IRONSIGHT_TIME = 0.25

/---------------------------------------------------------
Name: GetViewModelPosition
Desc: Allows you to re-position the view model
---------------------------------------------------------
/
function SWEP:GetViewModelPosition( pos, ang )

if ( !self.IronSightsPos ) then return pos, ang end

local bIron = self.Weapon:GetNetworkedBool( "Ironsights" )

if ( bIron != self.bLastIron ) then

    self.bLastIron = bIron 
    self.fIronTime = CurTime()
    
    if ( bIron ) then 
        self.SwayScale  = 0.3
        self.BobScale   = 0.1
    else 
        self.SwayScale  = 1.0
        self.BobScale   = 1.0
    end

end

local fIronTime = self.fIronTime or 0

if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then 
    return pos, ang 
end

local Mul = 1.0

if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then

    Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 )
    
    if (!bIron) then Mul = 1 - Mul end

end

local Offset    = self.IronSightsPos

if ( self.IronSightsAng ) then

    ang = ang * 1
    ang:RotateAroundAxis( ang:Right(),      self.IronSightsAng.x * Mul )
    ang:RotateAroundAxis( ang:Up(),         self.IronSightsAng.y * Mul )
    ang:RotateAroundAxis( ang:Forward(),    self.IronSightsAng.z * Mul )


end

local Right     = ang:Right()
local Up        = ang:Up()
local Forward   = ang:Forward()



pos = pos + Offset.x * Right * Mul
pos = pos + Offset.y * Forward * Mul
pos = pos + Offset.z * Up * Mul

return pos, ang

end

/---------------------------------------------------------
SetIronsights
---------------------------------------------------------
/
function SWEP:SetIronsights( b )

self.Weapon:SetNetworkedBool( "Ironsights", b )

end

SWEP.NextSecondaryAttack = 0
/---------------------------------------------------------
SecondaryAttack
---------------------------------------------------------
/
function SWEP:SecondaryAttack()

if ( !self.IronSightsPos ) then return end
if ( self.NextSecondaryAttack > CurTime() ) then return end

bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false )

self:SetIronsights( bIronsights )

self.NextSecondaryAttack = CurTime() + 0.3

end

if CLIENT then

surface.CreateFont( "HL2MPSelectIcons", {
    font        = "HL2MP",
    size        = ScreenScale(60),
    weight      = 500,
    blursize    = 0,
    scanlines   = 0,
    antialias   = true,
    underline   = false,
    italic      = false,
    strikeout   = false,
    symbol      = false,
    rotary      = false,
    shadow      = false,
    additive    = true,
    outline     = false
} )

/*---------------------------------------------------------
    Checks the objects before any action is taken
    This is to make sure that the entities haven't been removed
---------------------------------------------------------*/
function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
    
    draw.SimpleText( self.IconLetter, "HL2MPSelectIcons", x + wide/2, y + tall*0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
    
end

/*********************
 Start of SCK base code
**********************/

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 of SCK base code
**********************/

function SWEP:AdjustMouseSensitivity()

    return nil
    
end

function SWEP:GetTracerOrigin()
    if (self:GetNetworkedBool( "Ironsights", false )) then return self.Owner:EyePos() end
end

function SWEP:DrawHUD()

end

end

/*
Laser!
*/

local ENT = {}

ENT.Type = “anim”
ENT.PrintName = “”
ENT.Author = “Clavus”
ENT.Purpose = “”

PrecacheParticleSystem( “striderbuster_break” )

HIT_EFFECT = {
SUPERBURN = 1,
ENERGYBLAST = 2
}

function ENT:GetLaserDamage()
return self:GetNWFloat(“damage”,10)
end

function ENT:GetLaserColor()

local col = Color(0,255,0,255)
local vec = self:GetNWVector("color")
if (vec) then
    col.r = vec.x
    col.g = vec.y
    col.b = vec.z
end

return col

end

function ENT:Active()
return self:GetNWBool( “active”, true )
end

function ENT:GetBeamSize()
return self:GetNWFloat( “beamsize”, 1.0 )
end

function ENT:HitEffect()
return self:GetNWInt(“hiteffect”,0)
end

function ENT:HitPos()
local hit = self:GetNWVector( “hitpos”, Vector(0,0,0) )
if (hit == Vector(0,0,0)) then return nil end
return hit
end

function ENT:Trace( start )

local pos = start or self:GetOwner():GetShootPos()

if (!self.AimAngle) then
    self.AimAngle = self:GetOwner():GetAimVector()
end

local trace = {}
trace.start = pos
trace.endpos = pos + self.AimAngle*20000
trace.filter = { self:GetOwner(), self:GetOwner():GetActiveWeapon() }

return util.TraceLine(trace)

end

if SERVER then

ENT.NextDamage = 0

function ENT:Initialize()

    self:DrawShadow( false )
    self:SetSolid( SOLID_NONE )
    self:SetNWBool("active", true)
    
end

function ENT:KillLaser()

    self:SetNWBool("active", false)
    timer.Simple( 1, function()
        if IsValid(self) then self:Remove() end
    end)
    
end

function ENT:SetWeapon( wep )

    self.Weapon = wep
    
end

function ENT:SetLaserProperties( mat, damage, beamsize, color )

    self:SetNWString("material", mat)
    self:SetNWFloat("damage", damage)
    self:SetNWFloat("beamsize", beamsize)
    self:SetNWVector("color", Vector(0,255,0))
    
end

function ENT:Think()

    if (!self:Active()) then return end

    local owner = self:GetOwner()
    local weapon
    
    if (IsValid(owner)) then
        weapon = owner:GetActiveWeapon()
    end
    
    if (!IsValid(owner) or !IsValid(weapon) or weapon != self.Weapon) then
        self:Remove()
        return
    end

    local tr = self:Trace()
    if (tr.Hit) then
        
        self:SetNWVector( "hitpos", tr.HitPos )
        
        if IsValid(tr.Entity) then

            local dmg = DamageInfo()
            dmg:SetDamage(self:GetLaserDamage())
            dmg:SetDamagePosition(tr.HitPos)
            dmg:SetDamageForce( owner:GetAimVector()*400 )
            dmg:SetDamageType( DMG_ENERGYBEAM )
            dmg:SetAttacker( owner )
            dmg:SetInflictor( weapon )
            
            tr.Entity:TakeDamageInfo( dmg )
            
        end
        
    end
    
    self:KillLaser()
    
    self:NextThink( CurTime() + 0.05 )

end

else

local matLight = Material( "models/roller/rollermine_glow" )
local matLaser

ENT.RenderGroup = RENDERGROUP_TRANSLUCENT

function ENT:Initialize()

    self.EffectDone = false
    self.LastTrace = nil
    self.DieTime = 0
    
end

function ENT:Think()
    
    local owner = self:GetOwner()
    if (IsValid(owner) and !self.LastTrace) then
        local tr = self:Trace(owner:EyePos())
        self.LastTrace = tr
        self:SetRenderBoundsWS( tr.HitPos, self:GetPos(), Vector()*8 )
    end
    
    if (IsValid(owner) and self.LastTrace and self:HitPos() and !self.EffectDone) then
        
        local tr = self.LastTrace
        local hitpos = self:HitPos() // correct to server hitpos
        
        ParticleEffect( "striderbuster_break", hitpos, tr.HitNormal:Angle() )
        //util.Decal( "Scorch", hitpos + tr.HitNormal, hitpos - tr.HitNormal )
        self.EffectDone = true
        
    end
    
end

function ENT:GetLaserMaterial()
    if (!matLaser) then
        local str = self:GetNWString("material","")
        if (str != "") then
            local params = {
                ["$basetexture"] = str,
                ["$spriteorientation"] = "vp_parallel",
                ["$spriteorigin"] = "[ 0.50 0.50 ]",
                ["$spriterendermode"] = "5"
            }

            matLaser = CreateMaterial(str.."ragnarokconflictlaser","Sprite",params)
        end
    end
    return matLaser
end

function ENT:DrawTranslucent()
    self:Draw()
end

function ENT:CorrectBeamStart( pos )
    
    self.BeamStart = pos    
    
end

function ENT:Draw()

    local owner = self:GetOwner()
    if (!IsValid(owner)) then return end
    
    local wep = owner:GetActiveWeapon()
    local colLaser = self:GetLaserColor()
    local mat = self:GetLaserMaterial()
    local beamsize = self:GetBeamSize()
    local active = self:Active()
    
    if (!active) then
        self.DieTime = self.DieTime + FrameTime() * 2
        beamsize = beamsize * math.max(0, 1 - self.DieTime)
    end    
    
    if (!(IsValid(owner) and mat)) then return end
    if (!IsValid(wep)) then return end
    
    if (!self.BeamStart) then return end
    if (!self.LastTrace) then return end
    
    render.SetMaterial( mat )
    
    // Draw the beam
    local colBeam = colorEx.Copy( colLaser )
    local colBeamInner = colorEx.Lighten( colBeam, 20 )
    
    colBeam.a = 150
    colBeamInner.a = 200
    
    local hitpos = self:HitPos() or self.LastTrace.HitPos
    
    if (beamsize > 0) then
        render.DrawBeam( hitpos, self.BeamStart, beamsize, 0, 0, colBeam )
        render.DrawBeam( hitpos, self.BeamStart, beamsize/3, 0, 0, colBeamInner )
    end
    
end

// some utility stuff
colorEx = {}
function colorEx.Copy( col )
    return Color( col.r, col.g, col.b, col.a )
end

function colorEx.Lighten( col, a )
    return Color( math.min(255, col.r + a), math.min(255, col.g + a), math.min(255, col.b + a), col.a )
end

end
scripted_ents.Register( ENT, “rc_laser”, true )
[/lua]

This strange bug only happens when you spectate someone holding that gun, when you hold it yourself, it is fine.