[Tutorial] Hook Method Statement By Willian_Luigi.
#1

What is Hook?
Hooking is done with one function call another function apparently the same name, thus "chaining" all these similar functions together so that they all get a flame. Hook functions to this is easy because the chain calls the previous function of the same name, however, hooking returns is complicated by the fact that the chain of calls the next function of the same name - a role that has not been defined yet and can not even exist.

Hooking CallBack

We will need a variable at the top, in my case will be:
pawn Code:
stock hooking;
Now define when to start hooking be true:
pawn Code:
main()
{
    state hooking:true;
}
Now let's create our Callback hooked (in my case I will hook the OnPlayerConnect):
pawn Code:
public OnPlayerConnect(playerid) <hooking:true>
{
    state hooking:false;

    // functions of your hooked Callback

    return OnPlayerConnect(playerid);
}
Now we can create our normal callback.
pawn Code:
public OnPlayerConnect(playerid) <hooking:false>
{
    state hooking:true;

    // functions of your original CallBack

    return 1;
}
Ready Hooked is a CallBack to the method hook state.


Hooking Functions

We will need a variable at the top, in my case will be:
pawn Code:
stock hooking;
Now define when to start hooking be true:
pawn Code:
main()
{
    state hooking:true;
}
Now let's create our Function hooked ( In my case MyFunction() ):
pawn Code:
MyFunction() <hooking:true>
{
    state hooking:false;

    // functions of your hooked Function

    return MyFunction();
}
Now we can create our normal Function.
pawn Code:
MyFunction() <hooking:false>
{
    state hooking:true;

    // functions of your original Function

    return 1;
}
Ready Hooked is a Function to the method hook state.


Return true (1), but also we could by false (0), not only to give warning by the lack of feedback, we can not return MyFunction (), the original callback to prevent create a flood in the hook and in the original function.

I like to use it there until it is more simple, but stay tidy.
Credits:
- Willian_Luigi - Hook Method
- DanDRT - Tutorial
- [IPS]Team and CODE.ME
Reply
#2

Nice hook method. It's a good method of use Statement. Congratz to creators.
Reply
#3

Thanks Dolby
Reply
#4

not bad
Reply
#5

Thanks 22
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)