Troubles with y_hooks -
[XST]O_x - 27.02.2016
I'm trying to hook OnGameModeInit from 2 different includes:
main.pwn:
pawn Код:
#include <a_samp>
public OnGameModeInit()
{
OnGameModeEx();
#if defined main_OnGameModeInit
return main_OnGameModeInit();
#else
return 1;
#endif
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit main_OnGameModeInit
#if defined main_OnGameModeInit
forward main_OnGameModeInit();
#endif
#include <YSI\YSI\y_hooks>
dest_management.pwn
pawn Код:
#include <YSI\YSI\y_hooks>
hook OnGameModeInit()
{
print("dest_management.pwn OnGameModeInit called.");
return 1;
}
work.pwn
pawn Код:
#include <YSI\YSI\y_hooks>
hook OnGameModeInit()
{
print("work.pwn OnGameModeInit called.");
return 1;
}
I'm following this tutorial:
https://sampforum.blast.hk/showthread.php?tid=597338
The problem is, main.pwn OnGameModeInit is called, and then dest_management.pwn OnGameModeInit is called, and that's it. work.pwn is completely ignored and not included. I can write random bullshit on the .pwn file but I don't get any errors after compiling, and work.pwn OnGameModeInit is not called.
Re: Hooking callbacks between a gamemode and an include -
[XST]O_x - 27.02.2016
Bump. I'm sorry for bumping so soon, it's just that I've edited the thread saying it was solved, but then the problem came back.
Re: Hooking callbacks between a gamemode and an include -
Abagail - 27.02.2016
If you are simply interacting between a gamemode and an include(and the include is just for your gamemode specifically/not for release), there's really zero need for hooking.
Simply call a seperate callback, example:
pawn Код:
// MAIN GAMEMODE //
public OnGameModeInit()
{
Init_Dest();
Init_Work();
GameModeEx();
return 1;
}
// dest_management.pwn //
Init_Dest()
{
// do something here
return 1;
}
// work.pwn //
Init_Work()
{
// do something here
return 1;
}
Also, if you are using y_hooks, you can just use the hook function(this also works for custom callbacks as of YSI 4.0+).
Re: Hooking callbacks between a gamemode and an include -
[XST]O_x - 27.02.2016
Quote:
Originally Posted by Abagail
If you are simply interacting between a gamemode and an include(and the include is just for your gamemode specifically/not for release), there's really zero need for hooking.
Simply call a seperate callback, example:
pawn Код:
// MAIN GAMEMODE // public OnGameModeInit() { Init_Dest(); Init_Work();
GameModeEx(); return 1; }
// dest_management.pwn // Init_Dest() { // do something here return 1; }
// work.pwn // Init_Work() { // do something here return 1; }
Also, if you are using y_hooks, you can just use the hook function(this also works for custom callbacks as of YSI 4.0+).
|
Well, now it won't recognize work_OnGameModeInit. It returns an error.
If I switch the order, it won't recognize destmanagement_OnGameModeInit.
Like it only calls the first one and then something gets fucked up.
But anyhow, what's wrong with the code I posted? Shouldn't it be working?
Re: Hooking callbacks between a gamemode and an include -
Vince - 27.02.2016
Quote:
Originally Posted by Abagail
Simply call a seperate callback, example:
|
The idea behind hooking is precisely to
not having to do that.
Personally I've never used Y_hooks. But it shouldn't be necessary to write the hooking stuff in the main gamemode file. That only applies to the includes themselves. You may also try running the compiler with -l (lowercase L) option which only runs the preprocessor. This will give you insight in what code is actually being fed to the compiler.
Re: Hooking callbacks between a gamemode and an include -
[XST]O_x - 28.02.2016
Quote:
Originally Posted by Vince
The idea behind hooking is precisely to not having to do that.
Personally I've never used Y_hooks. But it shouldn't be necessary to write the hooking stuff in the main gamemode file. That only applies to the includes themselves. You may also try running the compiler with -l (lowercase L) option which only runs the preprocessor. This will give you insight in what code is actually being fed to the compiler.
|
It drives me nuts. It should work. I hooked it in the GM because I blindly followed the tutorial and I have no idea what hooking is.
Re: Hooking callbacks between a gamemode and an include -
[XST]O_x - 28.02.2016
OK. I solved it.
The problem, apparently, wasn't even related to hooking, or y_hooks.
It was because I used #include ".../gamemodes/path" instead of "path", which was correct, but for some reason fucked something up in the compiler.
I changed this:
pawn Код:
#include "../gamemodes/utils/msg.pwn" //Working
#include "../gamemodes/utils/utils.pwn" //Working
#include "../gamemodes/utils/distance_gun.pwn" //Working
#include "../gamemodes/core/server/dest_management.pwn" //Working
#include "../gamemodes/core/server/work.pwn" //NOT working
To this:
pawn Код:
#include "utils/msg.pwn" //Working
#include "utils/utils.pwn" //Working
#include "utils/distance_gun.pwn" //Working
#include "core/server/dest_management.pwn" //Working
#include "core/server/work.pwn" //Working! WTF?
Unbelievable.