Fixing The Melee Function On This Blaster

I’m working on some Star Wars blasters to release for my Star Wars models because everyone has been asking for them since I started putting my stuff on the Workshop. So far It’s been going very well. I’ve contacted the guy who made the “Nomad” swep and he said I could use that as a base for the blasters. The only problem I’m facing now is making the melee function work on the swep. I have it to the point where primary fire works. Secondary fire plays the animation, plays the sound, and moves the camera. It just doesn’t deal damage, and it gives a timer error. It’s extremely messy code because it’s a lot of copy and paste from existing weapons.

Here’s the code for one of the weapons, once I get one working, I can get them all to work.





AddCSLuaFile();


------------
-- Info --
------------
SWEP.Category                = "Star Wars";
SWEP.PrintName                = "DC-17m";
SWEP.Author                    = "Chad Barrett, Charles Conard";
SWEP.Contact                = "cdbarrett@gmail.com, charlesmc49@gmail.com";
SWEP.Purpose                = "Usable DC-17m Blaster Rifle";
SWEP.Instructions            = "Mouse 1 for Blaster bolts, Mouse 2 for Melee";


SWEP.WorldModel                = "models/SGG/StarWars/weapons/RC_Weapons/w_dc-17m.mdl";
SWEP.ViewModel                = "models/SGG/StarWars/weapons/RC_Weapons/v_dc-17m.mdl";
SWEP.ViewModelFOV            = 64;


SWEP.Slot                    = 2;
SWEP.SlotPos                = 3;
SWEP.Weight                    = 5;


SWEP.SwayScale                = 1.0;
SWEP.BobScale                = 1.0;


SWEP.AutoSwitchTo            = true;
SWEP.AutoSwitchFrom            = true;
-------------
-- Misc. --
-------------
SWEP.Spawnable                = true;
SWEP.AdminSpawnable            = false;
SWEP.BounceWeaponIcon        = false 
----------------------
-- Primary Fire --
----------------------
SWEP.Primary.ClipSize        = 60;
SWEP.Primary.DefaultClip    = 300;
SWEP.Primary.Automatic        = true;
SWEP.Primary.Ammo            = "DC-17_Blaster_Power_Pack";


SWEP.ShootSound                = "weapons/RC_Weapons/wep_GEN_dc17Fire_02.wav";
SWEP.EmptySound                = "weapons/RC_Weapons/wep_empty_01.wav";




SWEP.Damage                    = 12;
SWEP.FireRate                = 0.1;
SWEP.EmptyFireRate            = 0.2;
//SWEP.RegenerateRate            = 0.0;
//SWEP.RegenerateDelay        = 0.0;
SWEP.MaxEnergy                = 50;
//SWEP.Spread                    = 0.01;
----------------------
-- Secondary Fire --
----------------------
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 0.6


local SwingSound = Sound( "weapons/RC_weapons/fol_GEN_dc17Melee_01.wav" )
local HitSound = Sound( "Flesh.ImpactHard" )
---------------------------------------
-- Recoil, Spread, and Spray --
---------------------------------------
SWEP.RecoverTime     = 0.8 -- Time in seconds it takes the player to re-steady his aim after firing.


-- The following variables control the overall accuracy of the gun and typically increase with each shot
-- Recoil: how much the gun kicks back the player's view.
SWEP.MinRecoil        = 0.15
SWEP.MaxRecoil        = 0.5
SWEP.DeltaRecoil    = 0.15 -- The recoil to add each shot.  Same deal for spread and spray.


-- Spread: the width of the gun's firing cone.  More spread means less accuracy.
SWEP.MinSpread        = 0.002
SWEP.MaxSpread        = 0.05
SWEP.DeltaSpread    = 0.005


-- Spray: the gun's tendancy to point in random directions.  More spray means less control.
SWEP.MinSpray        = 0
SWEP.MaxSpray        = 1.4
SWEP.DeltaSpray        = 0.16




---------------------------
-- Ironsight/Scope --
---------------------------
-- IronSightsPos and IronSightsAng are model specific paramaters that tell the game where to move the weapon viewmodel in ironsight mode.


SWEP.IronSightsPos             = Vector (-6.1052, -14.8804, 2.65)
SWEP.IronSightsAng             = Vector (0, 0, 0)
SWEP.IronSightZoom            = 1.3 -- How much the player's FOV should zoom in ironsight mode. 
SWEP.UseScope                = true -- Use a scope instead of iron sights.
SWEP.ScopeScale                 = 0.4 -- The scale of the scope's reticle in relation to the player's screen size.
SWEP.ScopeZooms                = {8} -- The possible magnification levels of the weapon's scope.   If the scope is already activated, secondary fire will cycle through each zoom level in the table.
SWEP.DrawParabolicSights        = false -- Set to true to draw a cool parabolic sight (helps with aiming over long distances)


