• Hooks
    4 replies, posted
I am trying to learn Lua, but in the tutorials on the garrysmod wiki do not explain what hooks are. [url]http://wiki.garrysmod.com/?title=Lua_Tutorial_Series[/url] Can someone explain what hooks are, and/or add a tutorial there explaining them?
Hooks "hook" into certain functions.. Here's an example, dono if it will make sense. [b]Function[/b] - This is a normal function, no hooks. [lua] function GM:PlayerSpawn(p) Msg("hi!\n") end -- When you spawn you will see the message - hi! - in your console. [/lua] [b]Hook[/b] [lua] function MySpawnFunction(p) Msg("How are you?") end hook.Add("PlayerSpawn", "HookName", MySpawnFunction) -- I just "hooked" into the PlayerSpawn function, no when you spawn -- you will see. -- hi! -- How are you? [/lua] Hope that makes sense.
Basically this hook system lets you set up a function to be run when a certain event happens, like a player dying, an entity taking damage, a prop being spawned etc. So if you wanted to ban a model you'd add a prop spawn hook that checks the model and blocks the prop from being spawned if it's a banned model.
If this clarifies: a hook is a function that is called when the function you have hooked into is called.
Which is exactly why I wonder why most aimbots actually use hooks. Mine doesn't :wink:
Sorry, you need to Log In to post a reply to this thread.