Weapon Issue

Warning messy code

The Error




[ERROR] addons/birdguns/lua/weapons/weapon_bg_base/shared.lua:213: bad argument #1 to 'SetModelScale' (number expected, got userdata)
  1. SetModelScale - [C]:-1
   2. MakeViewModel - addons/birdguns/lua/weapons/weapon_bg_base/shared.lua:213
    3. First - addons/birdguns/lua/weapons/weapon_bg_base/shared.lua:259
     4. unknown - addons/birdguns/lua/weapons/weapon_bg_base/shared.lua:300





if(SERVER)then
	AddCSLuaFile("shared.lua")
end

if(CLIENT)then
	SWEP.DrawAmmo			=false
	SWEP.DrawCrosshair		=false
	SWEP.ViewModelFOV		=89
	
	SWEP.PrintName			="birdgun_base"
	SWEP.Author				=""
	SWEP.Slot				=3
	SWEP.SlotPos			=1
	
	SWEP.ViewModelFlip		=true
	
	SWEP.SwayScale			=-1.5
	SWEP.BobScale			=-1.5
	
	SWEP.iconchar			="b"
	SWEP.scope				=nil
	
	surface.CreateFont("birdguns_select", {
	    font = "cs",
		size = ScreenScale(60),
		weight = 500,
		antialias = true,
		aditive = true
	})
	
	surface.CreateFont("hl238", {
	    font = "HALFLIFE2",
		size = 38,
		weight = 700,
		antialias = true,
		aditive = false
	})
	
	local vmodel=nil
	local viewpos=Vector(0,0,0)
end

SWEP.Author			=""
SWEP.Contact		=""
SWEP.Purpose		=""
SWEP.Instructions	=""

SWEP.Spawnable				=false
SWEP.AdminSpawnable			=false

SWEP.ViewModel			="models/weapons/v_rif_ak47.mdl"
SWEP.WorldModel			="models/weapons/w_rif_ak47.mdl"

SWEP.Weight				=5
SWEP.AutoSwitchTo		=false
SWEP.AutoSwitchFrom		=false

SWEP.Primary.ClipSize 	=-1
SWEP.Primary.DefaultClip=-1
SWEP.Primary.Automatic	=false
SWEP.Primary.Ammo		="none"
SWEP.CSMuzzleFlashes	=true
 
SWEP.Secondary.ClipSize	=-1
SWEP.Secondary.DefaultClip=-1
SWEP.Secondary.Automatic=false
SWEP.Secondary.Ammo		="none"

SWEP.holdtype		="ar2"

SWEP.sound			=Sound("Weapon_UMP45.Single")
SWEP.recoil			=1.5
SWEP.damage			=7
SWEP.magazine		=20
SWEP.force			=10
SWEP.bullets		=1
SWEP.spread			=0.02
SWEP.delay			=0.2
SWEP.reloadtime		=3
SWEP.deploytime		=1

SWEP.burst			=1
SWEP.burstdelay		=0.05

SWEP.automatic		=true
SWEP.ammo			="pistol"
SWEP.ammoused		=1

SWEP.attackanim		=ACT_VM_PRIMARYATTACK
SWEP.reloadanim		=ACT_VM_RELOAD
SWEP.deployanim		=ACT_VM_DRAW
SWEP.idleanim		=ACT_VM_IDLE

