09.12.2013, 00:35
(
Last edited by DanDRT; 09/12/2013 at 11:09 AM.
)
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:
Now define when to start hooking be true:
Now let's create our Callback hooked (in my case I will hook the OnPlayerConnect):
Now we can create our normal callback.
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:
Now define when to start hooking be true:
Now let's create our Function hooked ( In my case MyFunction() ):
Now we can create our normal Function.
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: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;
pawn Code:
main()
{
state hooking:true;
}
pawn Code:
public OnPlayerConnect(playerid) <hooking:true>
{
state hooking:false;
// functions of your hooked Callback
return OnPlayerConnect(playerid);
}
pawn Code:
public OnPlayerConnect(playerid) <hooking:false>
{
state hooking:true;
// functions of your original CallBack
return 1;
}
Hooking Functions
We will need a variable at the top, in my case will be:
pawn Code:
stock hooking;
pawn Code:
main()
{
state hooking:true;
}
pawn Code:
MyFunction() <hooking:true>
{
state hooking:false;
// functions of your hooked Function
return MyFunction();
}
pawn Code:
MyFunction() <hooking:false>
{
state hooking:true;
// functions of your original Function
return 1;
}
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.
- Willian_Luigi - Hook Method
- DanDRT - Tutorial
- [IPS]Team and CODE.ME