Could someone please take a quick look at the lua in my SWEP? *Ignore my other thread*

Hello, I’m new to both Facepunch and Lua, and I was wondering if someone could take a quick look at my SWEP.
The SWEP is a stunbaton designed for the gamemode “Tiramisu” in GMod.
It’s supposed to flash the target’s screen on left click, right click is supposed to damage and eventually knock unconscious when the target gets to 0 hp, and reload is supposed to get them back up.
I am aware there are console commands in Tiramisu called rp_passout and rp_wakeup that knocks out a player and gets them back up, I’m trying to implement that into a SWEP.
Currently, it says it has errors somewhere and won’t even show up in my spawn weapon list.
Any help would be greatly appreciated.
The shared.lua is below.


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 = "Stunstick";
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = false;

end


SWEP.Author = "gcm471995";
SWEP.Contact = "";
SWEP.Purpose = "To remind citizens how to behave.";
SWEP.Instructions = "Left click to discipline, Right click to damage and eventually knock out, Reload to get back up.";


SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "stunstick"

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

SWEP.ViewModel = "models/weapons/v_stunstick.mdl";
SWEP.WorldModel = "models/weapons/w_stunbaton.mdl";

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

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



/*---------------------------------------------------------
Name: SWEP:Initialize( )
Desc: Called when the weapon is first loaded
---------------------------------------------------------*/

function SWEP:Initialize()

if( SERVER ) then

self:SetWeaponHoldType( "melee" );

end

self.Hit = { 
Sound( "weapons/stunstick/stunstick_impact1.wav" ),
Sound( "weapons/stunstick/stunstick_impact2.wav" ) };

self.FleshHit = {
Sound( "weapons/stunstick/stunstick_fleshhit1.wav" ),
Sound( "weapons/stunstick/stunstick_fleshhit2.wav") }; 
};

end

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

function SWEP:DoFlash( ply )

umsg.Start( "StunStickFlash", ply ); umsg.End();

end


/*---------------------------------------------------------
Name: SWEP:PrimaryAttack( )
Desc: +attack1 has been pressed
---------------------------------------------------------*/
function SWEP:PrimaryAttack()

if( CurTime() < self.NextStrike ) then return; end

self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:EmitSound( self.Sound );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );

self.NextStrike = ( CurTime() + .3 );

if( CLIENT ) then return; end

local trace = self.Owner:GetEyeTrace();

if( not trace.Entity:IsValid() ) then
return;
end

if( self.Owner:EyePos():Distance( trace.Entity:GetPos() ) > 100 ) then
return;
end

if( SERVER ) then 

local hp = trace.Entity:Health();
hp = hp - math.random( 0, 0 );
if( hp <= 0 ) then hp = 1; end

trace.Entity:SetHealth( hp );

if( not trace.Entity:IsDoor() ) then
trace.Entity:SetVelocity( ( trace.Entity:GetPos() - self.Owner:GetPos() ) * 7 ); 
end

if( trace.Entity:IsPlayer() ) then
timer.Simple( .3, self.DoFlash, self, trace.Entity );
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end

end


end



/*---------------------------------------------------------
Name: SWEP:SecondaryAttack( )
Desc: +attack2 has been pressed
---------------------------------------------------------*/
function SWEP:SecondaryAttack()

if( CurTime() < self.NextStrike ) then return; end

self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:EmitSound( self.Sound );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );

self.NextStrike = ( CurTime() + .3 );

if( CLIENT ) then return; end

local trace = self.Owner:GetEyeTrace();

if( not trace.Entity:IsValid() ) then
return;
end

if( self.Owner:EyePos():Distance( trace.Entity:GetPos() ) > 100 ) then
return;
end

if( SERVER ) then 

local hp = trace.Entity:Health();
hp = hp - math.random( 10, 45 );
if( hp <= 0 ) then hp = 1; end
if( hp <= 1 ) then local function ccKnockOut( ply, cmd, args )

CAKE.UnconciousMode( ply ); end

trace.Entity:SetHealth( hp );

if( not trace.Entity:IsDoor() ) then
trace.Entity:SetVelocity( ( trace.Entity:GetPos() - self.Owner:GetPos() ) * 7 ); 
end

