Raised This Month: $51 Target: $400
 12% 

Solved SDKHook question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 03-03-2019 , 12:39   SDKHook question
Reply With Quote #1

I'm sorry if this was mentioned somewhere.

Everything below is about players-entities only (PostThinkPost)

1. Will this be a problem if I hook the same function to the same entity twice in a row without unhooking?

2. Will this be a problem if I unhook something that was not even hooked?

3. Is there any way to check is there any active hook with certain callback?

4. Is disconnecting of a player (or entire plugin stopped working) the only condition when it unhooks everything itself?

5. What is better to do.

a) often hook/unhook
b) hook once but most time it is not needed

Thanks in advance
Sorry for bad English.

Last edited by impossible_cc; 03-05-2019 at 04:17.
impossible_cc is offline
adma
Senior Member
Join Date: Oct 2015
Old 03-03-2019 , 17:11   Re: SDKHook question
Reply With Quote #2

1. Hooking an entity twice with the same callback will make the callback fire twice
2. No, according to https://sm.alliedmods.net/new-api/sdkhooks/SDKUnhook, there are no error conditions for SDKUnhook
3. Not built into SDKHooks, but it is possible. One way would be to keep a global count for each hook-callback and increment it every time a player is hooked, and then decrement the count when the player leaves (unhooked). Then you can check if count > 0 e.g.
PHP Code:
int g_iCount 0;
public 
void OnClientPutInServer(int iClient) {
  
SDKHook(iClient/* blah */);
  
g_iCount++;
}

public 
void OnClientDisconnect(iClient) {
  
g_iCount--;

4. Player is unhooked when they disconnect and when the plugin is unloaded
5. Depends on what you want to achieve. Most of the time, you can hook and forget. If you want a one time action, you can hook them, then SDKUnhook in the callback
adma is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:00.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode