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

How to make a private forward that accepts multiple functags?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ici
Member
Join Date: Jan 2014
Old 03-29-2016 , 12:17   How to make a private forward that accepts multiple functags?
Reply With Quote #1

What I'm trying to do is register a private forward that accepts different functags.

For instance look at SDKHooks:

PHP Code:
funcenum SDKHookCB
{
    ...
    
// OnTakeDamagePost
    
public(victimattackerinflictorFloat:damagedamagetype),
    public(
victimattackerinflictorFloat:damagedamagetypeweapon, const Float:damageForce[3], const Float:damagePosition[3]),
    ...

This page tells me that forwards are type-checked and that forward's parameter types must be known in advance, and if you push a mismatching type, the call will not complete.

In this scenario:
PHP Code:
public Native_HookForward(Handle:pluginnumParams)
{
    
AddToForward(g_Forwardplugin, Function:GetNativeCell(1)); // Here, check against a valid functag

How can I check the function's tag that I've passed to make sure I push the correct number of parameters in the forward call?

Suppose this is not possible, if I push more parameters than the function I've registered accepts, would it still work? Would it just ignore the extra params?

Example:
PHP Code:
enum MyHookType
{
    
MyHook_OnTick
}

funcenum MyHookCB
{
    
// OnTick
    
public(client),
    public(
clienttick)
}

// new Handle:g_hFwdOnTick[MAXPLAYERS+1];
// g_hFwdOnTick[client] = CreateForward(ET_Ignore, Param_Cell, Param_Cell);

public Native_MyHook(Handle:pluginnumParams)
{
    new 
client GetNativeCell(1);
    
// client checks here, throw native errors
    
    
new MyHookType:type MyHookType:GetNativeCell(2);
    
    switch (
type)
    {
        case 
MyHook_OnTick:
        {
            
AddToForward(g_hFwdOnTick[client], plugin, Function:GetNativeCell(3));
        }
    }
}

// native MyHook(client, MyHookType:type, MyHookCB:callback); 

Last edited by ici; 03-29-2016 at 12:21.
ici is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-29-2016 , 13:24   Re: How to make a private forward that accepts multiple functags?
Reply With Quote #2

Forwards can't check SP function params when functions are being added.

Creating the forward requires params to be known so it can validate params YOU PUSH are correct type.

Last edited by WildCard65; 03-29-2016 at 13:26.
WildCard65 is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 03-31-2016 , 07:03   Re: How to make a private forward that accepts multiple functags?
Reply With Quote #3

Additional parameters in a forward passed to a callback with less parameters are just inacessable and ignored in the callback.
__________________
Peace-Maker 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 18:20.


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