SWEP troubles.


// Variables that are used on both client and server
SWEP.Instructions			= "Uses .45Acp ammo"
SWEP.Base 				= "modern_base"
SWEP.HoldType				= "pistol"
SWEP.ViewModelFOV			= 70
SWEP.ViewModelFlip		= true
SWEP.ViewModel			= "models/weapons/v_what_deagle.mdl"
SWEP.WorldModel			= "models/weapons/w_colt_deagle.mdl"

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true

SWEP.Primary.Sound 		= Sound("weapons/what/deagle-1.wav")
SWEP.Primary.Recoil		= 2.9
SWEP.Primary.Damage		= 99
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.0182
SWEP.Primary.Delay 		= 0.12

SWEP.Primary.ClipSize		= 10					// Size of a clip
SWEP.Primary.DefaultClip	= 10					// Default number of bullets in a clip
SWEP.Primary.Automatic		= false				// Automatic/Semi Auto
SWEP.Primary.Ammo			= "SniperPenetratedRound"

SWEP.Secondary.ClipSize		= -1					// Size of a clip
SWEP.Secondary.DefaultClip	= -1					// Default number of bullets in a clip
SWEP.Secondary.Automatic	= false				// Automatic/Semi Auto
SWEP.Secondary.Ammo		= "none"

SWEP.ShellEffect			= "effect_umb_shell_pistol"	// "effect_mad_shell_pistol" or "effect_mad_shell_rifle" or "effect_mad_shell_shotgun"
SWEP.ShellDelay			= 0.02

SWEP.Pistol				= true
SWEP.Rifle				= false
SWEP.Shotgun			= false
SWEP.Sniper				= false

SWEP.IronSightsPos = Vector (2.1881, -6.8981, 0.1186)
SWEP.IronSightsAng = Vector (0, 0, 0)

SWEP.RunArmOffset 		= Vector (0.1703, 0, 3.2242)
SWEP.RunArmAngle 			= Vector (-29.6614, 0.5052, 0.0057)

/*---------------------------------------------------------
   Name: SWEP:Precache()
   Desc: Use this function to precache stuff.
---------------------------------------------------------*/
function SWEP:Precache()

    	util.PrecacheSound("weapons/Colt/Colt-1.wav")
end

function SWEP:RDSightchange()
self.IronSightsPos = Vector (0.8701, -9.6045, 0.0206)
self.IronSightsAng = Vector (0, 0, 0)
PrintMessage( HUD_PRINTCENTER, "Red Dot" )
end

function SWEP:AcogSightchange()
self.IronSightsPos = Vector (2.1881, -6.8981, 0.1186)
self.IronSightsAng = Vector (0, 0, 0)
PrintMessage( HUD_PRINTCENTER, "Acog" )
end

concommand.Add( "RedDotSight", RDSightchange )
concommand.Add( "AcogSight", AcogSightchange )

I’m getting the error “Console command not found”, so if anyone can help me with this, or tell me a different way to switch ironsight positions.

You cant call functions that are associated with weapons via console commands like that.
And why can’t you do this through key binds in the think hook? AKA in the think hook, check if the a key is down, and do the appropriate function.

Thanks for the fast reply, and i didnt even think of that. I usually dont do much advanced stuff swep wise, and do you think you can give me an example of the think hook key press? Or a link on the wiki?

Keys List

[lua]
function SWEP:Think()
if( player:KeyDown( IN_FORWARD ) ) then
Msg( "You pressed the forward key!
" )
end
end
[/lua]
[editline]14th July 2012[/editline]

Due to the nature of the Think, you will more than likely have to have other checks/cooldowns to prevent it from being called hundreds of times.