• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Library] y_hooks 4 - Hook callbacks, functions, and natives.
#1
Introduction



After some discussion recently, I have finally gotten around to updating y_hooks. You can now hook callbacks (publics), functions (your own code), and natives! The full documentation is on github:



https://github.com/pawn-lang/YSI-Includes/tree/5.x



But in short, there are three types of hooks: original, callback, and function.



Original



Originals are still the fastest (faster even than a normal function call) and simplest, but can only hook publics:



PHP Code:
#include <YSI_Coding\y_hooks>



hook OnPlayerConnect(playerid)

{

    
SendClientMessage(playeridCOLOUR_GREETING"Welcome!");





The system will call each hook of a public in the order they are declared. When one ends the next starts. There is a way to stop the chain entirely, such that no more hooks are called, but this is all the control given. These can hook callbacks that don't even exist, you don't need `public OnPlayerConnect` anywhere in code for this example to work.



Function



A function hook hooks a function - i.e. something called within the script. This includes pawn functions and natives:



PHP Code:
#include <YSI_Coding\y_hooks>



hook function SetPlayerPos(playeridFloat:xFloat:yFloat:z)

{

    return continue(
playeridxyz  0.1);





Every time `SetPlayerPos` is used in the script, this hook will be called first. `continue` is an explicit call to the next function in the chain - this may be another hook or the original code (a native in this case).



Callback



A callback hook combines the hooking of callbacks from original hooks with the explicit chaining of function hooks:



PHP Code:
#include <YSI_Coding\y_hooks>



hook callback OnPlayerConnect(playerid)

{

    
SendClientMessage(playeridCOLOUR_GREETING"Welcome!");

    return continue(
playerid);





Note that I haven't ACTUALLY written this last one 1yet.
  Reply


Messages In This Thread
y_hooks 4 - Hook callbacks, functions, and natives. - by Y_Less - 2019-06-02, 09:14 PM

Forum Jump: