PHP Code:
public Action Callback_Mute(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_Mute);
}
public Action Callback_UnMute(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_UnMute);
}
public Action Callback_Gag(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_Gag);
}
public Action Callback_UnGag(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_UnGag);
}
public Action Callback_Silence(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_Silence);
}
public Action Callback_UnSilence(int i_client, int i_args)
{
return BaseCommandHandler(i_client, i_args, PersistMuteUI_Action_UnSilence);
}
Action BaseCommandHandler(int i_client, int i_args, PersistMuteUI_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(1, s_target, sizeof(s_target));
Simplified_ProcessTargets(i_client, s_target, PerformAction, "[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_client, int i_target, any 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_client, i_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_client, i_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_client, i_target, PersistMuteUI_Action_Mute);
PerformAction(i_client, i_target, PersistMuteUI_Action_Gag);
}
else if (a_action == PersistMuteUI_Action_UnSilence)
{
PerformAction(i_client, i_target, PersistMuteUI_Action_UnMute);
PerformAction(i_client, i_target, PersistMuteUI_Action_UnGag);
}
}
It helped me avoid some monkey typing and if you need to change something, you only do it on one function.