Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

[forums.alliedmods.net] [Dev] Improved Commands


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
Brak odpowiedzi do tego tematu

#1 Adminek AMXX.PL

    Admin :)

  • Bot

Reputacja: 156
Profesjonalista

  • Postów:7 488
  • Lokalizacja:AMXX.PL
Offline

Napisano 20.03.2012 01:40

This plugin's purpose is to make console, admin (and later say/server commands) quite a bit easier for plugin authors to add, and saves quite a bit of duplicate code. Here is an example, comparing the same function using my plugin 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 <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);
}
}

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:

native Dev_RegAdminCmd(String:command[],Function:func,AdminFlag:flag,_:params[],totalParams,reqParams);
native Dev_RegConCmd(String:command[],Function:func,_:params[],totalParams,reqParams);

Params:


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.
};

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).

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 Dołączona grafika improved_commands.inc (630 Bytes) Dołączona grafika Get Plugin or Get Source (improved_commands.sp - 4.0 KB)

Wyświetl pełny artykuł




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych