I realized that having an extra plugin to do this was...redundant and redid this plugin:
https://forums.alliedmods.net/showthread.php?t=180761 as a simple include file.
This include's purpose is to make console commands quite a bit easier for plugin authors to add, saving quite a bit of duplicate code. Here is an example, comparing the same function using my include and using the playercommands version:
slap.sp:
PHP Code:
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "Player Commands",
author = "AlliedModders LLC",
description = "Misc. Player Commands",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegAdminCmd("sm_slap", Command_Slap, ADMFLAG_SLAY, "sm_slap <#userid|name> [damage]");
}
public Action:Command_Slap(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_slap <#userid|name> [damage]");
return Plugin_Handled;
}
decl String:arg[65];
GetCmdArg(1, arg, sizeof(arg));
new damage = 0;
if (args > 1)
{
decl String:arg2[20];
GetCmdArg(2, arg2, sizeof(arg2));
if (StringToIntEx(arg2, damage) == 0 || damage < 0)
{
ReplyToCommand(client, "[SM] %t", "Invalid Amount");
return Plugin_Handled;
}
}
decl String:target_name[MAX_TARGET_LENGTH];
decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (new i = 0; i < target_count; i++)
{
PerformSlap(client, target_list[i], damage);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Slapped target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Slapped target", "_s", target_name);
}
return Plugin_Handled;
}
My version:
PHP Code:
#include <sourcemod>
#include <easy_commands>
#include <sdktools_functions>
public Plugin:myinfo =
{
name = "Slap command!",
author = "necavi",
description = "Supplies a single command to slap any player.",
version = "1.0",
url = "http://necavi.org"
}
public OnPluginStart()
{
RegEasyAdminCmd("sm_slap2 <playerfilter> [damage]", Command_Slap, Admin_Cheats, { Cmd_Filter, Cmd_Cell }, 2, 1);
}
public Command_Slap(client, targets[], numTargets, damage)
{
if(damage < 0)
{
damage = 0;
}
for(new i = 1; i < numTargets; i++)
{
SlapPlayer(i, damage);
}
}
Obviously this is a bit oversimplified, as the slap command did have a few extra checks to verify various portions for integrity, which I have not added in such a basic, short example.
The commands are as follows:
PHP Code:
stock RegEasyConCmd(String:command[], Function:func, _:params[]={0}, totalParams = 0, reqParams = 0, filterFlags = 0, replyNoTargetFound = true)
stock RegEasyAdminCmd(String:command[], Function:func, AdminFlag:flag = Admin_Generic, _:params[] = {0}, totalParams = 0, reqParams = 0, filterFlags = 0, replyNoTargetFound = true)
Params:
PHP Code:
enum CmdParam
{
Cmd_All = 0,
Cmd_Cell,
Cmd_Float,
Cmd_String,
Cmd_Filter, //Note! This parameter requires two on the handler, targets[] and numTargets.
Cmd_Filter_Single
};
Currently it does not allow for a description, it simply gives the full command string in reply (including parameters).
Benefits:
Deals with filtering (@me,@all,@ct,etc)
Deals with replying to too few arguments
Allows for command handlers with single arguments, instead of the sometimes cryptic (client,args).