Doing different things in same callback. - 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: Doing different things in same callback. (
/showthread.php?tid=601357)
Doing different things in same callback. -
vassilis - 20.02.2016
I am trying to convert my script to
Modular Programming. However, i noticed that there are some callbacks that i used multiple things in it. For example, OnPlayerDeath. I have a medical fees system and a hit/bounty system used. I want to seperate it to includes so i can read the code in a better view. How can i use the same callback for different functionality in 2 seperate includes/files. I think that i can do that through hooking although this tutorial didnt really help me.
Hook Method 7
Anyone could explain me a bit ? Would be appreciated.
Re: Doing different things in same callback. -
IstuntmanI - 20.02.2016
Just hook the callback like in a normal include. In every .pwn file the OnPlayerDeath (for example) callback should look like this, if you actually use the callback, but if you don't use it in that module you don't need to use it at all:
pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
/*
CODES THERE
*/
#if defined Module_OnPlayerDeath
return Module_OnPlayerDeath( playerid, killerid, reason );
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerDeath
#undef OnPlayerDeath
#else
#define _ALS_OnPlayerDeath
#endif
#define OnPlayerDeath Module_OnPlayerDeath
#if defined Module_OnPlayerDeath
forward Module_OnPlayerDeath( playerid, killerid, reason );
#endif
You should change the "Module_" prefix in every module you use, so it won't conflict.