-------------------
-- Modifiers --
-------------------
-- Modifiers scale the gun's recoil, spread, and spray based on the player's stance
SWEP.CrouchModifier        = 0.7 -- Applies if player is crouching.
SWEP.IronSightModifier     = 0.7 -- Applies if player is in iron sight mode.
SWEP.RunModifier         = 1.4 -- Applies if player is moving.
SWEP.JumpModifier         = 1.6 -- Applies if player is in the air (jumping)


-- Note: the jumping and crouching modifiers cannot be applied simultaneously


//---------- NPC Weapon
list.Set( "NPCWeapons", "weapon_dc-17m", "DC-17m" );


if( SERVER ) then


    AccessorFunc( SWEP, "fNPCMinBurst", "NPCMinBurst" );
    AccessorFunc( SWEP, "fNPCMaxBurst", "NPCMaxBurst" );
    AccessorFunc( SWEP, "fNPCFireRate", "NPCFireRate" );
    AccessorFunc( SWEP, "fNPCMinRestTime", "NPCMinRest" );
    AccessorFunc( SWEP, "fNPCMaxRestTime", "NPCMaxRest" );
    
    resource.AddFile( "models/SGG/StarWars/weapons/RC_Weapons/w_dc-17m.mdl" );
    resource.AddFile( "models/SGG/StarWars/weapons/RC_Weapons/v_dc-17m.mdl" );
    resource.AddFile( "materials/vgui/entities/weapon_nomad.vmt" );
    resource.AddFile( "materials/nomad/glow.vmt" );
    resource.AddFile( "materials/nomad/muzzle.vmt" );
    resource.AddFile( "materials/nomad/scorch.vmt" );
    resource.AddFile( "materials/nomad/scorch_model.vmt" );
    resource.AddFile( "materials/models/weapons/v_nomad/texture4.vmt" );
    resource.AddFile( "materials/models/weapons/v_nomad/texture5.vmt" );
    resource.AddFile( "materials/models/weapons/v_nomad/v_smg1_sheet.vmt" );
    resource.AddFile( "materials/models/weapons/w_nomad/smg_crosshair.vmt" );
    resource.AddFile( "materials/models/weapons/w_nomad/w_smg2.vmt" );
    resource.AddFile( "sound/nomad/whiz.wav" );
    resource.AddFile( "sound/nomad/shoot.wav" );
    
    SWEP.tblSounds = {}
    SWEP.tblSounds["Hit"] = {"physics/imp_GEN_cc_hitByMelee_01.wav", "physics/imp_GEN_cc_hitByMelee_02.wav", "physics/imp_GEN_cc_hitByMelee_03.wav", "physics/imp_GEN_cc_hitByMelee_04.wav", "physics/imp_GEN_cc_hitByMelee_05.wav"}
    SWEP.tblSounds["HitBod"] = {"physics/flesh/imp_GEN_bloodSplat_01.wav", "physics/flesh/imp_GEN_bloodSplat_02.wav", "physics/flesh/imp_GEN_bloodSplat_03.wav", "physics/flesh/imp_GEN_bloodSplat_04.wav"}
    SWEP.tblSounds["Miss"] = {"weapons/RC_weapons/wep_GEN_swing_01.wav", "weapons/RC_weapons/wep_GEN_swing_02.wav", "weapons/RC_weapons/wep_GEN_swing_03.wav"}
    
    function SWEP:SetIdleTime( time )


        self.NextIdleTime = CurTime() + time;


    end


    
    //function SWEP:SetRegenTime( time )


    //    self.NextRegenTime = CurTime() + time;


    //end




    function SWEP:IdleTime()


        return self.NextIdleTime;


    end


    
    //function SWEP:RegenTime()


    //    return self.NextRegenTime;


    //end




    function SWEP:TakeEnergy( amt )


        self:SetEnergyVar( math.max( 0, self:GetEnergyVar() - amt ) );


    end


    
    function SWEP:GiveEnergy( amt )


        self:SetEnergyVar( math.min( self.MaxEnergy, self:GetEnergyVar() + amt ) );


    end


    
    function SWEP:TakePrimaryAmmo( amt )


        self:TakeEnergy( amt );


    end


    
    function SWEP:ShouldDropOnDie()


        return false;


    end


    
    function SWEP:NPCShoot_Primary( pos, dir )


        if( not IsValid( self.Owner ) ) then return; end
        
        self:PrimaryAttack();


    end




    function SWEP:NPCShoot_Secondary( pos, dir )


        if( not IsValid( self.Owner ) ) then return; end
        
        self:SecondaryAttack();


    end




    function SWEP:GetCapabilities()


        return bit.bor( CAP_WEAPON_RANGE_ATTACK1, CAP_INNATE_RANGE_ATTACK1 );


    end
    
