Skip to content

Commit f892fd6

Browse files
Added holdtype for hold prop
1 parent 2585e79 commit f892fd6

File tree

1 file changed

+37
-7
lines changed
  • gamemode/modules/attributes/entities/weapons/lia_hands

1 file changed

+37
-7
lines changed

gamemode/modules/attributes/entities/weapons/lia_hands/shared.lua

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SWEP.PrintName = L("handsWeaponName")
1+
SWEP.PrintName = L("handsWeaponName")
22
SWEP.Slot = 0
33
SWEP.SlotPos = 1
44
SWEP.DrawAmmo = false
@@ -29,17 +29,20 @@ SWEP.LowerAngles = Angle(0, 5, -14)
2929
SWEP.LowerAngles2 = Angle(0, 5, -19)
3030
SWEP.KnockViewPunchAngle = Angle(-1.3, 1.8, 0)
3131
SWEP.FireWhenLowered = true
32-
SWEP.HoldType = "fist"
32+
SWEP.HoldType = "normal"
3333
SWEP.holdDistance = 64
3434
SWEP.maxHoldDistance = 96
3535
SWEP.maxHoldStress = 4000
3636
ACT_VM_FISTS_DRAW = 2
3737
ACT_VM_FISTS_HOLSTER = 1
38+
3839
function SWEP:Initialize()
3940
self:SetHoldType(self.HoldType)
4041
self.lastHand = 0
4142
self.maxHoldDistanceSquared = self.maxHoldDistance ^ 2
4243
self.heldObjectAngle = Angle(angle_zero)
44+
self.lastPunchTime = 0
45+
self.isFistHold = false
4346
end
4447

4548
function SWEP:Deploy()
@@ -77,6 +80,11 @@ function SWEP:Think()
7780
local viewModel = self:GetOwner():GetViewModel()
7881
if IsValid(viewModel) and self.NextAllowedPlayRateChange < CurTime() then viewModel:SetPlaybackRate(1) end
7982
else
83+
if self.isFistHold and (CurTime() - (self.lastPunchTime or 0) > 5) then
84+
self:SetHoldType("normal")
85+
self.isFistHold = false
86+
end
87+
8088
if self:IsHoldingObject() then
8189
local physics = self:GetHeldPhysicsObject()
8290
local bIsRagdoll = self.heldEntity:IsRagdoll()
@@ -198,6 +206,8 @@ function SWEP:DropObject(bThrow)
198206
end)
199207
end
200208

209+
self:SetHoldType("normal")
210+
201211
self.heldEntity.ixHeldOwner = nil
202212
self.heldEntity.ixCollisionGroup = nil
203213
self.heldEntity = nil
@@ -227,13 +237,19 @@ end
227237

228238
function SWEP:PrimaryAttack()
229239
if not IsFirstTimePredicted() then return end
240+
230241
if SERVER and self:IsHoldingObject() then
231242
self:DropObject(true)
232243
return
233244
end
234245

235-
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
246+
if not self.isFistHold then
247+
self:SetHoldType("fist")
248+
self.isFistHold = true
249+
end
250+
236251
if hook.Run("CanPlayerThrowPunch", self:GetOwner()) == false then return end
252+
237253
local staminaUse = lia.config.get("PunchStamina")
238254
if staminaUse > 0 then
239255
local owner = self:GetOwner()
@@ -243,19 +259,32 @@ function SWEP:PrimaryAttack()
243259
if SERVER then owner:consumeStamina(staminaUse) end
244260
end
245261

246-
if SERVER then self:GetOwner():EmitSound("npc/vort/claw_swing" .. math.random(1, 2) .. ".wav") end
247-
self:DoPunchAnimation()
248-
self:GetOwner():SetAnimation(PLAYER_ATTACK1)
249-
self:GetOwner():ViewPunch(Angle(self.lastHand + 2, self.lastHand + 5, 0.125))
262+
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
263+
264+
if SERVER then
265+
self:GetOwner():EmitSound("npc/vort/claw_swing" .. math.random(1, 2) .. ".wav")
266+
end
267+
268+
-- I can't do it without timer, my bad :(
269+
timer.Simple(0.1, function()
270+
self:DoPunchAnimation()
271+
self:GetOwner():SetAnimation(PLAYER_ATTACK1)
272+
self:GetOwner():ViewPunch(Angle(self.lastHand + 2, self.lastHand + 5, 0.125))
273+
end)
274+
275+
self.lastPunchTime = CurTime()
276+
250277
timer.Simple(0.055, function()
251278
if not IsValid(self) or not IsValid(self:GetOwner()) then return end
279+
252280
local damage = self.Primary.Damage
253281
local context = {
254282
damage = damage
255283
}
256284

257285
local result = hook.Run("GetPlayerPunchDamage", self:GetOwner(), damage, context)
258286
damage = result ~= nil and result or context.damage
287+
259288
self:GetOwner():LagCompensation(true)
260289
local startPos = self:GetOwner():GetShootPos()
261290
local endPos = startPos + self:GetOwner():GetAimVector() * 96
@@ -319,6 +348,7 @@ function SWEP:SecondaryAttack()
319348
self:PickupObject(entity)
320349
self:PlayPickupSound(trace.SurfaceProps)
321350
self:SetNextSecondaryFire(CurTime() + self.Secondary.Delay)
351+
self:SetHoldType("pistol")
322352
end
323353
end
324354
end

0 commit comments

Comments
 (0)