rehlds / ReAPI

AMXModX module providing APIs for ReHLDS, ReGameDLL, and Metamod plugins (e.g., ReUnion, ReVoice).
GNU General Public License v3.0
159 stars 105 forks source link

how to get the hookchain id in its callback #107

Closed ish12321 closed 4 years ago

ish12321 commented 6 years ago

Hey, I want to register a hookchain on plugin_init and after its first callback, I want to disable that hookchain. Now, since I'm using it for single time don't it good to register a variable for that. Is it possible that with some function I can get hookchain id in its callback ?

ish12321 commented 6 years ago

Bump

In-line commented 6 years ago

Nobody will help you, because you didn't even read documentation. "Bump" will not work.

ish12321 commented 6 years ago

Sorry for the bump.

WPMGPRoSToTeMa commented 6 years ago

It will be good if we'll have stateful hooks in which you can pass userdata.

ish12321 commented 6 years ago

Any progress?

SergeyShorokhov commented 6 years ago

See plugins on ReAPI

ish12321 commented 6 years ago

I see no plugins in which we can get hookchain id in the callback.

SergeyShorokhov commented 6 years ago
#include <amxmodx>
#include <reapi>

new HookChain: g_hSpawn;

public plugin_init()
{
// You should get hook handler from native and remember his
    g_hSpawn = RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn", .post = true));
// Simple cmd for test
    register_clcmd("say /check", "toggler");
}

public toggler()
{
    static bool: bToggle;

    if(g_bToggle)
// It will disable hook
        DisableHookChain(g_hSpawn);
    else
// Well, you understand
        EnableHookChain(g_hSpawn);

    bToggle = !bToggle;
}

public CBasePlayer_Spawn()
{
// Was called when hook be ENABLED.
    server_print("CALLED: -> CBasePlayer_Spawn()");
}
ish12321 commented 6 years ago

That way I know. Actually, I wished to call a hookchain only once and disable it. So, I wished if the hookchain id was in callback so there was no need of an extra variable.