SA-MP Forums Archive
Hooking custom callbacks using y_hooks - 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: Hooking custom callbacks using y_hooks (/showthread.php?tid=602107)



Hooking custom callbacks using y_hooks - [XST]O_x - 02.03.2016

Is it possible to hook my own callbacks (not default SA:MP ones) using y_hooks?
Because right now the hooked callback doesn't get called at all, but the original one does.

What I mean is:
pawn Код:
//On gamemode
forward OnMyCustomCallbackGetsCalled();

public OnGameModeInit()
{
    OnMyCustomCallbackGetsCalled(); //Call the callback
    return 1;
}

public OnMyCustomCallbackGetsCalled()
{
    //Gets called
    return 1;
}

//On include
hook OnMyCustomCallbackGetsCalled()
{
    //Doesn't get called
    return 1;
}



Re: Hooking custom callbacks using y_hooks - [XST]O_x - 02.03.2016

Bump


Re: Hooking custom callbacks using y_hooks - [XST]O_x - 03.03.2016

Bump.
I also figured hooking some native callbacks doesn't work, such as OnTrailerUpdate, and OnGameModeExit


Re: Hooking custom callbacks using y_hooks - SecretBoss - 03.03.2016

OnGameModeInit also doesn't work

y_hooks provide some callbacks if the callback is not listed I think it can't hook it


Re: Hooking custom callbacks using y_hooks - Misiur - 03.03.2016

It's easy. Don't use OnMyCustomCallbackGetsCalled();, do
pawn Код:
CallLocalFunction("OnMyCustomCallbackGetsCalled", "");



Re: Hooking custom callbacks using y_hooks - [XST]O_x - 03.03.2016

Quote:
Originally Posted by Misiur
Посмотреть сообщение
It's easy. Don't use OnMyCustomCallbackGetsCalled();, do
pawn Код:
CallLocalFunction("OnMyCustomCallbackGetsCalled", "");
Aha. Beautiful. It's working now, thanks
But what about OnGameModeExit?


Re: Hooking custom callbacks using y_hooks - Misiur - 03.03.2016

I'm not aware of it not working, are you using YSI 3 or 4?


Re: Hooking custom callbacks using y_hooks - [XST]O_x - 03.03.2016

Quote:
Originally Posted by Misiur
Посмотреть сообщение
I'm not aware of it not working, are you using YSI 3 or 4?
I've used YSI 3.1, and now 4.0. It didn't make any difference.


Re: Hooking custom callbacks using y_hooks - Misiur - 03.03.2016

Have you checked if it is executing on GMX? Normal ctrl+c doesn't execute OGME at all.


Re: Hooking custom callbacks using y_hooks - [XST]O_x - 04.03.2016

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Have you checked if it is executing on GMX? Normal ctrl+c doesn't execute OGME at all.
Every time I'm updating something in my gamemode I'm using gmx. That's the only way I'm resetting the server, and I know it doesn't get called because nothing gets saved to the database. I'll try moving the calling of the save function to the main OnGameModeExit and see if it works.