Raised This Month: $ Target: $400
 0% 

[snippet]A function that greatly simplifies the use of a target filter on sourcemod


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fakuivan
Senior Member
Join Date: Nov 2015
Old 11-28-2016 , 20:00   Re: [snippet]A function that greatly simplifies the use of a target filter on sourcem
Reply With Quote #4

Take this as pseudocode:

PHP Code:
public Action Callback_Mute(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_Mute);
}

public 
Action Callback_UnMute(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_UnMute);
}

public 
Action Callback_Gag(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_Gag);
}

public 
Action Callback_UnGag(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_UnGag);
}

public 
Action Callback_Silence(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_Silence);
}

public 
Action Callback_UnSilence(int i_clientint i_args)
{
    return 
BaseCommandHandler(i_clienti_argsPersistMuteUI_Action_UnSilence);
}

Action BaseCommandHandler(int i_clientint i_argsPersistMuteUI_Action i_action)
{
    if (
i_args <= 0)
    {
        
ReplyToCommand(i_client"[SM] %t: <target>""persm_usage");
        return 
Plugin_Handled;
    }
    
    
char s_target[MAX_NAME_LENGTH];
    
GetCmdArg(1s_targetsizeof(s_target));
    
    
Simplified_ProcessTargets(i_clients_targetPerformAction"[SM] %t""persm_ml_you_action""persm_you_action"
        (
i_action == PersistMuteUI_Action_Mute        "persm_muted" 
        
i_action == PersistMuteUI_Action_UnMute        "persm_unmuted" 
        
i_action == PersistMuteUI_Action_Gag        "persm_gagged" 
        
i_action == PersistMuteUI_Action_UnGag        "persm_ungagged" 
        
i_action == PersistMuteUI_Action_Silence    "persm_silenced" 
        
"persm_unsilenced"), view_as<any>(i_action));
    return 
Plugin_Handled;
}

void PerformAction(int i_clientint i_targetany a_action)
{
    
bool b_no_effect;
    
bool b_cached;
    
    if (
a_action != PersistMuteUI_Action_Silence && a_action != PersistMuteUI_Action_UnSilence)
    {
        if (
a_action == PersistMuteUI_Action_Mute || a_action == PersistMuteUI_Action_UnMute)
        {
            
b_cached PerformSetMute(i_clienti_target, (a_action == PersistMuteUI_Action_Mute), b_no_effect);
        }
        else if (
a_action == PersistMuteUI_Action_Gag || a_action == PersistMuteUI_Action_UnGag)
        {
            
b_cached PerformSetGag(i_clienti_target, (a_action == PersistMuteUI_Action_Gag), b_no_effect);
        }
        if (!
b_cached)
        {
            
ReplyToCommand(i_client"[SM] %t""persm_cache_not_ready"i_target);
        }
        else if (
b_no_effect)
        {
            
ReplyToCommand(i_client"[SM] %t""persm_player_already", (a_action == PersistMuteUI_Action_Mute "persm_muted" 
                                                                        
a_action == PersistMuteUI_Action_Gag "persm_gagged" 
                                                                        
a_action == PersistMuteUI_Action_UnGag "persm_ungagged" 
                                                                        
"persm_unmuted"), 
                                                                        
i_target);
        }
    }
    else if (
a_action == PersistMuteUI_Action_Silence)
    {
        
PerformAction(i_clienti_targetPersistMuteUI_Action_Mute);
        
PerformAction(i_clienti_targetPersistMuteUI_Action_Gag);
    }
    else if (
a_action == PersistMuteUI_Action_UnSilence)
    {
        
PerformAction(i_clienti_targetPersistMuteUI_Action_UnMute);
        
PerformAction(i_clienti_targetPersistMuteUI_Action_UnGag);
    }

It helped me avoid some monkey typing and if you need to change something, you only do it on one function.
fakuivan is offline
 



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:55.


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