Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get the hookchain id in its callback #107

Closed
ish12321 opened this issue Mar 27, 2018 · 9 comments · Fixed by #173
Closed

how to get the hookchain id in its callback #107

ish12321 opened this issue Mar 27, 2018 · 9 comments · Fixed by #173

Comments

@ish12321
Copy link

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
Copy link
Author

Bump

@In-line
Copy link
Contributor

In-line commented Mar 31, 2018

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

@ish12321
Copy link
Author

Sorry for the bump.

@WPMGPRoSToTeMa
Copy link
Contributor

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

@ish12321
Copy link
Author

Any progress?

@SergeyShorokhov
Copy link
Member

See plugins on ReAPI

@ish12321
Copy link
Author

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

@SergeyShorokhov
Copy link
Member

SergeyShorokhov commented Apr 18, 2018

#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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants