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 client, int 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; i <= GetCmdArgs(); i++)
{
GetCmdArg(i, s_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 = 0; i<= GetCmdArgs(); i++)
{
PrintToChat(client, "%s %s", TAG_MESSAGE, s_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
__________________