• secondary fire not shooting
    9 replies, posted
Hello, total lua newbie experimenting with scripts for the first time. I am trying to get my secondary fire to shoot an explosive bullet, and I want it to use ammo from the primary clip. However, it's not even firing at this point. What should I do? [Code]//General Variables\\ SWEP.AdminSpawnable = true SWEP.ViewModelFOV = 64 SWEP.ViewModel = "models/weapons/v_pist_deagle.mdl" SWEP.WorldModel = "models/weapons/w_pist_deagle.mdl" SWEP.AutoSwitchTo = false SWEP.Slot = 1 SWEP.HoldType = "Pistol" SWEP.PrintName = "Smith & Wesson Model 500" SWEP.Author = "Bop" SWEP.Spawnable = true SWEP.AutoSwitchFrom = false SWEP.FiresUnderwater = true SWEP.Weight = 5 SWEP.DrawCrosshair = true SWEP.Category = "Handcannons" SWEP.SlotPos = 0 SWEP.DrawAmmo = true SWEP.ReloadSound = "Weapon_357.Reload" SWEP.Instructions = "Shoot" SWEP.Contact = "Don't" SWEP.Purpose = "Killing" SWEP.base = "weapon_base" //General Variables\\ //Primary Fire Variables\\ SWEP.Primary.Damage = 1000 SWEP.Primary.TakeAmmo = 1 SWEP.Primary.ClipSize = 6 SWEP.Primary.Ammo = "357" SWEP.Primary.DefaultClip = 120 SWEP.Primary.Spread = 0.1 SWEP.Primary.NumberofShots = 1 SWEP.Primary.Automatic = false SWEP.Primary.Recoil = 5 SWEP.Primary.Delay = 1 SWEP.Primary.Force = 1000 //Primary Fire Variables\\ //Secondary Fire Variables\\ SWEP.Secondary.Damage = 2000 SWEP.Secondary.Force = 2000 SWEP.Secondary.Spread = 0.1 SWEP.Secondary.Recoil = 5 SWEP.Secondary.Delay = 1 SWEP.Secondary.NumberofShots = 1 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Sound = Sound("weapons/s&w500/fire.wav") SWEP.ReloadSound = Sound("weapons/s&w500/reload.wav") //Secondary Fire Variables\\ //SWEP:Initialize()\\ //SWEP:Initialize()\\ //SWEP:PrimaryFire()\\ 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 * -1 local rndb = self.Primary.Recoil * math.random(-1, 1) self:ShootEffects() self.Owner:FireBullets( bullet ) self.Weapon:EmitSound(Sound(self.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 //SWEP:PrimaryFire()\\ //SWEP:SecondaryFire()\\ function SWEP:SecondaryAttack() if ( !self:CanSecondaryAttack() ) then return end local bullet = {} bullet.Num = self.Secondary.NumberofShots bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector( self.Secondary.Spread * 0.1 , self.Secondary.Spread * 0.1, 0) bullet.Tracer = 0 bullet.Force = self.Secondary.Force bullet.Damage = self.Secondary.Damage bullet.AmmoType = self.Primary.Ammo local rnda = -self.Secondary.Recoil local rndb = self.Secondary.Recoil * math.random(-1, 1) self.Owner:FireBullets( bullet ) self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) local eyetrace = self.Owner:GetEyeTrace() self:EmitSound ( self.Sound ) self:ShootEffects() local explode = ents.Create("env_explosion") explode:SetPos( eyetrace.HitPos ) explode:SetOwner( self.Owner ) explode:Spawn() explode:SetKeyValue("iMagnitude","150") explode:Fire("Explode", 0, 0 ) explode:EmitSound("self.Sound", 400, 400 ) self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self:TakePrimaryAmmo(1) end //SWEP:SecondaryFire()\\ [/Code]
First of all, is all of this in one file? You could do that with shared.lua for a file but I don't see a: if (SERVER) then init.lua shit here end if (CLIENT) then cl_init.lua shit here end, Your gun's lua file may not even be loading, Have you tried looking over example swep's on Wiki.garrysmod.com first before trying to do this alone?
Yes, that's all in my shared.lua file. I have looked at the example scripts, and I'm just experimenting right now to try and teach myself through trial and error. Also, the gun [i]is[/i] working besides for the secondary fire problem, so it shouldn't be too messed up right now.
It might be easier to figure out the problem if it were more organized. >:(
Sorry... That's something I can't really do much about.
Well then I don't think programming is a thing for you :\
[QUOTE=Dane Somdahl;22936230]It might be easier to figure out the problem if it were more organized. >:([/QUOTE] It's organized just fine, I've seen snippets much messier then that. [QUOTE=Dane Somdahl;22936520]Well then I don't think programming is a thing for you :\[/QUOTE] Get out. [lua]SWEP.Sound = Sound("weapons/s&w500/fire.wav") SWEP.ReloadSound = Sound("weapons/s&w500/reload.wav")[/lua] -snip- Apparently folders can have the & symbol in them.. Just in-case the below doesn't fix it, then try changing the folder name. [lua] local rnda = -self.Secondary.Recoil[/lua] Try changing that to: [lua] local rnda = -1 * self.Secondary.Recoil[/lua] Are you ever defining the SWEP:Initialize() function anywhere in this SWEP? Most importantly, do you get any lua errors in the console? Next time use [lua][/lua ] tags like this when posting lua code (Without the space).
Sorry for the late reply. Unfortunately, neither did the trick. And to answer your questions: I'm not getting any lua errors, it's just that I just can't shoot anything with secondary fire (I get that empty clip clicking noise). No, I'm not using the SWEP:Initialize() function because when I do, I get some lua error about PreCache sound.
[lua] explode:EmitSound("self.Sound", 400, 400 ) [/lua] Should be [lua] explode:EmitSound(self.Sound, 400, 400 ) [/lua] [editline]03:56PM[/editline] Also I'm pretty sure SWEP.base should have a capital B
I fixed both, but nothing happened. EDIT: I figured out what the problem was. I changed [lua]if ( !self:CanSecondaryAttack() ) then return end[/lua] to [lua]if ( !self:CanPrimaryAttack() ) then return end[/lua] and that got it working. Anyway, thanks to everyone for helping me.
Sorry, you need to Log In to post a reply to this thread.