AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Any] Grabbing all arguments (https://forums.alliedmods.net/showthread.php?t=296887)

B3none 05-01-2017 03:46

[Any] Grabbing all arguments
 
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

WildCard65 05-01-2017 11:08

Re: [Any] Grabbing all arguments
 
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


B3none 05-01-2017 14:23

Re: [Any] Grabbing all arguments
 
Thankyou :3

Mitchell 05-03-2017 22:37

Re: [Any] Grabbing all arguments
 
None of this snippet makes any sense. If you're making a command you should know which arguments are required and optional.


All times are GMT -4. The time now is 07:14.

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