Hooking callbacks between a gamemode and an include
#1

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

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

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+).
Reply
#4

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?
Reply
#5

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Simply call a seperate callback, example:
pawn Код:
// ...
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.
Reply
#6

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)