Raised This Month: $51 Target: $400
 12% 

[Dev] Improved Commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author
necavi
Veteran Member
Join Date: Sep 2010
Plugin ID:
2844
Plugin Version:
1.1
Plugin Category:
Technical/Development
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Provides an interface for easier to work with commands.
    Unapprover:
    Reason for Unapproving:
    Author requested
    Old 03-19-2012 , 20:40   [Dev] Improved Commands
    Reply With Quote #1

    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_SlapADMFLAG_SLAY"sm_slap <#userid|name> [damage]");
    }
    public 
    Action:Command_Slap(clientargs)
    {
        if (
    args 1)
        {
            
    ReplyToCommand(client"[SM] Usage: sm_slap <#userid|name> [damage]");
            return 
    Plugin_Handled;
        }

        
    decl String:arg[65];
        
    GetCmdArg(1argsizeof(arg));

        new 
    damage 0;
        if (
    args 1)
        {
            
    decl String:arg2[20];
            
    GetCmdArg(2arg2sizeof(arg2));
            if (
    StringToIntEx(arg2damage) == || damage 0)
            {
                
    ReplyToCommand(client"[SM] %t""Invalid Amount");
                return 
    Plugin_Handled;
            }
        }
        
        
    decl String:target_name[MAX_TARGET_LENGTH];
        
    decl target_list[MAXPLAYERS], target_countbool: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(clienttarget_count);
            return 
    Plugin_Handled;
        }
        
        for (new 
    0target_counti++)
        {
            
    PerformSlap(clienttarget_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(clienttargets[],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
    File Type: sp Get Plugin or Get Source (improved_commands.sp - 264 views - 4.0 KB)
    File Type: inc improved_commands.inc (660 Bytes, 277 views)
    File Type: smx improved_commands.smx (4.7 KB, 257 views)

    Last edited by necavi; 03-23-2012 at 19:59.
    necavi is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 03-20-2012 , 19:47   Re: [Dev] Improved Commands
    Reply With Quote #2

    Cool stuff. Do you know if GetCmdReplySource works properly within the callbacks?
    __________________
    Bread EOTL GunMettle Invasion Jungle Inferno 64-bit will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, etc.
    Post in plugin threads with questions.
    Steam is for playing games.
    You will be fed to javalia otherwise.
    Psyduck likes replays.
    FlaminSarge is offline
    necavi
    Veteran Member
    Join Date: Sep 2010
    Old 03-20-2012 , 19:50   Re: [Dev] Improved Commands
    Reply With Quote #3

    I don't believe that it will.
    necavi is offline
    psychonic

    BAFFLED
    Join Date: May 2008
    Old 03-21-2012 , 12:02   Re: [Dev] Improved Commands
    Reply With Quote #4

    Quote:
    Originally Posted by FlaminSarge View Post
    Cool stuff. Do you know if GetCmdReplySource works properly within the callbacks?
    Quote:
    Originally Posted by necavi View Post
    I don't believe that it will.
    It should still work.
    psychonic is offline
    necavi
    Veteran Member
    Join Date: Sep 2010
    Old 03-21-2012 , 16:53   Re: [Dev] Improved Commands
    Reply With Quote #5

    Hmm..interesting, I haven't had cause to use it recently, although if it doesn't, I can always replicate the command inside improved_commands fairly easily.
    necavi is offline
    Zephyrus
    Cool Pig B)
    Join Date: Jun 2010
    Location: Hungary
    Old 03-22-2012 , 16:29   Re: [Dev] Improved Commands
    Reply With Quote #6

    shouldnt that example be

    PHP Code:
    public Command_Slap(clienttargets[],numTargets,damage)
    {
        if(
    damage 0)
            
    damage 0;
        for(new 
    i=0;i<numTargets;i++)
        {
            
    SlapPlayer(targets[i],damage);
        }

    __________________
    Taking private C++/PHP/SourcePawn requests, PM me.
    Zephyrus is offline
    necavi
    Veteran Member
    Join Date: Sep 2010
    Old 03-22-2012 , 17:08   Re: [Dev] Improved Commands
    Reply With Quote #7

    One would assume so, but for some reason that I haven't figured out yet, it always ends up passing zero as the first cell in the array. I haven't had time to look into precisely why its happening yet.
    necavi is offline
    Marcus101RR
    Veteran Member
    Join Date: Aug 2009
    Location: Tampa, FL
    Old 03-22-2012 , 18:17   Re: [Dev] Improved Commands
    Reply With Quote #8

    Quote:
    Originally Posted by necavi View Post
    One would assume so, but for some reason that I haven't figured out yet, it always ends up passing zero as the first cell in the array. I haven't had time to look into precisely why its happening yet.
    You start with 1, not with 0. Zero is always the host name. Mostly the server name if it is a dedicated, else its the host name if its a listening.
    __________________
    Marcus101RR is offline
    Send a message via AIM to Marcus101RR Send a message via Skype™ to Marcus101RR
    necavi
    Veteran Member
    Join Date: Sep 2010
    Old 03-22-2012 , 18:26   Re: [Dev] Improved Commands
    Reply With Quote #9

    That makes absolutely no sense in this context. I would assume spam, but the 2009 joindate does make it less likely, so language difference?
    necavi is offline
    Powerlord
    AlliedModders Donor
    Join Date: Jun 2008
    Location: Seduce Me!
    Old 03-23-2012 , 16:13   Re: [Dev] Improved Commands
    Reply With Quote #10

    Quote:
    Originally Posted by necavi View Post
    One would assume so, but for some reason that I haven't figured out yet, it always ends up passing zero as the first cell in the array. I haven't had time to look into precisely why its happening yet.
    I assume it's because of this...

    Quote:
    Originally Posted by Natives - Argument Counts/Backwards Compatibility
    In native handlers, the params array has a 0th index which stores the number of parameters it contains.
    __________________
    Not currently working on SourceMod plugin development.
    Powerlord is offline
    Reply



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


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