[size=18pt]How to hook callbacks[/size]
Using the ALS method into hooking callbacks if you're making a include with a callback.
- [li][size=14pt]What is this?[/size][/li]
Well, making a include may seem simple though having callbacks in the include to actually be compiled within the gamemode you're creating may seem frustrating. You'd get errors like, 'Symbol is already define, 'Callback(params)'. This tutorial will help you prevent this cause.
- [li][size=14pt]The ALS hooking method[/size][/li]
Code :
/* codename: myinclude.inc */
#include <vaultmp>
public OnPlayerDeath(clientID)
{
timestamp();
new name[32]; new str[64];
GetPlayerName(clientID, name);
strformat(str, sizeof(str), false, "OnPlayerDeath: %s died\n", name);
print(str, 1, -1, 1);
return 1;
}
gamemode:
Code :
#include <vaultmp>
#include <myinclude>
public OnPlayerDeath(clientID)
{
return 1;
}
Now compiling for this would return a error:
Code :
error 021: symbol already defined: "OnPlayerJoin"
Preventing this all we do is:
Code :
/* codename: myinclude.inc */
#include <vaultmp>
//Calling the callback again.
public OnPlayerJoin(clientID)
{
timestamp();
new name[32]; new str[64];
GetPlayerName(clientID, name);
strformat(str, sizeof(str), false, "OnPlayerDeath: %s died\n", name);
print(str, 1, -1, 1);
//Return your callback
return myhook_OnPlayerJoin(clientID);
}
//if the ALS hook method is already defined:
#if defined _ALS_OnPlayerJoin
// Undefine the callback
#undef OnPlayerJoin
#else
//redefine the callback.
#define _ALS_OnPlayerJoin
#endif
//defining OnPlayerJoin with your 'onplayerjoin' that was returned.
#define OnPlayerJoin myhook_OnPlayerJoin
//forwarding it so we don't get any warnings referring to the code.
forward myhook_OnPlayerJoin(playerid);
Yeah, that's how its done. Compile and there should be no problem. Most things shall work correctly.
Tutorials still in development. Sorry for mistakes.