AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   ForwardEx - A more extensive forward management system (https://forums.alliedmods.net/showthread.php?t=201727)

minimoney1 11-25-2012 15:49

ForwardEx - A more extensive forward management system
 
2 Attachment(s)
Hello everyone.
For Simple Chat Processor (Redux), I needed a way to call each forward one by one (as the current forward manager's methods call either the first or the highest depending on your settings set in CreateForward).
So here it is!

Note: This is for private forwards

Sample Plugin:
PHP Code:

#include <sourcemod>
#include <forwardex>

new Forward:g_fMyForward INVALID_FORWARD;

public 
APLRes:AskPluginLoad2(Handle:pluginbool:lateString:err[], err_max)
{
    
CreateNative("AddToMyForward"Native_Add);
    
CreateNative("RemoveFromMyForward"Native_Remove);
    return 
APLRes_Success;
}

public 
Native_Add(Handle:pluginnumParams)
{
    if (
g_fMyForward != INVALID_FORWARD)
    {
        
FwdEx_AddToForward(g_fMyForwardplugin, Function:GetNativeCell(1));
    }
}

public 
Native_Remove(Handle:pluginnumParams)
{
    if (
g_fMyForward != INVALID_FORWARD)
    {
        
FwdEx_RemoveFromForward(g_fMyForwardplugin, Function:GetNativeCell(1));
    }
}

public 
OnPluginStart()
{
    
FwdEx_Init();
    
g_fMyForward FwdEx_CreateForward();
}

public 
OnMapStart()
{
    if (
g_fMyForward != INVALID_FORWARD)
    {
        new 
bool:finish false;
        new 
bool:isTrue true;
        new 
count FwdEx_GetFwdCount(g_fMyForward);
        for (new 
0counti++)
        {
            
finish false;
            
Call_StartPrivateForward(g_fMyForwardForwardId:i);
            
Call_PushCellRef(isTrue);
            
Call_Finish(finish);
            if (!
finish)
            {
                
isTrue true;
            }
        }
    }
}

public 
OnPluginEnd()
{
    
FwdEx_End();


Please let me know of any bugs/questions/suggestions.

Thank you

minimoney1 11-25-2012 22:54

Re: ForwardEx - A more extensive forward management system
 
*Reserved*

11-25: Fixed a small bug.

Powerlord 11-27-2012 10:21

Re: ForwardEx - A more extensive forward management system
 
Quote:

Originally Posted by minimoney1 (Post 1843662)
Hello everyone.
For Simple Chat Processor (Redux), I needed a way to call each forward one by one (as the current forward manager's methods call either the first or the highest depending on your settings set in CreateForward).

Are you talking about return values here?

The forward manager is supposed to call all private forwards registered. The value it returns depends on the execution type.

ET_Ignore doesn't return anything.
ET_Single returns the value from the last forward.
ET_Event runs all forwards until it hits a forward that returns something other than Plugin_Continue (or runs all of them). It then returns that value.
ET_Hook runs all forwards until it hits a forward that returns Plugin_Stop (or runs all of them). It then returns the highest value that was returned.

By highest value, I mean out of these values:
Code:

    Plugin_Continue = 0,    /**< Continue with the original action */
    Plugin_Changed = 1,        /**< Inputs or outputs have been overridden with new values */
    Plugin_Handled = 3,        /**< Handle the action at the end (don't call it) */
    Plugin_Stop = 4,        /**< Immediately stop the hook chain and handle the original */


minimoney1 11-27-2012 20:03

Re: ForwardEx - A more extensive forward management system
 
Quote:

Originally Posted by Powerlord (Post 1844638)
Are you talking about return values here?

The forward manager is supposed to call all private forwards registered. The value it returns depends on the execution type.

ET_Ignore doesn't return anything.
ET_Single returns the value from the last forward.
ET_Event runs all forwards until it hits a forward that returns something other than Plugin_Continue (or runs all of them). It then returns that value.
ET_Hook runs all forwards until it hits a forward that returns Plugin_Stop (or runs all of them). It then returns the highest value that was returned.

By highest value, I mean out of these values:
Code:

    Plugin_Continue = 0,    /**< Continue with the original action */
    Plugin_Changed = 1,        /**< Inputs or outputs have been overridden with new values */
    Plugin_Handled = 3,        /**< Handle the action at the end (don't call it) */
    Plugin_Stop = 4,        /**< Immediately stop the hook chain and handle the original */


Yes, I needed to get the return value of every single forward to change things based on its return value, hence why I made this library.


All times are GMT -4. The time now is 18:37.

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