• Three round Burst problem
    10 replies, posted
My current three round burst function I ported for gmod 13 works fine but has two annoying glitches. 1st glitch If I want to reload right after and press R too soon like when it just fired the second bullet of the three. the weapon begins its reload time So after the third round the gun remains frozen untill the time It would take to reload the gun is passed. What I basicly want is that the player can't use the reload function during its burst so this glitch would not occure, but i have no clue how to blend it in this function (which I already had to rewrite to be compatible for the gmod13 update) 2nd glitch When you fire the three rounds and still hold down the trigger It will automaticly fire the next 3 rounds and so over... I'd rather see that you have to click again to fire the next burst, like Semi auto's does. Code is below [Lua] SWEP.FireModes.Burst = {} SWEP.FireModes.Burst.FireFunction = function(self) local clip = self.Weapon:Clip1() if not self:CanFire(clip) then return end self:BaseAttack() timer.Simple(self.BurstDelay, function() self:BaseAttack() end ) if clip > 1 then timer.Simple(2*self.BurstDelay, function() self:BaseAttack() end ) end end SWEP.FireModes.Burst.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.SemiRPM + 3*self.BurstDelay -- Burst delay is derived from self.BurstRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end SWEP.FireModes.Burst.RevertFunction = function(self) return end SWEP.FireModes.Burst.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppp") end [/Lua] I'm not a Lua expert so if anyone knows what needs to be added or changed on this script, please leave a reply. thanks
What I do for my 3 round burst is this: Only allow bullets to be fired until the trigger is released, or the pack has fired 2 or 3 ( depending on weapon system ); as in real-life. No automatic 3 rounds to fire on 1 click... -- I wouldn't recommend allowing 3 rounds to fire on 1 click because it isn't how real weapons work, and if it was an accident then there are 3 rounds down-range instead of 1. So, I switch Automatic mode on/off depending on where/when/how, etc... in PrimaryAttack. Second, for reload, Add a clause, if !CanPrimaryAttack || !CanSecondaryAttack, then return false to prevent reloading.
Can u show me where you would place the [Lua]if !CanPrimaryAttack || !CanSecondaryAttack, then return false [/Lua] in my function? I fail to do so (erroring) [ERROR] addons/testsweps/lua/weapons/my_base/cl_init.lua:141: attempt to index a nil value 1. unknown - addons/'realistic' sweps/lua/weapons/rg_base/cl_init.lua:141 If I understood what u mean to say: the burst mode should only fire all three bullets if you would hold down the trigger during the fire rate. so if the gun has e.g. 3 round burst and you would release the trigger after it only fired the second round, it would cease fire and not fire the third obviously?
Mine looks like this right now: [code]--[[--------------------------------------------------------- Name: SWEP:Reload( ) Desc: Reload is being pressed -----------------------------------------------------------]] function SWEP:Reload( ) if ( !self:CanPrimaryAttack( ) || !self:CanSecondaryAttack( ) ) then return false; end if ( self.Weapon.NextReload && self.Weapon.NextReload > CurTime( ) ) then return false; end if ( self.WeaponClass == WEAPON_CLASS_KNIFE || self.WeaponClass == WEAPON_CLASS_MELEE ) then return false; end self:DefaultReload( self.Animations.vmreload ); self.Weapon.NextReload = CurTime( ) + self.Weapon:SequenceDuration( ); self.ShotsFired = 0 return true; end [/code]
Ive used your function, It didnt change anything only added a empty click sound everytime I use the Reload key, Also if I do nothing and hold down R it spams that click round at an infinite rate I'd be awesome if my reload function works the same way m9k base does, There you dont have the issue of "infinite reloading" which I mean to say if you would hold down reload key before firing and then fire the weapon it instantly reloads, thus even skipping the fire animation. In M9k you cant use both reload and fire at the same time so This would prevent that e.g. a fully automatic weapon would loop firing->instantreloading firing->instantreloading and so on. because If you hold down R while weapon it full it wont fire and the other way around after it fiinished reloading... Id love to have that function as my primary reload.
Show me your entire SWEP Base, you may not be setting the next primary fire correctly, etc...
Shared: [Lua] -- 'Realistic' SWEP base -- -- if SERVER then AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end SWEP.Author = "Teta_Bonita" SWEP.Contact = "" SWEP.Purpose = "To crush your enemies." SWEP.Instructions = "Aim away from face." SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Primary.Sound = Sound("Weapon_TMP.Single") SWEP.Primary.Damage = 40 SWEP.Primary.NumShots = 1 SWEP.AutoRPM = 200 SWEP.SemiRPM = 200 SWEP.BurstRPM = 200 SWEP.MuzzleVelocity = 920 SWEP.AvailableFireModes = {} SWEP.DrawFireModes = true SWEP.FiresUnderwater = false SWEP.MuzzleEffect = "rg_muzzle_pistol" SWEP.ShellEjectEffect = "rg_shelleject" SWEP.MuzzleAttachment = "1" SWEP.ShellEjectAttachment = "2" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.GrenadeDamage = 100 SWEP.GrenadeVelocity = 1400 SWEP.GrenadeRPM = 50 SWEP.Secondary.Sound = Sound("Weapon_AR2.Double") -- For grenade launching SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false -- Best left at false, as secondary is used for ironsights/switching firemodes SWEP.Secondary.Ammo = "none" SWEP.IronSightZoom = 1.2 SWEP.ScopeZooms = {5} SWEP.UseScope = false SWEP.ScopeScale = 0.4 SWEP.DrawParabolicSights = false SWEP.MinRecoil = 0.1 SWEP.MaxRecoil = 0.5 SWEP.DeltaRecoil = 0.1 SWEP.RecoverTime = 1 SWEP.MinSpread = 0.01 SWEP.MaxSpread = 0.08 SWEP.DeltaSpread = 0.003 SWEP.MinSpray = 0.2 SWEP.MaxSpray = 1.5 SWEP.DeltaSpray = 0.2 SWEP.CrouchModifier = 0.7 SWEP.IronSightModifier = 0.7 SWEP.RunModifier = 1.5 SWEP.JumpModifier = 1.5 --------------------------------------------------------- --------------------Firemodes------------------------ --------------------------------------------------------- SWEP.FireModes = {} --------------------------------------- -- Firemode: Semi Automatic -- --------------------------------------- SWEP.FireModes.Semi = {} SWEP.FireModes.Semi.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Semi.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.SemiRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end -- We don't need to do anything for these revert functions, as self.Primary.Automatic, self.Primary.Delay, self.FireModeDrawTable.x, and self.FireModeDrawTable.y are set in every init function SWEP.FireModes.Semi.RevertFunction = function(self) return end SWEP.FireModes.Semi.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("p") -- "p" corresponds to the hl2 pistol ammo icon in this font end --------------------------------------- -- Firemode: Fully Automatic -- --------------------------------------- SWEP.FireModes.Auto = {} SWEP.FireModes.Auto.FireFunction = function(self) self:BaseAttack() end SWEP.FireModes.Auto.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.AutoRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.912*surface.ScreenHeight() end end SWEP.FireModes.Auto.RevertFunction = function(self) return end SWEP.FireModes.Auto.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppppp") end ------------------------------------------- -- Firemode: Three-Round Burst -- ------------------------------------------- SWEP.FireModes.Burst = {} SWEP.FireModes.Burst.FireFunction = function(self) local clip = self.Weapon:Clip1() if not self:CanFire(clip) then return end self:BaseAttack() timer.Simple(self.BurstDelay, function() self:BaseAttack() end ) if clip > 1 then timer.Simple(2*self.BurstDelay, function() self:BaseAttack() end ) end end SWEP.FireModes.Burst.InitFunction = function(self) self.Primary.Automatic = true self.Primary.Delay = 60/self.SemiRPM + 3*self.BurstDelay -- Burst delay is derived from self.BurstRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end SWEP.FireModes.Burst.RevertFunction = function(self) return end SWEP.FireModes.Burst.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("ppp") end ------------------------------------------ -- Firemode: Grenade Launcher -- ------------------------------------------ SWEP.FireModes.Grenade = {} SWEP.FireModes.Grenade.FireFunction = function(self) if not self:CanFire(self.Weapon:Ammo2()) then return end local PlayerAim = self.Owner:GetAimVector() local PlayerAng = PlayerAim:Angle() local PlayerPos = self.Owner:GetShootPos() - PlayerAng:Up()*20 if not self.Weapon:GetNetworkedBool("Ironsights",false) then -- For some reason getattachement is fucked serverside, so we have to do this to get an estimate of the muzzle pos. PlayerPos = PlayerPos + PlayerAng:Right()*20 end if SERVER then local grenade = ents.Create("sent_rg_grenade") grenade:SetPos(PlayerPos) grenade:SetAngles(PlayerAim:Angle()) grenade:SetOwner(self.Owner) grenade:SetVar("Damage",self.GrenadeDamage) grenade:Spawn() local grenphys = grenade:GetPhysicsObject() grenphys:SetVelocity(PlayerAim*self.GrenadeVelocity) grenphys:ApplyForceOffset(VectorRand()*math.Rand(15,30),PlayerPos + VectorRand()*math.Rand(0.5,1.5)) -- Add spinniness end self:TakeSecondaryAmmo(1) -- Shoot Effects self.Weapon:EmitSound(self.Secondary.Sound) self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) -- View model animation self.Owner:SetAnimation(PLAYER_ATTACK1) -- 3rd Person Animation local fx = EffectData() fx:SetEntity(self.Weapon) fx:SetOrigin(PlayerPos) fx:SetNormal(PlayerAim) fx:SetAttachment(self.MuzzleAttachment) util.Effect("rg_muzzle_grenade",fx) -- Additional muzzle effects end SWEP.FireModes.Grenade.InitFunction = function(self) self.Primary.Automatic = false self.Primary.Delay = 60/self.GrenadeRPM if CLIENT then self.FireModeDrawTable.x = 0.037*surface.ScreenWidth() self.FireModeDrawTable.y = 0.922*surface.ScreenHeight() end end SWEP.FireModes.Grenade.RevertFunction = function(self) return end SWEP.FireModes.Grenade.HUDDrawFunction = function(self) surface.SetFont("rg_firemode") surface.SetTextPos(self.FireModeDrawTable.x,self.FireModeDrawTable.y) surface.SetTextColor(255,220,0,200) surface.DrawText("t") -- "t" corresponds to the hl2 smg grenade ammo icon in this font end --------------------------------------------------------- -----------------Init Functions---------------------- --------------------------------------------------------- local sndZoomIn = Sound("Weapon_AR2.Special1") local sndZoomOut = Sound("Weapon_AR2.Special2") local sndCycleZoom = Sound("Default.Zoom") local sndCycleFireMode = Sound("Weapon_Pistol.Special2") function SWEP:Initialize() self:SetWeaponHoldType(self.HoldType) if SERVER then self:SetNPCMinBurst(3) self:SetNPCMaxBurst(6) self:SetNPCFireRate(60/self.AutoRPM) end if CLIENT then -- We need to get these so we can scale everything to the player's current resolution. local iScreenWidth = surface.ScreenWidth() local iScreenHeight = surface.ScreenHeight() -- The following code is only slightly riped off from Night Eag
[QUOTE=TigerMeet2142;45376531]Shared: This is a Gmod 12 Base has has alot of existing code changes in order to be compatible with Gmod 13, hence therer are still some existing bugs I'll be coming back later on.[/QUOTE] Change the following in shared.lua and it should work just fine: [code]function SWEP:Reload( ) // Checks to see if they can use primary / secondary fire meaning the shot / animation should be over... if ( CurTime( ) - self:GetNextPrimaryFire( ) > 0 ) then return false; end if ( CurTime( ) - self:GetNextSecondaryFire( ) > 0 ) then return false; end self:SetIronsights( false, self.Owner ); self:DefaultReload( ACT_VM_RELOAD ); end[/code] If not, I'll dig a little deeper. A lot of the code could be simplified; example you're using different functions for each fire-mode, and you're using a fire function to call a fire function to call the mode function... Your can attack function does the empty sound which may be your issue with the repeated noises being played. I wouldn't even bring that into the mix... I'm all for creating helper-functions and simplifying logic, but there comes a point where you're simplifying to simplify and it ends up making things more complicated than they need to be. Also, self.Weapon is deprecated, it is just self now.
Thanks for helping me out, but It doesnt necessarily works fine at all, it gives no errors but the reload act like its jammed alot, if I fire just a random amound of shots and wanna reload it doesnt do anything unless I fire one shot again. very weird...
You could do something similar then. Basically try this: [code]SWEP.InReload = 0; function SWEP:Reload( ) // One second between reload use... if ( CurTime( ) - self.InReload > 1 ) then return; end self.InReload = CurTime( ); self:SetIronsights( false, self.Owner ); self:DefaultReload( ACT_VM_RELOAD ); end[/code] If that doesn't work, sometimes wrapping helps with SWEPs [code]SWEP.InReload = 0; function SWEP:Reload( ) // One second between reload use... if ( CurTime( ) - self.InReload < 1 ) then self.InReload = CurTime( ); self:SetIronsights( false, self.Owner ); self:DefaultReload( ACT_VM_RELOAD ); end end[/code]
-removed-
Sorry, you need to Log In to post a reply to this thread.