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

[Any] Grabbing all arguments


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
B3none
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 05-01-2017 , 03:46   [Any] Grabbing all arguments
Reply With Quote #1

PHP Code:
#include <sourcemod>

#pragma semicolon 1 // Singals that a semicolon is used at the end of a line.
#pragma newdecls required // Enforces newest syntax

/*
* I am using colour codes to define what colour I want the text
* \x01 = White (Default)
* \x02 = Red
* \x0C = Blue

* Colour codes:
* https://goo.gl/9CQzmu
*/
#define TAG_MESSAGE "[\x02ArgumentGrabbing\x01]"

char s_CommandArgs[MAXPLAYERS+1]/*ClientSize*/[32]/*Array Size*/[1024]/*Size to store data*/;
// char = Character

int i_PlayerCount 0// Sets the value to 0, may be inaccurate so might move to define OnMapStart / End
// int = Integer

public Plugin myinfo // Plugin information section
{
    
name        "Grabbing All Arguments",
    
author      "B3none",
    
description "A tutorial on grabbing all arguments.",
    
version     "0.0.1",
    
url         "www.sourcemod.net"
};

/* public voids (Plugin Fired Code)*/

/*
* Fired when the plugin starts (usually at the beginning of each map)
* Plugins are refreshed on map change.
*/
public void OnPluginStart()
{
    
RegConsoleCmd("sm_team"Command_Teaming"Command to select a team of friends!");
}

/*
* When the client is put into the server (we could hook playerspawn with the client involved)
* https://goo.gl/XLIcib <- Link to how to Hook Events.
*/
public void OnClientPutInServer()
{
    
i_PlayerCount++; // Playercount +1 on client join
}

/*
* Off of the top of my head the only public void that fires
* when a client leaves the server.
*/
public void OnClientDisconnect()
{
    
i_PlayerCount--; // Playercount -1 on client leave
}


/* public Actions (Command Fired Code) */
public Action Command_Teaming(int clientint args)
{
    
/* 
    * For loop to get all existing arguments.
    * A space makes the word a different argument
    * this is 4 arguments
    *  1   2  3    4
    *
    * Each time I want to grab the arguments I will
    * need to use the for loop.
    * 
    * As we are dealing with an array we will start
    * this for loop from value 0.
    */
    
for(int i 0<= GetCmdArgs(); i++)
    {
        
GetCmdArg(is_CommandArgs[client][i], sizeof(s_CommandArgs));
    }
    
    
    
/*
    * If there are 1 or more arguments,
    * use this section of code
    */
    
if(args >= 1)
    {
        
PrintToChat(client"%s The arguments are..."TAG_MESSAGE);
        for(
int i 0i<= GetCmdArgs(); i++)
        {
            
PrintToChat(client"%s %s"TAG_MESSAGEs_CommandArgs[client][i]);
        }
    }
    
    
/*
    * Otherwise default to this line of code
    */
    
else
    {
        
PrintToChat(client"%s Please enter arguments!"TAG_MESSAGE);
    }
    
    

Any questions then feel free to ask, if there is an issue with the code then I would also like to know ;P
__________________

Last edited by B3none; 05-01-2017 at 03:55. Reason: Alterations to buffer size.
B3none is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-01-2017 , 11:08   Re: [Any] Grabbing all arguments
Reply With Quote #2

OnClientPutInServer/OnClientDisconnect both require the client param (type: int).

PHP Code:
GetCmdArg(is_CommandArgs[client][i], sizeof(s_CommandArgs)); 
to:
PHP Code:
GetCmdArg(is_CommandArgs[client][i], sizeof(s_CommandArgs[][])); 
PHP Code:
if(args >= 1
simplify to:
PHP Code:
if(args 0
__________________

Last edited by WildCard65; 05-01-2017 at 11:09. Reason: <= is correct.
WildCard65 is offline
B3none
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 05-01-2017 , 14:23   Re: [Any] Grabbing all arguments
Reply With Quote #3

Thankyou
__________________
B3none is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 05-03-2017 , 22:37   Re: [Any] Grabbing all arguments
Reply With Quote #4

None of this snippet makes any sense. If you're making a command you should know which arguments are required and optional.
Mitchell is offline
Reply


Thread Tools
Display Modes

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 22:09.


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