function SWEP:Initialize()
	self:SetWeaponHoldType(self.holdtype)
	self.Weapon.lastshoot=CurTime()+self.deploytime
	self.Weapon.shootarray={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
	self.Weapon.shooti=1
	
	self.Weapon.deployed=nil
end

function SWEP:Reload()
	if(self.Weapon.ammoc==self.magazine)then return end
	if(CurTime()<self.Weapon.lastshoot+self.delay)then return end
	if not(tobool(self.Owner.ammo[self.ammo]))then return end
	
	self.Weapon.lastshoot=CurTime()
	
	local ammo
	if(CLIENT)then
		ammo=self.Owner.ammo[self.ammo]
	else
		ammo=birdguns_getammo(self.Owner,self.ammo)
	end
	
	if not(tobool(ammo))then return end
	if(ammo==self.Weapon.ammoc)then return end
	
	
	if(ammo>=self.magazine)then
		self.Weapon.ammoc=self.magazine
	else
		self.Weapon.ammoc=ammo
	end

	self.Weapon.lastshoot=CurTime()+self.reloadtime
	
	self.Weapon:SendWeaponAnim(self.reloadanim)
	if(CLIENT)then
		if(IsValid(vmodel))then
			vmodel:ResetSequenceInfo()
			vmodel:SetCycle(0)
			vmodel:ResetSequence(self.Owner:GetViewModel():GetSequence())
		else
			self:MakeViewModel()
		end
	else
		birdguns_replicateammo(self.Owner,self.ammo)
	end
end

//if(CLIENT)then

local function drawviewmodel()
	if(SERVER)then return end
	
	if not(IsValid(vmodel))then return end
	
	if(vmodel.frame<CurTime())then
		vmodel:FrameAdvance()
		vmodel.frame=CurTime()+RealFrameTime()*0.5
	end
	
	if(vmodel.scoped)then return end
	
	if(LocalPlayer():GetActiveWeapon()!=vmodel.weapon)then
		if(IsValid(LocalPlayer():GetActiveWeapon()))then
			LocalPlayer():GetViewModel():SetColor(255,255,255,255)
		end
		vmodel.weapon.deployed=nil
		vmodel=nil
		return
	end
	
	local ang=LocalPlayer():EyeAngles()
	
	if(vmodel.flip)then
		ang.p=ang.p*-1
		ang=ang+Angle(0,180,0)
	end
	
	local fov=vmodel.fov
	
	cam.Start3D(viewpos,ang,fov)
		cam.IgnoreZ(true)
		
		if(vmodel.flip)then
			render.CullMode(MATERIAL_CULLMODE_CW)
		end
		
		render.SetBlend(1)
		render.SetColorModulation(1,1,1)

		vmodel:SetColor(Color(255,255,255,255))
		vmodel:DrawModel()
			
		if(vmodel.flip)then
			render.CullMode(MATERIAL_CULLMODE_CCW)
		end
		
		cam.IgnoreZ(false)
	cam.End3D()
end

//end

function SWEP:MakeViewModel()
	if(SERVER)then return end
	
	vmodel=ClientsideModel(self.ViewModel,RENDERGROUP_OPAQUE)
	vmodel:Spawn()
		
	vmodel:SetNoDraw(true)
	vmodel:SetParent(self.Owner:GetViewModel())
	vmodel:SetPos(self.Owner:GetViewModel():GetPos())
	vmodel:SetAngles(self.Owner:GetViewModel():GetAngles())
	vmodel:ResetSequenceInfo()
	vmodel:SetCycle(0)
	vmodel:ResetSequence(self.Owner:GetViewModel():GetSequence())
		
	if(self.ViewModelFlip)then
		vmodel:SetModelScale(Vector(-1,1,1))
	end
	
	vmodel.weapon=self.Weapon
	vmodel.fov=self.ViewModelFOV
	vmodel.flip=self.ViewModelFlip
	vmodel.frame=CurTime()+FrameTime()
	
	self.Weapon.vmodel=vmodel
	
	hook.Add("PostDrawTranslucentRenderables","birdwep_drawviewmodel",drawviewmodel)
end

function SWEP:First()
	self.Weapon.lastshoot=CurTime()+self.deploytime
	
	if not(self.Owner.ammo)then
		self.Owner.ammo={}
	end
	
	if not(self.Owner.ammo[self.ammo])then
		self.Owner.ammo[self.ammo]=0
	end
		
	if(SERVER)then
		local ammo=birdguns_getammo(self.Owner,self.ammo)
		
		if not(self.Weapon.ammoc)then
			if(ammo>=self.magazine)then
				self.Weapon.ammoc=self.magazine
			else
				self.Weapon.ammoc=ammo
			end
		elseif(self.Weapon.ammoc>ammo)then
			self.Weapon.ammoc=ammo
		end
		
		self.Owner.ammo[self.ammo]=ammo
		
		birdguns_replicateammo(self.Owner,self.ammo)
	end
	
	self.Weapon:SendWeaponAnim(self.deployanim)
	
	if(CLIENT)then
		if not(IsValid(vmodel))then
			self:MakeViewModel()
		end
	end
end

function SWEP:Deploy()
	
end

function SWEP:OnRemove()
	if(CLIENT)then
		if(IsValid(self.Owner))then
			if(IsValid(self.Owner:GetViewModel()))then
				self.Owner:GetViewModel():SetColor(255,255,255,255)
			end
		end
		if(IsValid(vmodel))then vmodel:Remove() end
		vmodel=nil
	end
	
	self.Weapon.deployed=nil
end

function SWEP:Holster()
	if(CLIENT)then
		if(IsValid(self.Owner:GetViewModel()))then
			self.Owner:GetViewModel():SetColor(255,255,255,255)
		end
		if(IsValid(vmodel))then vmodel:Remove() end
		vmodel=nil
		self.Weapon.drawscope=false
	end
	
	self.Weapon.deployed=nil
	
	return true
end

function SWEP:Think()

	if not(self.Weapon.deployed)then
		self.Weapon:First()
		self.Weapon.deployed=true
	end
	
	if(CLIENT)then
		if not(IsValid(vmodel))then
			self:MakeViewModel()
		end
	
		local ammo=self.Owner.ammo[self.ammo]
	
		if not(self.Weapon.ammoc)then
			if(tobool(ammo))then
				if(ammo>=self.magazine)then
					self.Weapon.ammoc=self.magazine
				else
					self.Weapon.ammoc=ammo
				end
			end
		elseif(self.Weapon.ammoc>ammo)then
			self.Weapon.ammoc=ammo
		end
	end
	
	if(tobool(self.Weapon.ammoc))then
		if(self:CanPrimaryAttack())then
			self.Weapon:SendWeaponAnim(self.idleanim)
		end
	end

	/*if(self.automatic and self.Owner:KeyDown(IN_ATTACK))then
		self.Weapon.allowattack=true
		//self.Weapon:PrimaryAttack()
	else
		if(self.Owner:KeyDown(IN_ATTACK))then
			if(self.Weapon.allowattack)then
				//self.Weapon:PrimaryAttack()
				self.Weapon.allowattack=false
			end
		else
			self.Weapon.allowattack=true
		end
	end*/
	
	if(self.automatic and self.Owner:KeyDown(IN_ATTACK) and self.Weapon.nextfire)then
		if(self.Weapon.nextfire<CurTime())then
			self.Weapon:PrimaryAttack()
		end
	end

	local i
	
	for i=1,16 do
		if(CurTime()>self.Weapon.shootarray*)then
			if(self.Weapon.shootarray*!=0)then
				self.Weapon.shootarray*=0
				self.Weapon:ShootBullet()
			end
		end
	end
	
	self.Weapon:NextThink(CurTime())	
	return true
end

function SWEP:CanPrimaryAttack()
	if(CurTime()<self.Weapon.lastshoot+self.delay)then
		return false
	end
	
	if not(tobool(self.Weapon.ammoc))then
		self:EmitSound("Weapon_Pistol.Empty")
		self.Weapon.lastshoot=CurTime()+0.3
		return false
	end
	
	//return self.Weapon.allowattack
	return true
end

function SWEP:ShootBullet()
	local bullet = {}
	bullet.Num 		=self.bullets
	bullet.Src 		=self.Owner:GetShootPos()
	bullet.Dir 		=self.Owner:GetAimVector()
	bullet.Spread 	=Vector(self.spread,self.spread,0)
	bullet.Tracer	=1
    bullet.TracerName="Tracer"
	bullet.Force	=self.force
	bullet.Damage	=self.damage
	
	if(self.Weapon.ammoc>0)then
		self.Owner:FireBullets(bullet)
		self.Weapon.ammoc=self.Weapon.ammoc-self.ammoused
	end
	
	if(SERVER)then
		birdguns_takeammo(self.Owner,self.ammo,self.ammoused)
		birdguns_replicateammo(self.Owner,self.ammo)
	end
	
	self.Weapon:EmitSound(self.sound)
	self.Owner:SetAnimation(PLAYER_ATTACK1)

	self.Weapon:SendWeaponAnim(self.attackanim)
	if(CLIENT)then
		if(IsValid(vmodel))then
			vmodel:ResetSequenceInfo()
			vmodel:SetCycle(0)
			vmodel:ResetSequence(self.Owner:GetViewModel():GetSequence())
		else
			self:MakeViewModel()
		end
	end
	self.Owner:MuzzleFlash()

	self.Owner:ViewPunch(Angle(math.Rand(-0.1,-0.4)*self.recoil,math.Rand(-0.2,0.2)*self.recoil,0))
	
	if(CLIENT)then
		local ang=self.Owner:EyeAngles()+Angle(math.Rand(-0.2,-1.4)*self.recoil,math.Rand(-0.6,0.6)*self.recoil,0)
		ang.p=math.Clamp(ang.p or 0,-88,88)
		self.Owner:SetEyeAngles(ang)
	end
end

function SWEP:AddBullet(delay)
	self.Weapon.shootarray[self.Weapon.shooti]=delay+CurTime()
	self.Weapon.shooti=self.Weapon.shooti+1
	
	if(self.Weapon.shooti>16)then self.Weapon.shooti=1 end
end

function SWEP:PrimaryAttack()
	if not(self:CanPrimaryAttack())then return end

	if(self.automatic)then
		self.Weapon.nextfire=CurTime()+self.delay
	end
	
	self.Weapon.lastshoot=CurTime()
	
	self:ShootBullet()
	
	local i
	
	for i=1,self.burst-1 do
		self:AddBullet(i*self.burstdelay)
	end
	
end

function SWEP:GetViewModelPosition(pos,ang)
	viewpos=pos
	if(IsValid(self.Owner:GetViewModel()))then
		self.Owner:GetViewModel():SetColor(0,0,0,0)
	end
	return pos,ang
end

function SWEP:SecondaryAttack()
	/*if(CLIENT)then
		if not(self.scope)then return end
		
		self.Weapon.drawscope=!self.Weapon.drawscope
		if(IsValid(vmodel))then
			vmodel.scoped=self.Weapon.drawscope
		end
	end*/
end

function SWEP:TranslateFOV(fov)
	if not(self.scope)then return fov end
	
	//if(self.Weapon.drawscope)then return self.scope end
	if(LocalPlayer():KeyDown(IN_ATTACK2))then
		self.Weapon.drawscope=true
		if(IsValid(vmodel))then
			vmodel.scoped=true
		end
		return self.scope
	else
		self.Weapon.drawscope=false
		if(IsValid(vmodel))then
			vmodel.scoped=nil
		end
		return fov
	end
	
	return fov
end

function SWEP:AdjustMouseSensitivity()
	if(self.Weapon.drawscope)then
		return 0.25
	end
end

function SWEP:DrawWeaponSelection(x,y,wide,tall,alpha)
	draw.SimpleText(self.iconchar,"birdguns_select",x+wide/2,y-4+tall*0.17,Color(255,210,0,255),TEXT_ALIGN_CENTER)
end

function SWEP:DrawHUD()
	//CROSSHAIR

	local x,y=ScrW()/2,ScrH()/2
	local quad={}
	
	//SCOPE
	if(self.Weapon.drawscope)then
		local zy=x/2
		local zx=zy*1.25
		
		quad.color=Color(0,0,0,255)
		/*quad.texture=surface.GetTextureID("gmod/scope-refract")
		quad.x=x-(zx*1.25)
		quad.y=y-zx
		quad.w=x*1.5625
		quad.h=x*1.25
		draw.TexturedQuad(quad)*/
		
		quad.texture=surface.GetTextureID("gmod/scope")
		quad.x=x-zx
		quad.y=y-zy
		quad.w=x*1.25
		quad.h=x
		draw.TexturedQuad(quad)
		
		surface.SetDrawColor(0,0,0,255)
		
		surface.DrawRect(0,0,x-zx,y*2)
		surface.DrawRect(x+zx,0,x-zx,y*2)
		
		surface.DrawRect(x-zx,0,x*1.25,y-zy)
		surface.DrawRect(x-zx,y+zy,x*1.25,y-zy)
		
		surface.DrawLine(x,0,x,y*2)
		surface.DrawLine(0,y,x*2,y)
		
		surface.DrawLine(x-16,y-4,x-16,y+4)
		surface.DrawLine(x+16,y-4,x+16,y+4)
		surface.DrawLine(x-4,y-16,x+4,y-16)
		surface.DrawLine(x-4,y+16,x+4,y+16)
		
	else//REGULAR CROSSHAIR
		local scale=math.Clamp(self.spread or 0,0.01,0.3)*14
	
		scale=scale+(math.Clamp(CurTime()-0.2-self.Weapon.lastshoot,-0.2,0)*-2.7)
		
		surface.SetDrawColor(200,180,0,255)

		local gap=40*scale
		local length=gap+20*scale
		surface.DrawLine(x-length,y,x-gap,y)
		surface.DrawLine(x+length,y,x+gap,y)
		surface.DrawLine(x,y-length,x,y-gap)
		surface.DrawLine(x,y+length,x,y+gap)
	end
	
	
	//AMMO
	
	x,y=ScrW(),ScrH()
 
 	quad.texture=surface.GetTextureID("vgui/gradient-r")
 	quad.color	=Color(255,210,0,255) 
 
 	quad.x 		=x-(x/5)
 	quad.y 		=y-8
 	quad.w 		=x/5
 	quad.h 		=4
 	draw.TexturedQuad(quad)
	
 	quad.y 		=y-44
 	draw.TexturedQuad(quad)
	
	quad.x 		=x-(x/7)
 	quad.y 		=y-64
 	quad.w 		=x/7
 	quad.h 		=4
 	draw.TexturedQuad(quad)
	
	quad.color	=Color(0,0,0,200)
	quad.x 		=x-(x/5)
	quad.y 		=y-40
	quad.w 		=x/10
	quad.h=32
	draw.TexturedQuad(quad)
	
	surface.SetDrawColor(0,0,0,200)
	surface.DrawRect(x-(x/10),y-40,x/10,32)
	
	if not(self.Owner.ammo)then return end

	surface.SetFont("hl238")
	surface.SetTextColor(255,220,0,160)
	surface.SetTextPos(x-(x/12)-6,y-45)
	surface.DrawText(tostring(self.Weapon.ammoc or 0).." / "..tostring(math.Clamp(self.Owner.ammo[self.ammo] or 0,0,9999)))
	
	local w=(x/10)*((self.Weapon.ammoc or 0)/self.magazine)
	surface.SetDrawColor(255,210,0,128)	
	surface.DrawRect(x-w,y-58,w,12)
end
 



Found what i did wrong /locked