I am having troubles finding a way to find out if a player is reloading or not. I have looked around and found a code snippet that i will show below, but the problem with this is it checks only every time a animation happens, therefor, when reloading is done, It doesn't update until another animation happens such as jumping.
local function CheckReload(pl, event, data)
if event == PLAYERANIMEVENT_RELOAD then
reloadinggun = true
else
reloadinggun = false
end
end
hook.Add("DoAnimationEvent", "CheckPlayerReload", CheckReload)
I am using the reloadinggun variable to just check true or false. If there is a better way to do this, it would help a lot! Thanks for any support!
To turn your var "reloadinggun" back to false I guess you can try OnReloaded.
For your Player:Alive() issue, maybe you could try to check the player's health is equal to 0 with Entity:Health. I've never experienced that issue before, are you sure you're doing it correctly?
An alternative to your reloading check would be to check the amount of ammo.
local function IsReloading(ply)
if(!IsValid(ply) or (!ply:Alive or ply:Health() == 0)) then return false end --Checking if the player is valid, you can do it before calling this function
local wep = ply:GetActiveWeapon()
if(!IsValid(wep)) then return false end --checking if the player has a valid weapon
return wep:HasAmmo() and wep:Clip1() == 0 --returning if the player has ammos and the clip isn't empty
end
You can try this function and do whatever you want from it, i didn't test it so maybe it won't work.
Yea, the SWEP:OnReloaded is a SWEP only function i believe so that wouldn't work on what i am making which is a HUD but the entity:health issue was a problem with my code, i failed to verify if the wep was valid therefor it was trying to run checks on a wep that was never there. Fixed it up though, if anyone still has a better way to check if someone is reloading other than a timer setting a variable when the reload event is called please let me know thank your for any advice!
Sorry, you need to Log In to post a reply to this thread.