Solved How do hooks work?

Discussion in 'Rust Development' started by Pois0n, Jun 11, 2018.

  1. This may be too general but I'm a newbie to game development and maybe in general with Rust being the first game I've written code for but I've been writing / fixing up plugins learning like crazy and now I need to know how hooks work. Recently I came across a plugin that creates custom objects with built in hooks like OnPlayerInteractWithCustomObject and it got me thinking, why does this work? If anyone could give me a basic overview of why the hooks work, even the oxide ones such as OnPlayerInit(). I get that events trigger them but how does it all link up, is it a naming scheme or something else? Thanks in advance.
     
  2. Wulf

    Wulf Community Admin

    That would just be a method, not really a hook. A hook is something in Oxide or a plugin that something outside of it calls. Generally though, a hook would mainly be what Oxide injects or provides for plugins.

    How a hook works in Oxide:
    1. Hook is injected into game at a certain area
    2. When that area is called in the game, the hook is hit
    3. Oxide then calls all plugins that implement that hook
    The "On" in the hook name is a naming scheme; the same would apply to the "Can" hooks, but "Can" hooks generally imply there is a way to cancel them. Any "hooks" in plugins other than what Oxide provides directly are just methods that other plugins can call; which some refer to as API. In the case of "OnPlayerInteractWithCustomObject", that's just a method naming choice by the author of that plugin.
     
  3. Ok, I think I follow.

    How does the method get called then? Even the oxide ones such as OnServerInitialized(), what is the relation between oxide and that method since there is no hard code reference to oxide when you define the method in your plugin why do they get connected.

    For example the code I'm looking at is for zones. A zone is a defined object with a radius and starting position x, y, z. Internally defined methods on the object such as OnPlayerEnterZone exist and get called, I'm just trying to figure out how that is possible.
     
  4. Wulf

    Wulf Community Admin

    Oxide calls them when the game gets to that point where the hook is injected. OnPlayerEnterZone would be a custom method specific to that plugin, not an actual Oxide hook.