• Help with a "shotgun-reload" script
    4 replies, posted
[code]AddCSLuaFile() --General SWEP.Base = "dm_baseweapon" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Category = "Testing SWEPs" SWEP.PrintName = "M3 Super 90" --View Model SWEP.ViewModelFOV = 52 SWEP.ViewModel = "models/weapons/cstrike/c_shot_m3super90.mdl" SWEP.ViewModelFlip = false SWEP.UseHands = true --World Model SWEP.WorldModel = "models/weapons/w_pist_usp.mdl" SWEP.HoldType = "pistol" --Primary SWEP.Primary.NumShots = 1 SWEP.Primary.Damage = 10 SWEP.Primary.Spread = 0.02 SWEP.Primary.ClipSize = 8 SWEP.Primary.DefaultClip = 16 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "Buckshot" --Secondary SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" function SWEP:SetupDataTables() self:NetworkVar( "Float", 0, "TimeToReload" ) end function SWEP:Initialize() self:SetTimeToReload( 0 ) self:SetHoldType( "shotgun" ) end function SWEP:ReloadShot( num ) if self:Clip1() >= 8 then self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ) return end self:SendWeaponAnim( ACT_VM_RELOAD ) self:SetClip1( self:Clip1() + num ) end function SWEP:Reload() if self:Clip1() >= 8 or self.Owner:GetAmmoCount( "Buckshot" ) <= 0 then return end self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ) self:SetTimeToReload( CurTime() + self.Owner:GetViewModel():SequenceDuration() ) end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + 0.15 ) if ( !self:CanPrimaryAttack() ) then return end self.Weapon:EmitSound( "Weapon_USP.Single" ) self:ShootBullet( self.Primary.Damage, 4, self.Primary.Spread ) self:TakePrimaryAmmo( 1 ) self.Owner:ViewPunch( Angle( math.Rand( -2, 2 ), math.Rand( -2, 2 ), 0 ) ) end function SWEP:Think() if self:GetTimeToReload() ~= 0 and self:GetTimeToReload() < CurTime() then self:ReloadShot( 1 ) self:SetTimeToReload( CurTime() + self.Owner:GetViewModel():SequenceDuration() ) end end [/code] The whole thing works [i]perfectly[/i], except for one thing I don't know how to do. You see, it reloads fine and all, but the loop goes on forever. Once my clip is at 8, it just repeatedly plays the animation of pumping the gun(as you'd do once you're finished reloading the shotgun). Of course I also need to simply set the next primary fire to the sequence duration to make a better "interupting reload" code too, but for now what I said above is my biggest concern. How would I stop the loop?
[code]function SWEP:Think() if self:GetTimeToReload() ~= 0 and self:GetTimeToReload() < CurTime() then self:ReloadShot( 1 ) if self:Clip1( ) < 8 then self:SetTimeToReload( CurTime() + self.Owner:GetViewModel():SequenceDuration() ) else self:SetTimeToReload( 0 ) end end end[/code] Something like that - you already have a case for it not being zero, so might as well make use of it.
[QUOTE=Kogitsune;48061003][code]function SWEP:Think() if self:GetTimeToReload() ~= 0 and self:GetTimeToReload() < CurTime() then self:ReloadShot( 1 ) if self:Clip1( ) < 8 then self:SetTimeToReload( CurTime() + self.Owner:GetViewModel():SequenceDuration() ) else self:SetTimeToReload( 0 ) end end end[/code] Something like that - you already have a case for it not being zero, so might as well make use of it.[/QUOTE] Thank you! It stops the loop perfectly, but it doesn't play the pumping animation that plays when you finish reloading. The sequence should go as follows: -Run out of 8 shots. -Reload 1 shot until you're at 8 again. -Go back to the idle animation. But, the last step(go back to the idle animation) is missing. You may think I could easily solve my problem by doing this: [code]function SWEP:Think() if self:GetTimeToReload() ~= 0 and self:GetTimeToReload() < CurTime() then self:ReloadShot( 1 ) if self:Clip1( ) < 8 then self:SetTimeToReload( CurTime() + self.Owner:GetViewModel():SequenceDuration() ) else self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ) self:SetTimeToReload( 0 ) end end end [/code] But on my 8th time putting a shell in, it plays the idle animation [i]instead[/i] of inserting a shell, [i]then[/i] playing the animation. I hope you understand what I mean.
Shouldn't that be ACT_SHOTGUN_RELOAD_FINISH?
[QUOTE=Kogitsune;48061078]Shouldn't that be ACT_SHOTGUN_RELOAD_FINISH?[/QUOTE] Yes. Sorry. Even with that though, it still doesn't get the desired effect. What's happening is that on my 8th reload it doesn't insert a shell [i]then[/i] go back to the idle animation, it just goes back to the idle animation. How would I make it insert a shell then go back to the animation?
Sorry, you need to Log In to post a reply to this thread.