end




if( CLIENT ) then


    language.Add("weapon_dc_17m", "DC-17m")
    killicon.AddFont( "weapon_dc-17m", "HL2MPTypeDeath", "/", Color( 255, 255, 255, 255 ) );
    SWEP.WepSelectIcon      = surface.GetTextureID("vgui/entities/weapon_dc-17m")
    
    local AmmoDisplay = {};


    function SWEP:CustomAmmoDisplay()


        AmmoDisplay.Draw = true;
        AmmoDisplay.PrimaryClip = self:GetEnergy();
        AmmoDisplay.PrimaryAmmo = -1;
        AmmoDisplay.SecondaryClip = -1;
        AmmoDisplay.SecondaryAmmo = -1;


        return AmmoDisplay;


    end


end




function SWEP:Initialize()


    self:SetupDataTables();
    
    self:SetWeaponHoldType( "ar2" );
    
    if( SERVER ) then


        self:SetNPCMinBurst( 3 );
        self:SetNPCMaxBurst( 10 );
        self:SetNPCFireRate( self.FireRate );
        self:SetNPCMinRest( 0.5 );
        self:SetNPCMaxRest( 2 );
        
        self:SetIdleTime( 0 );
        //self:SetRegenTime( 0 );
        
        self:GiveEnergy( self.MaxEnergy );


    end


end




function SWEP:SetupDataTables()


    self:InstallDataTable();
    self:NetworkVar( "Int", 0, "EnergyVar" );


end




function SWEP:WeaponSound( sound, volume, pitch )


    local shouldSuppress = SERVER and not game.SinglePlayer();
    
    if( shouldSuppress ) then SuppressHostEvents( self.Owner ); end
    self:EmitSound( sound, volume, pitch );
    if( shouldSuppress ) then SuppressHostEvents( NULL ); end


    -- there is a bug in the gmod code where it's supposed to use CHAN_WEAPON but it doesn't.


end




function SWEP:Precache()


    util.PrecacheSound( self.ShootSound );


end




function SWEP:SetNextFire( time )


    self:SetNextPrimaryFire( CurTime() + time );
    self:SetNextSecondaryFire( CurTime() + time );


end




function SWEP:GetEnergy()


    return self:GetEnergyVar();


end




function SWEP:ShootBullet( damage, num, cone )


    local bullet = {};
    bullet.Num = num;
    bullet.Src = self.Owner:GetShootPos();
    bullet.Dir = self.Owner:GetAimVector();
    bullet.Spread = Vector( cone, cone, 0 );
    bullet.Tracer = 1;
    bullet.Force = 100;
    bullet.Damage = damage;
    bullet.AmmoType = "ar2";
    bullet.TracerName = "blue_Tracer";
    bullet.Callback = function( attacker, tr, dmginfo )


        dmginfo:SetDamageType( bit.bor( DMG_ENERGYBEAM ) );


    end
    
    self.Owner:FireBullets( bullet, true );
    
    self:ShootEffects();


end




function SWEP:ShootEffects()


    self.Owner:MuzzleFlash();
    self.Owner:SetAnimation( PLAYER_ATTACK1 );
    self:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
    
    self:WeaponSound( self.ShootSound );
    
    -- we just played an animation, so don't play an idle animation again until it's over.
    if( SERVER ) then


        self:SetIdleTime( self:SequenceDuration() );


    end


end




function SWEP:CanPrimaryAttack()


    -- npcs get unlimited ammo because they don't know how to stop shooting!
    -- i could set the rest time, but this is quicker and easier.
    if( self.Owner:IsNPC() ) then return true; end
    if( self:GetEnergy() >= 1 ) then return true; end
    
    return false;


end




function SWEP:Empty()


    self:WeaponSound( self.EmptySound );
    self:SetNextFire( self.EmptyFireRate );


end




