Using the Think hook

I was just wondering, when using a think hook, is it in any way putting more “pressure” on the server?
Since it runs a function on every single tick, does it have any effect?

Depends entirely on what you’re doing inside the hook.

if Something(Very rare event) then
--blah blah blah

Think functions generally aren’t expensive as long as you know what you are doing.
Most or if not all objects in gmod have multiple think functions being called every frame. You should be fine.

As long as you’re not calling expensive functions like ents.FindInSphere, net messages or timers inside Think hooks you’ll pretty much be fine. Although

gives literally no insight as to how expensive the think hook you’re running is.

I think the actual question is in relation to an if statement check that will rarely return true

but what is the statement in the if()? It could be a very expensive statement or could be cheap.
We need to know the function.

If the event is active (if GetConVar( “blah_blah_blah” ):GetInt() == 1), check if a player has certain weapons, and if he does strip them, then give him a different weapon.

I always tend to try and avoid using Think functions as much as possible. If you want to check for an event, it’d be better to just call whatever code you have in a function you make and then calling that function when the event starts, rather than in a think hook.

Say, someone pushes a button and that makes every player lose all their weapons. Instead of changing a convar and think’ing it, just strip the weapons the moment when the button is pushed. Then make a variable that says the event is going on, and then check for that every time you would give a player the weapons, say, in PlayerSpawn.

It is generally good practice to only check the variable the moment it would have any impact (in the above case, when giving weapons and when the variable changes).

Or use this


I really wish it were that simple…
Maybe it’s just me, but I’m having a ridiculously hard time getting cvar callbacks to work serverside…

I’m really not attempting to hijack this thread, but if you or anyone could please take a look at the problem I posted yesterday ( link: ), I’d greatly appreciate some insight.

Sorry for being so vague about the code (It’s really nothing complicated as well…)
I made an event that runs when a ConVar is set to 1, but the event only lasts 1 round.
However, I need to check for if the player has weapons at all times he might not have them.
So I can change the code to not work with think hooks but with multiple hooks that will all run the command.

My question is: Should I?


And please don’t try to help me on the way the event is ran (There are probably way simpler ways than a ConVar), I’d rather keep it to the title of this thread.

No, you don’t. You shouldn’t even need to check more than once.

Strip bad weapons


Prevent from picking up bad weapons