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

TypeSet and hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PastyBully
Junior Member
Join Date: Dec 2016
Old 01-26-2018 , 06:00   TypeSet and hook
Reply With Quote #1

Hello guys,
I would make my own HookEvent function and I have a enum and a typeset. I don't understand how we can hook the typeset function with my enum. If you don't understand what I speak this is an example :

https://github.com/alliedmodders/sou...khooks.inc#L79
with
https://github.com/alliedmodders/sou...hooks.inc#L208

and make a function like this

https://github.com/alliedmodders/sou...hooks.inc#L344


Sorry for my english.
Pasty
PastyBully is offline
pride95
Senior Member
Join Date: Aug 2015
Old 01-26-2018 , 08:10   Re: TypeSet and hook
Reply With Quote #2

you can't create your own hook function in sourcemod. you must create in c++ and compile as an extension.
pride95 is offline
PastyBully
Junior Member
Join Date: Dec 2016
Old 01-26-2018 , 10:06   Re: TypeSet and hook
Reply With Quote #3

Ok thank you for your answer.

Pasty
PastyBully is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 01-26-2018 , 10:06   Re: TypeSet and hook
Reply With Quote #4

(Note: The links in the original post don't point to the correct lines anymore. The correct links are here, here, and here.)

If you want to just pass other events that you can get or generate through SourceMod (such as letting other plugins listen for when players are AFK or when they send chat messages), you'll want to read up on forwards.

If you want something specifically like SDKHooks with enums, you just have to retrieve the enum value you passed in and register your function with the appropriate forward. As far as I know, there's no checks to ensure the callback you pass in matches the expected prototype.

Quote:
Originally Posted by pride95 View Post
you can't create your own hook function in sourcemod. you must create in c++ and compile as an extension.
DHooks (in applicable cases). You can hook functions there and call forwards to other listening plugins so they don't have to ship their own gamedata.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
PastyBully
Junior Member
Join Date: Dec 2016
Old 01-26-2018 , 10:09   Re: TypeSet and hook
Reply With Quote #5

So if we want to add a new event we need to make a forward global or private ?
PastyBully is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 01-26-2018 , 10:46   Re: TypeSet and hook
Reply With Quote #6

Quote:
Originally Posted by PastyBully View Post
So if we want to add a new event we need to make a forward global or private ?
If you want to expose a plugin's custom events to other plugins, yes; one of the two would work. Hook-style callbacks created with things like HookEvent() and SDKHook() use private forwards, while forwards such as OnMapStart() or OnClientPutInServer() are global.

If you don't know anything about writing shared plugins, you'll also want to read up on how to create natives.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 01-26-2018 at 10:48.
nosoop is offline
PastyBully
Junior Member
Join Date: Dec 2016
Old 01-26-2018 , 11:06   Re: TypeSet and hook
Reply With Quote #7

I see, howewer, how I can say this function is call when a recurrent action is call like call this function when client spawn ? I have this code

PHP Code:
public void OnPluginStart() {
    
fwdHandle CreateForward(ET_EventParam_Cell);
}

//--------------------------------------------------------------------------

typedef Native_HookEvent = function bool(Handle pluginint numParams);

public 
int Native_HookEvent(Handle pluginint numParams) {
    
int client GetNativeCell(1);
    
event id GetNativeCell(2);
    
fwdHandle GetHookType(id);
    
    Function 
func GetNativeFunction(3);

    if(
fwdHandle != null)
        
AddToForward(fwdHandlepluginfunc);
}

//--------------------------------------------------------------------------

typedef Native_GetForwardPointer = function Handle(Handle pluginint numParams);

public 
int Native_GetForwardPointer(Handle pluginint numParams) {
    return 
view_as<int>(fwdHandle);
}

public 
Handle GetHookType(rp_event e) {
    switch(
e) {
        case 
OnClientHint :
            return 
p_OnClientHint;
        case 
OnClientCommand :
            return 
p_OnClientCommand;
    }
    
    return 
null;


Last edited by PastyBully; 01-26-2018 at 11:07.
PastyBully 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 21:12.


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