function SWEP:PrimaryAttack()


    self:SetNextFire( self.FireRate );
    
    -- don't regenerate ammo if they're just holding down the fire button
    -- make them stop to cool it off.
    if( SERVER ) then


        //self:SetRegenTime( self.RegenerateDelay );


    end


    -- do we have enoguh energy to fire?
    if( not self:CanPrimaryAttack() ) then


        self:Empty();
        return true;


    end
    
    -- consume energy
    if( SERVER ) then


        self:TakePrimaryAmmo( 1 );


    end
    
    self:ShootBullet( self.Damage, 1, self.Spread );
    
    return true;


end


SWEP.HitDistance = 67
SWEP.AttackAnims = { "meleeattack" }


function SWEP:SecondaryAttack()
    self.Owner:SetAnimation( PLAYER_ATTACK1 )


    if ( !SERVER ) then return end


    -- We need this because attack sequences won't work otherwise in multiplayer
    local vm = self.Owner:GetViewModel()
    vm:ResetSequence( vm:LookupSequence( "IR_idle" ) )


    local anim = self.AttackAnims[ math.random( 1, #self.AttackAnims ) ]


    timer.Simple( 0, function()
        if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
    
        local vm = self.Owner:GetViewModel()
        vm:ResetSequence( vm:LookupSequence( anim ) )


        self:Idle()
    end )


    timer.Simple( 0.05, function()
        if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
        if ( anim == "meleeattack" ) then
            self.Owner:ViewPunch( Angle( 0, 4, 0 ) )
        end
    end )


    timer.Simple( 0.2, function()
        if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
        if ( anim == "meleeattack" ) then
            self.Owner:ViewPunch( Angle( 1, -4, 0 ) )
        end
        self.Owner:EmitSound( SwingSound )
        
    end )


    timer.Simple( 0.2, function()
        if ( !IsValid( self ) || !IsValid( self.Owner ) || !self.Owner:GetActiveWeapon() || self.Owner:GetActiveWeapon() != self ) then return end
        self:DealDamage( anim )
    end )


    self:SetNextPrimaryFire( CurTime() + 0.6 )


end


function SWEP:DealDamage( anim )
    local tr = util.TraceLine( {
        start = self.Owner:GetShootPos(),
        endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
        filter = self.Owner
    } )


    if ( !IsValid( tr.Entity ) ) then 
        tr = util.TraceHull( {
            start = self.Owner:GetShootPos(),
            endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.HitDistance,
            filter = self.Owner,
            mins = self.Owner:OBBMins() / 3,
            maxs = self.Owner:OBBMaxs() / 3
        } )
    end


    if ( tr.Hit ) then self.Owner:EmitSound( HitSound ) end


    if ( IsValid( tr.Entity ) && ( tr.Entity:IsNPC() || tr.Entity:IsPlayer() ) ) then
        local dmginfo = DamageInfo()
        dmginfo:SetDamage( self.Primary.Damage )
        if ( anim == "meleeattack" ) then
            dmginfo:SetDamageForce( self.Owner:GetRight() * 49125 + self.Owner:GetForward() * 99984 ) -- Yes we need those specific numbers
        end
        dmginfo:SetInflictor( self )
        local attacker = self.Owner
        if ( !IsValid( attacker ) ) then attacker = self end
        dmginfo:SetAttacker( attacker )


        tr.Entity:TakeDamageInfo( dmginfo )
    end
end




function SWEP:Think()


    if( not SERVER ) then return; end
    
//    -- ammo regeneration
//    if( self:RegenTime() <= CurTime() ) then


//        self:GiveEnergy( 1 );
//        self:SetRegenTime( self.RegenerateRate );


//    end
    
    -- idle animations
    if( self:IdleTime() <= CurTime() ) then


        self:SendWeaponAnim( ACT_VM_IDLE );
        self:SetIdleTime( self:SequenceDuration() );


    end


end




function SWEP:FireAnimationEvent( pos, ang, event, options )


    -- we don't want shell casings
    if( event == 6001 ) then return true; end
    
    -- custom muzzle flash
    if( event == 21 or event == 22 ) then


        local effect = EffectData();
        effect:SetOrigin( pos );
        effect:SetAngles( ang );
        effect:SetEntity( self );
        effect:SetAttachment( 1 );


        util.Effect( "blue_Muzzle", effect );
        
        return true;
    end


end




function SWEP:DoImpactEffect( tr, dmgtype )


    if( tr.HitSky ) then return true; end
    
    util.Decal( "fadingscorch", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal );
    
    -- is this even the correct way to handle this?
    if( game.SinglePlayer() or SERVER or not self:IsCarriedByLocalPlayer() or IsFirstTimePredicted() ) then


        local effect = EffectData();
        effect:SetOrigin( tr.HitPos );
        effect:SetNormal( tr.HitNormal );


        util.Effect( "blue_Impact", effect );


        local effect = EffectData();
        effect:SetOrigin( tr.HitPos );
        effect:SetStart( tr.StartPos );
        effect:SetDamageType( dmgtype );


        util.Effect( "RagdollImpact", effect );
    end


    return true;


end


function SWEP:EntsInViewCone(pos, flDistance)
    for k, v in pairs(ents.FindInSphere(pos, flDistance)) do
        if ValidEntity(v) && v != self && v != self.Owner && (v:IsPhysicsEntity() || v:IsNPC() || v:IsPlayer()) && self.Owner:EntInViewCone(v,25) then
            return true
        end
    end
    return false
end


function SWEP:DoMeleeDamage(iDist, iDmg)
    local posStart = self.Owner:GetShootPos()
    local posEnd = posStart +self.Owner:GetAimVector() *iDist
    local tracedata = {}
    tracedata.start = posStart
    tracedata.endpos = posEnd
    tracedata.filter = self.Owner
    local tr = util.TraceLine(tracedata)
    
    local bEntsInViewCone = self:EntsInViewCone(tracedata.endpos, 12)
    local act
    if tr.Hit || bEntsInViewCone then
        if ValidEntity(tr.Entity) || bEntsInViewCone then
            if CLIENT then return 1, tr end
            return 1, tr, util.BlastDmg(self, self.Owner, tr.HitPos +tr.Normal *6, 12, iDmg, self.Owner, DMG_SLASH)
        end
        return 2, tr
    end
    return 0, tr
end


function SWEP:SetupWeaponHoldTypeForAI( t )


    self.ActivityTranslateAI = {};
    
    self.ActivityTranslateAI[ ACT_IDLE ]                        = ACT_IDLE_PISTOL;
    self.ActivityTranslateAI[ ACT_IDLE_ANGRY ]                    = ACT_IDLE_ANGRY_PISTOL;
    self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ]                = ACT_RANGE_ATTACK_PISTOL;
    self.ActivityTranslateAI[ ACT_RELOAD ]                        = ACT_RELOAD_PISTOL;
    self.ActivityTranslateAI[ ACT_WALK_AIM ]                    = ACT_WALK_AIM_PISTOL;
    self.ActivityTranslateAI[ ACT_RUN_AIM ]                        = ACT_RUN_AIM_PISTOL;
    self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ]        = ACT_GESTURE_RANGE_ATTACK_PISTOL;
    self.ActivityTranslateAI[ ACT_RELOAD_LOW ]                    = ACT_RELOAD_PISTOL_LOW;
    self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ]            = ACT_RANGE_ATTACK_PISTOL_LOW;
    self.ActivityTranslateAI[ ACT_COVER_LOW ]                    = ACT_COVER_PISTOL_LOW;
    self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ]                = ACT_RANGE_AIM_PISTOL_LOW;
    self.ActivityTranslateAI[ ACT_GESTURE_RELOAD ]                = ACT_GESTURE_RELOAD_PISTOL;
    
    -- we only want the smg hold type, ignore all others
    if( t == "ar2" ) then
        
        self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ]            = ACT_RANGE_ATTACK_SMG1;
        self.ActivityTranslateAI[ ACT_RELOAD ]                    = ACT_RELOAD_SMG1;
        self.ActivityTranslateAI[ ACT_IDLE ]                    = ACT_IDLE_SMG1;
        self.ActivityTranslateAI[ ACT_IDLE_ANGRY ]                = ACT_IDLE_ANGRY_SMG1;
        self.ActivityTranslateAI[ ACT_WALK ]                    = ACT_WALK_RIFLE;
        self.ActivityTranslateAI[ ACT_WALK_AIM ]                = ACT_WALK_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_IDLE_RELAXED ]            = ACT_IDLE_SMG1_RELAXED;
        self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ]            = ACT_IDLE_SMG1_STIMULATED;
        self.ActivityTranslateAI[ ACT_IDLE_AGITATED ]            = ACT_IDLE_ANGRY_SMG1;
        self.ActivityTranslateAI[ ACT_WALK_RELAXED ]            = ACT_WALK_RIFLE_RELAXED;
        self.ActivityTranslateAI[ ACT_WALK_STIMULATED ]            = ACT_WALK_RIFLE_STIMULATED;
        self.ActivityTranslateAI[ ACT_WALK_AGITATED ]            = ACT_WALK_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN_RELAXED ]                = ACT_RUN_RIFLE_RELAXED;
        self.ActivityTranslateAI[ ACT_RUN_STIMULATED ]            = ACT_RUN_RIFLE_STIMULATED;
        self.ActivityTranslateAI[ ACT_RUN_AGITATED ]            = ACT_RUN_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ]        = ACT_IDLE_SMG1_RELAXED;
        self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ]        = ACT_IDLE_AIM_RIFLE_STIMULATED;
        self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ]        = ACT_IDLE_ANGRY_SMG1;
        self.ActivityTranslateAI[ ACT_WALK_AIM_RELAXED ]        = ACT_WALK_RIFLE_RELAXED;
        self.ActivityTranslateAI[ ACT_WALK_AIM_STIMULATED ]        = ACT_WALK_AIM_RIFLE_STIMULATED;
        self.ActivityTranslateAI[ ACT_WALK_AIM_AGITATED ]        = ACT_WALK_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ]            = ACT_RUN_RIFLE_RELAXED;
        self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ]        = ACT_RUN_AIM_RIFLE_STIMULATED;
        self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ]        = ACT_RUN_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_WALK_CROUCH ]                = ACT_WALK_CROUCH_RIFLE;
        self.ActivityTranslateAI[ ACT_WALK_CROUCH_AIM ]            = ACT_WALK_CROUCH_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN ]                        = ACT_RUN_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN_AIM ]                    = ACT_RUN_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN_CROUCH ]                = ACT_RUN_CROUCH_RIFLE;
        self.ActivityTranslateAI[ ACT_RUN_CROUCH_AIM ]            = ACT_RUN_CROUCH_AIM_RIFLE;
        self.ActivityTranslateAI[ ACT_GESTURE_RANGE_ATTACK1 ]    = ACT_GESTURE_RANGE_ATTACK_AR2;
        self.ActivityTranslateAI[ ACT_COVER_LOW ]                = ACT_COVER_SMG1_LOW;
        self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ]            = ACT_RANGE_AIM_AR2_LOW;
        self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ]        = ACT_RANGE_ATTACK_SMG1_LOW;
        self.ActivityTranslateAI[ ACT_RELOAD_LOW ]                = ACT_RELOAD_SMG1_LOW;
        self.ActivityTranslateAI[ ACT_GESTURE_RELOAD ]            = ACT_GESTURE_RELOAD_SMG1;


    end


