I am making a weapon raising / lowering system with startcommand. When you hold R, it toggles weapon raising. When you simple press R, it reloads.
Here’s the code:
-- Prevent weapon firing when lowered
local KEY_BLACKLIST = IN_ATTACK + IN_ATTACK2
function SheepStartCommand( pl, cmd )
if pl.SheepWeaponRaised == nil then
pl.SheepWeaponRaised = true
end
if ( pl.SheepWeaponRaised == false ) then
cmd:RemoveKey( KEY_BLACKLIST )
end
--
pl.SheepAimingIronsights = bit.band(cmd:GetButtons(), IN_ATTACK2) ~= 0
-- Weapon raising / lowering
-- This is part of the "server needs to know we removed IN_RELOAD" thing
-- BUT this is "AFTER" we go through all the code, we need to reset the server's holdingR variable
if CLIENT then
net.Start("SendSheepHoldingR")
net.WriteBool( false )
net.SendToServer()
end
pl.HoldingR = bit.band(cmd:GetButtons(), IN_RELOAD) ~= 0
-- When we iterate on client, we're removing IN_RELOAD so we'll have to let the server know.
if CLIENT and pl.HoldingR then
net.Start("SendSheepHoldingR")
net.WriteBool( true )
net.SendToServer()
end
cmd:RemoveKey( IN_RELOAD )
-- Telling the server that we did indeed press reload.
if SERVER then
if pl.ServerSideHoldingR == true then
pl.HoldingR = true
end
end
if pl.HoldingR then
--print("holding R!...")
if pl.MidWeaponRaise == nil then pl.MidWeaponRaise = false end
if !pl.MidWeaponRaise then
pl.HoldingRStartTime = CurTime()
pl.MidWeaponRaise = true
pl.Reloaded = false
end
pl.MidWeaponReload = false
else
pl.MidWeaponRaise = false
-- Reload
end
if pl.HoldingRStartTime then
if pl.HoldingR then
--print("taking the potential holster event path...")
if pl.HoldingR and ((CurTime() - pl.HoldingRStartTime) >= 0.5) then
--print("doing the holster event")
pl.SheepWeaponRaised = !pl.SheepWeaponRaised
if SERVER then
end
pl.MidWeaponRaise = false
return
end
end
-- If we've pressed R for less than 0.5 seconds, simply reload as usual
if !pl.HoldingR and ((CurTime() - pl.HoldingRStartTime) < 0.5) and !pl.Reloaded then
print("doing the reloading event")
cmd:AddKey( IN_RELOAD )
pl.MidWeaponRaise = false
pl.Reloaded = true
pl.ReloadFinishTime = CurTime()
return
end
end
end
hook.Add("StartCommand", "SheepStartCommand", SheepStartCommand)
Problem: Aside from everything else working fine, reloading is now completely silent most of the time
Any help would be appreciated, thank you!