Skip to content

Commit

Permalink
Weapons: Shotgun changes (#1554)
Browse files Browse the repository at this point in the history
- Added SWEP.DryFireSound to the weapon base to allow the dryfire sound
to be easily changed (now used by the shotgun)
- Applied dryfire sound fix to the shotgun
- Allowed the shotgun to attempt reloading on dryfire
- Interrupting the shotgun's reload looks and feels less jank
- Added a third person reload animation to the shotgun

Side note: while making these changes, I only now realised that the
dryfire sound only plays for the player holding the weapon. I think this
is fine but I thought I would ask, should we instead let the sound be
audible to anyone near the player? I can make another PR if so
  • Loading branch information
TW1STaL1CKY authored Jun 13, 2024
1 parent e471dfb commit afdfd91
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added `admin.IsAdmin(ply)` as a wrapper that automatically calls `GM:TTT2AdminCheck` (by @TimGoll)
- Made sure this new function is used in our whole codebase for all admin checks
- Added `ENTITY:IsPlayerRagdoll` to check if a corpse is a real player ragdoll (by @TimGoll)
- Added the `SWEP.DryFireSound` field to the weapon base to allow the dryfire sound to be easily changed (by @TW1STaL1CKY)

### Changed

Expand All @@ -62,6 +63,10 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Updated the Turkish localization file (by @NovaDiablox)
- The level time now starts with the first preparing phase, meaning that idle on connect doesn't decrease the map time (by @TimGoll)
- Minor cleanup and optimizations in weapon code (by @TW1STaL1CKY)
- Shotgun weapon changes (by @TW1STaL1CKY)
- Dry firing (attempting to shoot with no ammo) will now make you reload if possible, like all the other weapons do
- Interrupting the reload should look and feel less jank
- A thirdperson animation now plays when each shell is loaded (the pistol reload animation seems to fit best)
- Now always properly checks if an entity is a true ragdoll to make sure no other props get ragdoll handling (by @TimGoll)
- Spectators are now able to look at corpses on fire (by @TimGoll)
- Corpses on fire display that information in targetID and MStack (by @TimGoll)
Expand Down
4 changes: 3 additions & 1 deletion gamemodes/terrortown/entities/weapons/weapon_tttbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ SWEP.Secondary.ClipMax = -1

SWEP.HeadshotMultiplier = 2.7

SWEP.DryFireSound = ")weapons/pistol/pistol_empty.wav"

SWEP.StoredAmmo = 0
SWEP.IsDropped = false

Expand Down Expand Up @@ -980,7 +982,7 @@ end
-- @realm shared
function SWEP:DryFire(setnext)
if CLIENT and LocalPlayer() == self:GetOwner() then
self:EmitSound(")weapons/pistol/pistol_empty.wav", 75, 100, 0.7, CHAN_ITEM)
self:EmitSound(self.DryFireSound, 75, 100, 0.7, CHAN_ITEM)
end

setnext(self, CurTime() + 0.2)
Expand Down
75 changes: 38 additions & 37 deletions gamemodes/terrortown/entities/weapons/weapon_zm_shotgun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ SWEP.Primary.NumShots = 8
SWEP.Primary.Sound = Sound("Weapon_XM1014.Single")
SWEP.Primary.Recoil = 7

SWEP.DryFireSound = ")weapons/shotgun/shotgun_empty.wav"

SWEP.AutoSpawnable = true
SWEP.Spawnable = true
SWEP.AmmoEnt = "item_box_buckshot_ttt"
Expand All @@ -53,21 +55,14 @@ SWEP.IronSightsAng = Vector(-0.101, -0.7, -0.201)
function SWEP:SetupDataTables()
self:NetworkVar("Bool", 0, "Reloading")
self:NetworkVar("Float", 0, "ReloadTimer")
self:NetworkVar("Float", 1, "ReloadInterruptTimer")

return BaseClass.SetupDataTables(self)
end

---
-- @ignore
function SWEP:Reload()
if
self:GetReloading()
or self:Clip1() > self.Primary.ClipSize
or self:GetOwner():GetAmmoCount(self.Primary.Ammo) < 0
then
return
end

self:StartReload()
end

Expand All @@ -78,21 +73,27 @@ function SWEP:StartReload()
return false
end

self:SetIronsights(false)
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

local owner = self:GetOwner()

if not owner or owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
if
not IsValid(owner)
or self:Clip1() >= self.Primary.ClipSize
or owner:GetAmmoCount(self.Primary.Ammo) <= 0
then
return false
end

if self:Clip1() >= self.Primary.ClipSize then
return false
end
local now = CurTime()

self:SetIronsights(false)
self:SetNextPrimaryFire(now + self.Primary.Delay)

self:SendWeaponAnim(ACT_SHOTGUN_RELOAD_START)
self:SetReloadTimer(CurTime() + self:SequenceDuration())

local sequenceDuration = self:SequenceDuration()

self:SetReloadTimer(now + sequenceDuration)
self:SetReloadInterruptTimer(now + sequenceDuration * 0.4)
self:SetReloading(true)

return true
Expand All @@ -103,46 +104,41 @@ end
function SWEP:PerformReload()
local owner = self:GetOwner()

-- prevent normal shooting in between reloads
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

if
not owner
or owner:GetAmmoCount(self.Primary.Ammo) <= 0
not IsValid(owner)
or self:Clip1() >= self.Primary.ClipSize
or owner:GetAmmoCount(self.Primary.Ammo) <= 0
then
return
end

owner:RemoveAmmo(1, self.Primary.Ammo, false)
local now = CurTime()

-- Prevent normal shooting in between reloads
self:SetNextPrimaryFire(now + self.Primary.Delay)

owner:RemoveAmmo(1, self.Primary.Ammo, false)
self:SetClip1(self:Clip1() + 1)

owner:DoAnimationEvent(ACT_HL2MP_GESTURE_RELOAD_PISTOL)
self:SendWeaponAnim(ACT_VM_RELOAD)
self:SetReloadTimer(CurTime() + self:SequenceDuration())

local sequenceDuration = self:SequenceDuration()

self:SetReloadTimer(now + sequenceDuration)
self:SetReloadInterruptTimer(now + sequenceDuration * 0.8)
end

---
-- @ignore
function SWEP:FinishReload()
self:SetReloading(false)

self:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)

self:SetReloadTimer(CurTime() + self:SequenceDuration())
end

---
-- @ignore
function SWEP:CanPrimaryAttack()
if self:Clip1() <= 0 then
self:EmitSound("Weapon_Shotgun.Empty")
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

return false
end

return true
end

---
-- @ignore
function SWEP:Think()
Expand All @@ -154,7 +150,11 @@ function SWEP:Think()

local owner = self:GetOwner()

if owner:KeyDown(IN_ATTACK) then
if
owner:KeyDown(IN_ATTACK)
and self:Clip1() >= 1
and self:GetReloadInterruptTimer() <= CurTime()
then
self:FinishReload()
elseif self:GetReloadTimer() <= CurTime() then
if owner:GetAmmoCount(self.Primary.Ammo) <= 0 then
Expand All @@ -172,6 +172,7 @@ end
function SWEP:Deploy()
self:SetReloading(false)
self:SetReloadTimer(0)
self:SetReloadInterruptTimer(0)

return BaseClass.Deploy(self)
end
Expand Down

0 comments on commit afdfd91

Please sign in to comment.