SA-MP Forums Archive
y_hooks explanation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: y_hooks explanation (/showthread.php?tid=570804)



y_hooks explanation - Denis1 - 13.04.2015

May I ask for an explanation? What does it do? What can it help me with?


Re: y_hooks explanation - Azula - 13.04.2015

........ from https://sampforum.blast.hk/showthread.php?tid=392061
Quote:

Hooking means to add something on a particular thing. Here, we refer it to adding something too on a callback or function. For example, function 'SetPlayerScore' sets the player's score. But if we are using a server sided score system, the 'SetPlayerScore' won't set it. So, we've gotta set that server sided score too by setting variables.




Re: y_hooks explanation - Dignity - 13.04.2015

If you want to actually learn what hooks are and how to use them, read the replies in a topic I made earlier: https://sampforum.blast.hk/showthread.php?tid=531197

y_hooks simplifies hooking, only needing you to do this:
pawn Код:
hook function(playerid)
{
// something
}
A normal hook (ALS method 7) would look like this:

pawn Код:
public function(playerid)
{
    #if defined something_function
        return something_function(playerid);
    #else
        return true;
    #endif
}

#if defined _ALS_function
    #undef function
#else
    #define _ALS_function
#endif
#define function something_function
#if defined something_function
    forward something_function(playerid);
#endif
The only requirement is that you include y_hooks in every file you use hooks in, because y_hooks generates unique function names.

Source: http://ysi.wikia.com/wiki/Library:YSI%5Cy_hooks

It may not be up for long though as ****** left SA-MP today and binned all of his content.

EDIT: Please read what Southclaw wrote, as it covers a lot I didn't. I personally never used y_hooks so I can't give a lot of info.

Quote:
Originally Posted by Southclaw
Public functions and regular functions can be hooked and they require different methods. The two primary methods of hooking are: ALS and y_hooks (only works on publics).