Hooks
What Is It
A Hook
is a way for modding frameworks to call your mod's code every time a certain action happens.
Some Hooks Are:
- If an Entity takes damage
- After a Player picks up an item
- If a locked door can be opened
- After a player pushes a boat
- After a player wakes up
- Before a player respawns
Some hooks control if an action should happen, some trigger after an action happens and some will do both.
How Does It Work
A modding framework such as Oxide will insert their special CallHook
functions throughout the Rust Server code.
A CallHook
function will run any code in your plugin that:
- Matches the name of the hook
- Has the same parameters as the hook
How Do I Use Them
Go to the Oxide Documentation page to see a list of every single hook.
First figure out what you want to do.
For this example we are going to prevent players from damaging boats.
Next we find a hook that relates to what we are trying to do.
We chose the hook OnEntityTakeDamage
as it occurs when damage is dealt but we can block it!
Now We Write The Code
First we copy the hook found in the documentation into our plugin.
Now all we need to do is remove the default code and put in our code.