Doing different things in same callback.
#1

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.
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)