SWEP help

am not sure why my swep dosent work right

so the problem is the hold type well not work
no matter what i set it to it is allways on pistol for some reason

how would i fix this?


local soundData = {
    name                = "Weapon_tosater.Magin" ,
    channel     = CHAN_WEAPON,
    volume              = 1,
    soundlevel  = 150,
    pitchstart  = 100,
    pitchend    = 100,
    sound               = "weapons/toaster/toaster_pushed_down.wav"
}
sound.Add(soundData)

local soundData = {
    name                = "Weapon_tosater.Magout" ,
    channel     = CHAN_WEAPON,
    volume              = 1,
    soundlevel  = 150,
    pitchstart  = 100,
    pitchend    = 100,
    sound               = "weapons/toaster/toaster_push_down.wav"
}
sound.Add(soundData)
if ( SERVER ) then
	AddCSLuaFile( "shared.lua" )
	SWEP.HoldType			= "ar2"
end

if ( CLIENT ) then
	SWEP.PrintName		= "TosterGun"
	SWEP.Author		    = "Jenssons"
	SWEP.Purpose		= ""
	SWEP.ViewModelFOV	= "70"
	SWEP.Instructions	= "meow"
	SWEP.Slot				= 1
	SWEP.SlotPos			= 1
end

SWEP.Category = "Jenssons" 
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_toastergun_gun.mdl"
SWEP.WorldModel			= "models/weapons/w_toastergun_gun.mdl"
SWEP.ViewModelFlip = false

SWEP.Primary.ClipSize = 1
SWEP.Primary.ClipMax = 1
SWEP.Primary.DefaultClip = 4
SWEP.Primary.Recoil			= 0.7
SWEP.Primary.Damage			= 26
SWEP.Primary.NumShots		= 2
SWEP.Primary.Cone			= 0.06
SWEP.Primary.Delay = 0.12
SWEP.Primary.Automatic   = true
SWEP.Primary.Ammo		= "RPG_Round"
SWEP.Primary.TakeAmmo = 1
SWEP.Primary.Model = "models/Jenssons/Ncat.mdl"

SWEP.UseHands = true

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

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

local FireSound 		= Sound ("weapons/toaster/toaster_pop_up.wav");

function SWEP:Initialize()
	if ( SERVER ) then
		self:SetNPCMinBurst( 10 )
		self:SetNPCMaxBurst( 10 )
		self:SetNPCFireRate( 0.01 )
	end
	self.Weapon:SetNetworkedBool( "Ironsights", false )
end

function SWEP:PrimaryAttack()
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	if ( !self:CanPrimaryAttack() ) then return end
	self.Weapon:EmitSound( FireSound )
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self:FireRocket() --self:FireRocket( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
	self:TakePrimaryAmmo( 1 )
	if ( self.Owner:IsNPC() ) then return end
	self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
	if ( (game.SinglePlayer() && SERVER) || CLIENT ) then
		self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
	end
end

function SWEP:FireRocket()
	local aim = self.Owner:GetAimVector()
	local side = aim:Cross(Vector(0,0,1))
	local up = side:Cross(aim)
	local pos = self.Owner:GetShootPos() +  aim * 60 + side * 6 + up * -5	--offsets the rocket so it spawns from the muzzle (hopefully)
	local pos2 = self.Owner:GetShootPos() +  aim * 60 + side * 12 + up * -5	--offsets the rocket so it spawns from the muzzle (hopefully)
	if SERVER then
		rocket = ents.Create("nyan_rocket")
		if !rocket:IsValid() then 
		return
		else
		rocket:SetAngles(aim:Angle())
		rocket:SetPos(pos)
	rocket:SetOwner(self.Owner)
	rocket:Spawn()
	rocket:Activate()
	rocket:SetVelocity(rocket:GetForward()*2500)
	local trail = util.SpriteTrail(rocket, 0, Color(255,255,255), false, 15, 1, 4, 1/(15+1)*0.5, "nyan/rainbow.vmt")
 
	rocket2 = ents.Create("nyan_rocket")
	end
		if !rocket2:IsValid() then 
		return
		else
		rocket2:SetAngles(aim:Angle())
		rocket2:SetPos(pos2)
	rocket2:SetOwner(self.Owner)
	rocket2:Spawn()
	rocket2:Activate()
	rocket2:SetVelocity(rocket2:GetForward()*2500)
		local trail = util.SpriteTrail(rocket2, 0, Color(255,255,255), false, 15, 1, 4, 1/(15+1)*0.5, "nyan/rainbow.vmt")
 
	end
end
end

function SWEP:Think()
	if self.Weapon:Clip1() > 0 then
		self.Weapon:SendWeaponAnim(ACT_VM_IDLE_DEPLOYED)
	end
end

function SWEP:Reload()
	if (self.Weapon:Clip1() < self.Primary.ClipSize) then
		if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then

		end
		self.Weapon:DefaultReload( ACT_VM_RELOAD );
	end
end

as you see i have it set to ar2 but in game he still holds it like a pistol IDK WHY ;-;

SWEP.HoldType doesn’t set the holdtype. Add self:SetHoldType( self.HoldType ) in your Initialize method.


function SWEP:Initialize()
	if ( SERVER ) then
		self:SetNPCMinBurst( 10 )
		self:SetNPCMaxBurst( 10 )
		self:SetNPCFireRate( 0.01 )
	end
	self.Weapon:SetNetworkedBool( "Ironsights", false )
	self:SetHoldType( self.HoldType )
end

[ERROR] addons/toastergun/lua/weapons/toastergun/shared.lua:81: bad argument #1 to ‘SetHoldType’ (string expected, got nil)

  1. SetHoldType - [C]:-1
  2. unknown - addons/toastergun/lua/weapons/toastergun/shared.lua:81

SWEP.HoldType should be shared, not just serverside.

it worked :smiley: thank you so much