end


The timer error in question.



Timer Failed! [Simple][@lua/weapons/weapon_dc-17m.lua (line 446)]
TEST [lua/weapons/weapon_dc-17m.lua][lua/weapons/weapon_dc-17m.lua]
FOUND IN ADDON [130680140]
TEST [lua/weapons/weapon_dc_15s.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_lightsaber.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_nomad.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_radar.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_dc-17m.lua][lua/weapons/weapon_dc-17m.lua]
FOUND IN ADDON [130680140]
TEST [lua/weapons/weapon_dc_15s.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_lightsaber.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_nomad.lua][lua/weapons/weapon_dc-17m.lua]
TEST [lua/weapons/weapon_radar.lua][lua/weapons/weapon_dc-17m.lua]


[Star Wars Blasters] lua/weapons/weapon_dc-17m.lua:476: bad argument #1 to 'SetDamage' (number expected, got nil)
  1. SetDamage - [C]:-1
   2. DealDamage - lua/weapons/weapon_dc-17m.lua:476
    3. unknown - lua/weapons/weapon_dc-17m.lua:448


Timer Failed! [Simple][@lua/weapons/weapon_dc-17m.lua (line 446)]


Also, How would I go about making a custom ammo type for the blasters to use.

Video of progress so far.

Thanks in advance.


[Star Wars Blasters] lua/weapons/weapon_dc-17m.lua:476: bad argument #1 to 'SetDamage' (number expected, got nil)

[lua]dmginfo:SetDamage( self.Primary.Damage )[/lua]

This seems to be your problem. SWEP:DealDamage seems to be what inflicts melee damage, and SWEP.Primary.Damage is defined nowhere in your script.

I could love you forever, it works flawlessly now. Thank you so much!

I have no idea what I’m doing so any help is greatly appreciated.
Now I just need to figure out how to make the custom ammo type and make the numbers change on the display.

Try this for your ammo type, and this to make your own ammo display.

Hey Shotgun, how did you do it for the gun to fire laser? Trying to make the E-11 blaster