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

How to hook on late load? [Solved]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EngHell
Member
Join Date: Jul 2013
Location: Guatemala
Old 01-25-2015 , 15:29   How to hook on late load? [Solved]
Reply With Quote #1

I have done this to hook the players picking items when theres a knife round, everything is working fine except it let players get droped items, but since i did a late load of the plugin, i think thats why it's not working, because i did the hook OnClientPutInServer() that is why the plugin is not working well, but since i ussually load and unload plugins every x time, i'll like to get a way to handle it, theres the code:
PHP Code:
public OnClientPutInServer(client) {
    
SDKHook(clientSDKHook_WeaponCanUseBlockPickup);
}

public 
OnClientDisconnect(client) {
    
SDKUnhook(clientSDKHook_WeaponCanUseBlockPickup);

and

PHP Code:
public Action:BlockPickup(clientweapon){
    if (
g_enabled && g_isKnifeRound) {
        
PrintHintText(client"%t","Knife round is enabled");
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;

How i can manage to hook it when i late load the plugin?

Last edited by EngHell; 01-26-2015 at 00:02.
EngHell is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 01-25-2015 , 15:41   Re: How to hook on late load?
Reply With Quote #2

You can use AskPluginLoad2
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-25-2015 , 16:24   Re: How to hook on late load?
Reply With Quote #3

PHP Code:
new bool:g_bLateLoaded false;

public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{
  
g_bLateLoaded late;
  return 
APLRes_Success;
}

public 
OnPluginStart()
{
  
//...

  
if (g_bLateLoaded)
  {
    for (new 
1<= MaxClientsi++)
    {
      if (
IsClientInGame(i)) //Add other checks, e.g. IsClientSourceTV, if needed
      
{
        
SDKHook(iSDKHook_WeaponCanUseBlockPickup);
      }
    }
  }

__________________
11530 is offline
EngHell
Member
Join Date: Jul 2013
Location: Guatemala
Old 01-25-2015 , 16:34   Re: How to hook on late load?
Reply With Quote #4

Quote:
Originally Posted by 11530 View Post
PHP Code:
new bool:g_bLateLoaded false;

public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{
  
g_bLateLoaded late;
  return 
APLRes_Success;
}

public 
OnPluginStart()
{
  
//...

  
if (g_bLateLoaded)
  {
    for (new 
1<= MaxClientsi++)
    {
      if (
IsClientInGame(i)) //Add other checks, e.g. IsClientSourceTV, if needed
      
{
        
SDKHook(iSDKHook_WeaponCanUseBlockPickup);
      }
    }
  }

Thanks, it did the job well, but if I unload the plugin, should I close the hooks? An if yes, what's the best way to do it?
EngHell is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-25-2015 , 17:09   Re: How to hook on late load?
Reply With Quote #5

You dont need to close sdhooks hooks, sdkhooks do it for you when entity is destroyed/player disconnected.
KissLick is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-25-2015 , 17:15   Re: How to hook on late load?
Reply With Quote #6

Any entities hooked with SDKHooks in a plugin will be automatically unhooked when the plugin unloads.
psychonic is offline
EngHell
Member
Join Date: Jul 2013
Location: Guatemala
Old 01-25-2015 , 20:32   Re: How to hook on late load?
Reply With Quote #7

Quote:
Originally Posted by KissLick View Post
You dont need to close sdhooks hooks, sdkhooks do it for you when entity is destroyed/player disconnected.
Quote:
Originally Posted by psychonic View Post
Any entities hooked with SDKHooks in a plugin will be automatically unhooked when the plugin unloads.
Then This code isn't needed?
PHP Code:
public OnClientDisconnect(client) {
    
SDKUnhook(clientSDKHook_WeaponCanUseBlockPickup);


Last edited by EngHell; 01-25-2015 at 20:34.
EngHell is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-25-2015 , 20:37   Re: How to hook on late load?
Reply With Quote #8

Quote:
Originally Posted by EngHell View Post
Then This code isn't needed?
PHP Code:
public OnClientDisconnect(client) {
    
SDKUnhook(clientSDKHook_WeaponCanUseBlockPickup);

That is correct.
psychonic is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-26-2015 , 02:17   Re: How to hook on late load? [Solved]
Reply With Quote #9

That's correct for a different reason. You don't need to unhook when a client disconnects from the server.

I'm not sure exactly why though. It's either because you can't hook something twice (which I doubt, you probably actually can and have double repeating code), or because client entities don't actually get "killed" or "removed" - at least that's my theory as I don't know - that when someone connects his control is exerted on an existing player entity that's being unused.


Or maybe SM does unhook clients on disconnect, who knows.
__________________

Last edited by Chdata; 01-26-2015 at 02:18.
Chdata is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 01-26-2015 , 02:43   Re: How to hook on late load? [Solved]
Reply With Quote #10

I have seen many plugins hook stuff on player spawn. Now I'm wondering how long these hooks stay active. And if hooktype + entindex + callback-address is unique so that it wouldn't be hooked or called multiple times.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 01-26-2015 at 02:43.
Dr. Greg House 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 15:22.


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