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;
}
PHP Code:
#include <sourcemod>
#include <improved_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.com"
}
public OnPluginStart()
{
Dev_RegAdminCmd("sm_slap <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);
}
}
The commands are as follows:
PHP Code:
native Dev_RegAdminCmd(String:command[],Function:func,AdminFlag:flag,_:params[],totalParams,reqParams);
native Dev_RegConCmd(String:command[],Function:func,_:params[],totalParams,reqParams);
PHP Code:
enum CmdParam
{
Cmd_All = 0,
Cmd_Cell,
Cmd_Float,
Cmd_String, //Untested! (Not incredibly useful)
Cmd_Filter //Note! This parameter requires two on the handler, targets[] and numTargets.
};
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).
Future Plans:
Adding Dev_RegServerCmd - Not added yet due to requiring an additional handler, unlike concmd/admincmd
Adding Dev_RegSayCmd - Not added yet, not entirely sure how I want to handle it, ideas are most certainly welcome
Adding further CmdParams, such as Cmd_Name, which will either attempt to pass a name, or take a name and pass an ID
Attached Files


Wyświetl pełny artykuł