• Check if Ammo just decreased
    3 replies, posted
Maybe really simple, maybe hard, or maybe even impossible. I´ve tryd to find a way or maybe even a hook that gets called when the player shoots, but i cannot seem to find one. So what i basically need is a way to start a piece of code as soon as the player shoots a weapon. (not physgun and stuff, weapons with bullets), or when his ammo got less. Checking for ammo got less would be better than shooting because then i wouldnt need to add to the check if the weapon is physgun etc. Is there a way to check that in a if statement, or use a hook or anything? Or is my idea impossible in gmod? Also, maybe someone can also answer me this: is there a way to refresh the code, without using the hook Think or Tick? Based on experience and other threads i made that just reloads my code way too fast, generating several random numbers, playing several sounds at the same time (thats bad)
Not impossible with a think hook, you just don't really seem to understand how it works. This is one of my utility functions: https://gist.github.com/JohnsonMcBig/bb8b39719664d77fb9992ad53e4da5df Of course you could make something similar that's more efficient for your case, but if you can't, then you can use this function which covers all cases. Example: hook.Add("Think", "name_change_listener", function() for _, ply in pairs(player.GetAll()) do if not IsValid(ply) then continue end TriggerUponChange("name_change", ply:SteamID(), ply:GetName()) end end)
TriggerUponChange sounds like exacly what i need. ...as soon as i found out how it works
It's just a wrapper to have callback functions for events, but there currently is no way to detect when ammo changes. I have made a request here.
Sorry, you need to Log In to post a reply to this thread.