• Playing the shotgun reload animation
    15 replies, posted
[url]http://wiki.garrysmod.com/?title=Talk:Activity[/url] That's the link to the activities page. Yes, as you can tell from the talk page, I'm Chicken on the wiki. I've been looking and looking, and I can't find the activity that happens when you reload a shotgun. (The activity where you stuff a shell into it) Where is it? Also, if you know, how do I change SWEP:Reload() to not give me any bullets? I want to do it myself because it gives me my entire clip all at once. I wish I knew how to reload one bullet at a time...
I had this same exact problem. [HD]http://www.youtube.com/watch?v=BP8y0axzJvw[/HD]
look at the source code for gamemodes/sweps that have already done it
It's hard to figure out which part it doing it usually, and sometimes it's coded all throughout the swep so it's tricky to implement in your swep.
[CODE]function SWEP:Think() if ( self.Weapon:GetNetworkedBool( "reloading", false ) ) then if ( self.Weapon:GetVar( "reloadtimer", 0 ) < CurTime() ) then // Finsished reload - if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then self.Weapon:SetNetworkedBool( "reloading", false ) return end // Next cycle self.Weapon:SetVar( "reloadtimer", CurTime() + 0.3 ) self.Weapon:SendWeaponAnim( ACT_VM_RELOAD ) // Add ammo self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false ) self.Weapon:SetClip1( self.Weapon:Clip1() + 1 ) // Finish filling, final pump if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ) else end end end end [/CODE] Uhh, copypasta from the CS_base pump shotgun, but would this be what you are looking for? Specifically: [CODE] // Add ammo self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false ) self.Weapon:SetClip1( self.Weapon:Clip1() + 1 ) [/CODE]
Okay, I tried your method, and it just gives me the no ammo click when I try to shoot at zero ammo, and when I press 'r', nothing happens! This is my code: [lua] SWEP.Base = "weapon_base" pumpTime = 0 pump = false -- Visual/sound settings SWEP.PrintName = "Super Shotgun" SWEP.Slot = 3 SWEP.SlotPos = 4 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 64 SWEP.ViewModel = "models/weapons/v_shotgun.mdl" SWEP.WorldModel = "models/weapons/w_shotgun.mdl" SWEP.ReloadSound = "weapons/shotgun/shotgun_reload2.wav" SWEP.HoldType = "shotgun" -- Other settings SWEP.Weight = 4 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Spawnable = false SWEP.AdminSpawnable = true -- SWEP info SWEP.Author = "Awesomeness" SWEP.Contact = "" SWEP.Purpose = "" SWEP.Instructions = "Aim away from face." -- Primary fire settings SWEP.Primary.Sound = "weapons/shotgun/shotgun_fire7.wav" SWEP.Primary.PumpSound = "weapons/shotgun/shotgun_cock.wav" SWEP.Primary.Damage = 9999 SWEP.Primary.NumShots = 99 SWEP.Primary.Recoil = 1 SWEP.Primary.Cone = 30 SWEP.Primary.Delay = 0.75 SWEP.Primary.ClipSize = 6 SWEP.Primary.DefaultClip = 99999999 SWEP.Primary.Tracer = 1 SWEP.Primary.Force = 100 SWEP.Primary.TakeAmmoPerBullet = false SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "Buckshot" -- Secondary fire settings SWEP.Secondary.Sound = "" SWEP.Secondary.Damage = 0 SWEP.Secondary.NumShots = 0 SWEP.Secondary.Recoil = 0 SWEP.Secondary.Cone = 0 SWEP.Secondary.Delay = 0 SWEP.Secondary.ClipSize = 0 SWEP.Secondary.DefaultClip = 0 SWEP.Secondary.Tracer = 0 SWEP.Secondary.Force = 0 SWEP.Secondary.TakeAmmoPerBullet = true SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" -- Hooks function SWEP:Initialize() if ( SERVER ) then self:SetWeaponHoldType( self.HoldType ) end end function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end local bullet = {} -- Set up the shot bullet.Num = self.Primary.NumShots bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector( self.Primary.Cone / 90, self.Primary.Cone / 90, 0 ) bullet.Tracer = self.Primary.Tracer bullet.Force = self.Primary.Force bullet.Damage = self.Primary.Damage bullet.AmmoType = self.Primary.Ammo self.Owner:FireBullets( bullet ) self.Owner:MuzzleFlash() self.Owner:SetAnimation( PLAYER_ATTACK1 ) self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) pumpTime = CurTime() + 0.3 pump = true self.Weapon:EmitSound(Sound(self.Primary.Sound)) self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0, 0 )) if (self.Primary.TakeAmmoPerBullet) then self:TakePrimaryAmmo(self.Primary.NumShots) else self:TakePrimaryAmmo(1) end self:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) end function SWEP:SecondaryAttack() end function SWEP:Think() if (pumpTime <= CurTime() && pump == true) then self.Weapon:SendWeaponAnim( ACT_SHOTGUN_PUMP ) self.Weapon:EmitSound(Sound(self.Primary.PumpSound)) pump = false end if ( self.Weapon:GetNetworkedBool( "reloading", false ) ) then if ( self.Weapon:GetVar( "reloadtimer", 0 ) < CurTime()) then // Finsished reload - if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then self.Weapon:SetNetworkedBool( "reloading", false ) return end // Next cycle self.Weapon:SetVar( "reloadtimer", CurTime() + 0.3 ) self.Weapon:SendWeaponAnim( ACT_VM_RELOAD ) // Add ammo self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false ) self.Weapon:SetClip1( self.Weapon:Clip1() + 1 ) // Finish filling, final pump if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ) else end end end end function SWEP:Reload() --self.Weapon:DefaultReload(ACT_SHOTGUN_RELOAD_START) --self.Weapon:DefaultReload(ACT_SHOTGUN_RELOAD_FINISH) --self.Weapon:DefaultReload(ACT_RELOAD_SHOTGUN) return true end function SWEP:Deploy() return true end function SWEP:Holster() return true end function SWEP:OnRemove() end function SWEP:OnRestore() end function SWEP:Precache() end function SWEP:OwnerChanged() end [/lua] What am I doing wrong? =(
Also, I have discovered it reloads when I reload a different weapon. I don't understand what's going on... [editline]10:00PM[/editline] Please guys, I need to know! I'm so close to making my shotgun's behavior identical to a normal one! I've found the sounds, the animations, the delay times, the models, and everything, but I just haven't been able to do this last one! Please!
...Where is everyone?
You simply copy pasted code hoping it would magically work right? Looking at your code you don't even have a reload function so I'm not surprised nothing at all is happening.
I'm sorry, I really don't know how it works. I don't know enough. I'm asking for help. Just by looking at Lua, I've learned its syntax like any other developer, but I don't understand how Lua ties in with the Source Engine. As this is my first SWEP as well as the first thing I have ever made in Lua, you are going to have to enlighten me. I had originally noticed that the code Grasp had shown me was in the Think() method. I have learned the hard way (through trial and error) that anything put in there happens each frame. Since shotgun reloading is not instantaneous, I thought a delay would happen. The if blocks checked the value of the networked boolean, (What IS a networked boolean, by the way?) "reloading," so I assumed that the reloading code inside Think() would be called when the character reloads and the Reload() method is called. In other words, I thought calling Reload() would change the value of "reloading. I'm probably totally wrong. I really need help, please, and I'm sorry if I looked stupid... =( It's just the documentation for Lua on the wiki doesn't help me very much, and there are almost no examples for anything, and certainly not a tutorial on the reloading of shotguns. Can you please help me?
A networked boolean is a boolean value (true or false) that is available to both the client and the server. For it to change value you will have to do it explicitely, like in your reload function (Not saying it will make your script work but it's a start). Oh and the fastest way to find out what a function does is always to use the wiki! :smile: [b][url=wiki.garrysmod.com/?title=Entity.GetNetworkedBool]Entity.GetNetworkedBool [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=wiki.garrysmod.com/?title=Entity.SetNetworkedBool]Entity.SetNetworkedBool [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Sorry to just say this, but it's kind of annoying when someone busts in and goes, "CODE THIS FOR ME" lol
Sorry for the late, late, late reply. I had forgotten about the forum for a while. How did Chad get banned? Anyways, I'm not asking for you to code the whole gun for me. I've done that myself. All I'm asking is how to play the shotgun reload animation where the player stuffs the shell in the gun. And yes, I checked the wiki's Activity list, (that's where I got the other animations for the shotgun from) and I can't find it. All I'm asking for is the name of the Activity.
Hello?
For what I can see on the Activity list its: ACT_SHOTGUN_RELOAD_START = 244 ACT_SHOTGUN_RELOAD_FINISH = 245 I might be wrong. I just saw the SHOTGUN The list is here: [url]http://wiki.garrysmod.com/?title=Activity[/url] There is more then one reload function so try them all? :3 Trail and Error!
[QUOTE=Trivkz;20895314]For what I can see on the Activity list its: ACT_SHOTGUN_RELOAD_START = 244 ACT_SHOTGUN_RELOAD_FINISH = 245 I might be wrong. I just saw the SHOTGUN The list is here: [url]http://wiki.garrysmod.com/?title=Activity[/url] There is more then one reload function so try them all? :3 Trail and Error![/QUOTE] Sorry for very late reply. I've already tried both of them.
Sorry, you need to Log In to post a reply to this thread.