SA-MP Forums Archive
ALS Hook question - 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: ALS Hook question (/showthread.php?tid=429451)



ALS Hook question - CJay9209 - 09.04.2013

just a quick question.

I'm running an intialisation routine during OnGameModeInit OR OnFilterScriptInit in my include.

If I hook both OnGameModeInit and OnFilterScriptInit am I gonna have problems with the initialisation routine running twice on a GM where the person uses a filterscript?

OR

do i need to add a check to see if OnFilterScriptInit has been called yet and prevent it from initialising during OnGameModeInit?


Re: ALS Hook question - Sanady - 19.04.2015

Same happend to me today. Anyone have answer?


Re: ALS Hook question - Ahmad45123 - 19.04.2015

I don't get you...
But if you mean that you have code for OnGameModeInit and a code for OnFilterScriptInit.
Then you can use this:
PHP код:
#if defined FILTERSCRIPT
public  OnFilterScriptInit()
{
}
#else
public OnGameModeInit()
{
}
#endif 
And of course you must have FILTERSCRIPT defined in you FILTERSCRIPT.

E: you can replace public with hook.


Re: ALS Hook question - MP2 - 19.04.2015

Only the relevant callback is called. If the script is a gamemode, OGMI is called, if it's a FS, OFSI is called. You don't have to worry about that.


Re: ALS Hook question - Lordzy - 19.04.2015

If you want to hook both callbacks and prevent collision between them, use a boolean to know whether one among them had been called or not. It doesn't usually get called together but there used to be a report that both of them sometimes get called when server loads up.

pawn Код:
new
    g_InitCalled = false;

public OnFilterScriptInit() {

    if(!g_InitCalled) {

        //codes
        g_InitCalled = true;
    }
    return 1;
}

public OnGameModeInit() {

    if(!g_InitCalled) {
   
        //Codes
        g_InitCalled = true;
    }
    return 1;
}



Re: ALS Hook question - Misiur - 19.04.2015

Partially related: YSI defines hookable OnScriptInit and OnScriptExit callbacks (y_scriptinit)