if( trace.Entity:IsPlayer() ) then
timer.Simple( .3, self.DoFlash, self, trace.Entity );
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end

end


end


/*---------------------------------------------------------
Name: SWEP:Reload( )
Desc: +reload has been pressed
---------------------------------------------------------*/
function SWEP:Reload()

if( CurTime() < self.NextStrike ) then return; end

self.Owner:SetAnimation( PLAYER_ATTACK1 );
self.Weapon:EmitSound( self.Sound );
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );

self.NextStrike = ( CurTime() + .3 );

if( CLIENT ) then return; end

local trace = self.Owner:GetEyeTrace();

if( not trace.Entity:IsValid() ) then
return;
end

if( self.Owner:EyePos():Distance( trace.Entity:GetPos() ) > 100 ) then
return;
end

if( SERVER ) then 

local hp = trace.Entity:Health();
hp = hp - math.random( 0, 0 );
if( hp <= 100 ) then local function ccWakeUp( ply, cmd, args )
if( hp <= 100 ) then hp = 100; end
local function ccWakeUp( ply, cmd, args )

if ply:GetNWBool( "unconciousmode", false ) then
CAKE.UnconciousMode( ply )
end

trace.Entity:SetHealth( hp );

if( not trace.Entity:IsDoor() ) then
trace.Entity:SetVelocity( ( trace.Entity:GetPos() - self.Owner:GetPos() ) * 7 ); 
end

if( trace.Entity:IsPlayer() ) then
timer.Simple( .3, self.DoFlash, self, trace.Entity );
self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
else
self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
end

end


end 

Post the errors and I’ll look at it.

It says:

[lua\weapons\stunstick\shared.lua:74] ‘}’ expected (to close ‘{’ at line 71) near ‘Sound’

As I said, Im new to scripting but I don’t see anything wrong with the following code, and plus that piece was copy pasted from another working script.

Heres lines 58-73, 58 starting at function.



function SWEP:Initialize()
 
        if( SERVER ) then
        
                self:SetWeaponHoldType( "melee" );
        
        end
        
        self.Hit = { 
        Sound( "weapons/stunstick/stunstick_impact1.wav" ),
        Sound( "weapons/stunstick/stunstick_impact2.wav" ) };
        
        self.FleshHit = {
        Sound( "weapons/stunstick/stunstick_fleshhit1.wav" ),
        Sound( "weapons/stunstick/stunstick_fleshhit2.wav") };        
}; 

Try removing the. }; at the end.

Its worth a shot. I’m just mostly concerned about it forcing the player to do the rp_knockout.
Thank you, and if this gets working, I’ll make you a admin or CP or something if you want on my RP server if youre into that kind of thing

Did that fix it?

Sorry about that, I havent been able to test it for a few days. However, I found that the error I posted was from a conflicting addon and happened to have the same command at Line 71 and both are stunsticks. I removed the other one and I got a new error from the actual stunstick Im working on. It say:

[lua\weapons\gcmstunstick\shared.lua:96] attempt to compare number with nil

Lines 94-100


function SWEP:PrimaryAttack()
  
        if( CurTime() < self.NextStrike ) then return; end ----This is line 96----
  
        self.Owner:SetAnimation( PLAYER_ATTACK1 );
        self.Weapon:EmitSound( self.Sound );
        self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER );

[editline]7th December 2011[/editline]

Most of the errors I’ve fixed over the last hour or so. Currently it does everything it needs to other than the animations are messed up, and there is no electricity effects or hit effects/sounds.

So I don’t generally work with Sweps, but in the init, try defining self.NextStrike as 0.

That parts fixed. I realized I accidently cut that part out of the script earlier and put it back in. But its mostly juts animations now. Im gonna try it on a person now

[editline]7th December 2011[/editline]

It’s pretty much fixed now. The animations are all set up and working, except the first-person animation for swinging is the crowbar anim when its supposed to be a stunstick anim. The only other problems are that it doesn’t recognize targets or do damage, and it doesnt have any of the stunstick electric effects.