For real... I just want to make a gun.

Does anyone see what’s wrong with this code:

if (SERVER) then --the init.lua stuff goes in here

AddCSLuaFile (“shared.lua”);

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

end

if (CLIENT) then --the cl_init.lua stuff goes in here

SWEP.PrintName = “Famas Creation”;
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;

end

SWEP.Author = “Myself”;
SWEP.Contact = “”;
SWEP.Purpose = “”;
SWEP.Instructions = “Left-click to fire; right-click to fire bombs”;
SWEP.Category = “Creations”;

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;

SWEP.ViewModel = “models/weapons/v_rif_famas.mdl”;
SWEP.WorldModel = “models/weapons/w_rif_famas.mdl”;

SWEP.ReloadSound = “sound/weapons/famas/clipin”;
SWEP.HoldType = “smg1”;
SWEP.FiresUnderwater = true;

end

SWEP.Primary.ClipSize =30 ;
SWEP.Primary.DefaultClip = 90;
SWEP.Primary.Automatic = true;
SWEP.Primary.Ammo = “none”;
SWEP.Primary.Recoil = 1
SWEP.Primary.Damage = 15
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.01
SWEP.Primary.Delay = 0.05

SWEP.Primary.Sound = “sound/weapons/famas/famas-1.wav”;

SWEP.Secondary.Recoil = 1.5;
SWEP.Secondary.Spread = 0.1;
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Force = 100;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = “none”;

function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end

function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {};
bullet.Num = self.Primary.NumberofShots;
bullet.Src = self.Owner:GetShootPos();
bullet.Dir = self.Owner:GetAimVector();
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0);
bullet.Tracer = 0;
bullet.Force = self.Primary.Force;
bullet.Damage = self.Primary.Damage;
bullet.AmmoType = self.Primary.Ammo;
local rnda = -self.Primary.Recoil;
local rndb = self.Primary.Recoil * math.random(-1, 1);
self:ShootEffects();
self.Owner:FireBullets( bullet );
self.Weapon:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
end

function SWEP:Think()

	if ( !self.Owner:KeyDown( IN_JUMP ) ) then return end
	local tracerlajn = {}
	local kickin = self.Owner:GetPos()
	tracerlajn.start = kickin
	tracerlajn.endpos = kickin - Vector(0,0,38)
	tracerlajn.filter = self.Owner
	local trace1 = util.TraceLine( tracerlajn )
	if SERVER then
	self.Owner:SetVelocity( self.Owner:GetAimVector() * 45 )
	end

end

function SWEP:Reload()
self.Weapon:DefaultReload(ACT_VM_RELOAD)
return true
end

Well, can someone give some advice, I don’t know where to put “fire under water”, followed this from a tutorial btw.


(User was banned for this post ("Wrong section" - mahalis))

Ask in the Lua section.

I’ll put it in lua tags for you to ease the pain of reading that.

[LUA]
if (SERVER) then --the init.lua stuff goes in here

AddCSLuaFile (“shared.lua”);

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

end

if (CLIENT) then --the cl_init.lua stuff goes in here

SWEP.PrintName = “Famas Creation”;
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;

end

SWEP.Author = “Myself”;
SWEP.Contact = “”;
SWEP.Purpose = “”;
SWEP.Instructions = “Left-click to fire; right-click to fire bombs”;
SWEP.Category = “Creations”;

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;

SWEP.ViewModel = “models/weapons/v_rif_famas.mdl”;
SWEP.WorldModel = “models/weapons/w_rif_famas.mdl”;

SWEP.ReloadSound = “sound/weapons/famas/clipin”;
SWEP.HoldType = “smg1”;
SWEP.FiresUnderwater = true;

end

SWEP.Primary.ClipSize =30 ;
SWEP.Primary.DefaultClip = 90;
SWEP.Primary.Automatic = true;
SWEP.Primary.Ammo = “none”;
SWEP.Primary.Recoil = 1
SWEP.Primary.Damage = 15
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.01
SWEP.Primary.Delay = 0.05

SWEP.Primary.Sound = “sound/weapons/famas/famas-1.wav”;

SWEP.Secondary.Recoil = 1.5;
SWEP.Secondary.Spread = 0.1;
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Force = 100;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = “none”;

function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end

function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {};
bullet.Num = self.Primary.NumberofShots;
bullet.Src = self.Owner:GetShootPos();
bullet.Dir = self.Owner:GetAimVector();
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0);
bullet.Tracer = 0;
bullet.Force = self.Primary.Force;
bullet.Damage = self.Primary.Damage;
bullet.AmmoType = self.Primary.Ammo;
local rnda = -self.Primary.Recoil;
local rndb = self.Primary.Recoil * math.random(-1, 1);
self:ShootEffects();
self.Owner:FireBullets( bullet );
self.Weapon:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
end

function SWEP:Think()

if ( !self.Owner:KeyDown( IN_JUMP ) ) then return end
local tracerlajn = {}
local kickin = self.Owner:GetPos()
tracerlajn.start = kickin
tracerlajn.endpos = kickin - Vector(0,0,38)
tracerlajn.filter = self.Owner
local trace1 = util.TraceLine( tracerlajn )
if SERVER then
self.Owner:SetVelocity( self.Owner:GetAimVector() * 45 )
end
end

function SWEP:Reload()
self.Weapon:DefaultReload(ACT_VM_RELOAD)
return true
end
[/LUA]

Maybe I’m missing something, but I don’t see what line 41 is ending. try getting rid of that

Both of your ammo types are set to ‘none’. Make sure that’s intentional or fix it.

Well I see some stuff mixed around, Not things of functional importance
as in:

SWEP.Author = “Myself”;
SWEP.Contact = “”;
SWEP.Purpose = “”;
SWEP.Instructions = “Left-click to fire; right-click to fire bombs”;

Normaly goes in, if (CLIENT)

SWEP.HoldType should go in, if (SERVER)

The one thing I see as possibly tthe source of the problem is:



SWEP.ReloadSound = "sound/weapons/famas/clipin";
SWEP.HoldType = "smg1";
SWEP.FiresUnderwater = true;

**end** <--- This end, right here

SWEP.Primary.ClipSize =30 ;
SWEP.Primary.DefaultClip = 90;
SWEP.Primary.Automatic = true;
SWEP.Primary.Ammo = "none";
SWEP.Primary.Recoil = 1
SWEP.Primary.Damage = 15
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.01 
SWEP.Primary.Delay = 0.05


Delete that end then try it.

Im not sure about the rest of the functions, I cant tell if you possibly fucked up with placing under ifs and thens ex…

Yeah, what in the hell is that end doing on line 41?!

yeah, you don’t need to put in ends when declaring and defining variables, only to wrap up functions

**( how did metanoia not catch this??? before he edited his post )

Elaborating on that; The only places “end” is acceptable is-

  1. To close a function
  2. To close an if-then statement

Infact thats the usage of “end” in a nice, neat bundle :slight_smile:

P.S. Dont make end a local value