|
|
|
Contents |
Command blocks are one of the core features of TNT Wars which allow things to happen through interaction with the block. These actions can be as simple as opening and closing a door, to the mechanics behind a capture the flag map. Command blocks have come a long way from their original form. A huge number of functions, commands and variables have been added, and many changes have been made to make them usable for gameplay. Previously, they were activatable across worlds, and quitting a command block exited the events of the command block for every player rather than the player who activated it.
Powering the mechanics of TNT, command blocks have lead to the creation of some of the most complex gametypes ever, such as Control Points and King of the Hill, but are also simplistic enough to be used to pull players into the game after they enter a portal.
This article should give you the absolute basics of command blocks. Beyond that, it is up to you and your own logical evaluation to produce from basic to advanced to insanely complex stuff.
Variants
There are several variants of command blocks, differing in the ways that they are activated. There are principally two types: Sensor commands and Clickable commands. Sensor commands require your head to move through the block, whilst Clickable commands need you to modify the specific block that is a command block.
CMD
A CMD block is a Clickable block to interact with. In a CMD block, you can only execute commands that are allowed for your rank. It is not possible to permanently change this block.
GCMD
A Guest CMD block is a Clickable block to interact with. In a GCMD block, you can execute any command, with some limitations to prevent abuse (i.e, setpoints won't work). It is not possible to permanently change this block.
SCMD
A Sensor CMD block should be a non-solid block (i.e. water, still lava, air), and is activated by a player's head passing through it. Similarly to CMD blocks, you can only execute commands that are allowed for your rank. It is not possible to permanently change this block.
GSCMD
A Guest Sensor CMD block should be a non-solid block (i.e. water, still lava, air), and is activated by a player's head passing through it. Similarly to Guest CMD blocks, you can execute any command, with some limitations. It is not possible to permanently change this block.
MGSCMD
An MGSCMD block should be a non-solid block (i.e. water, still lava, air). Similarly to Guest CMD blocks, you can execute any command, with some limitations. However, you are also able to place and destroy blocks here, such as placing or destroying dirt here. Weapon explosions also affect them as normal.
Command Block Functions
A command block is allowed to call several functions that are not normal commands. These include pausing a command block's events, cancelling them, and evaluating a variable.
Wait
- /cmdtype wait #
- Waits # seconds. # can be any number, including decimal values
Exit
- /cmdtype exit
- Immediately terminates execution of the command. While unnecessary at the end of the command block's scripts, it is often used for controlling who can run the block or stopping execution if an exception arises.
Get
A get function allows the user's input to be retrieved. Currently, they may enter a freetext message, a block name, a number, or a yes / no value. The variable which the value is assigned to cannot be accessed from another command block, and is known as $variable The syntax is as follows for each individual command.
GetInput
- getinput variable Message
- Requests freetext input, providing the prompt "[INPUT] Message"
GetNum
- getnum variable Message
- Requests numeric input, providing the prompt "[INPUT] Message"
- It's important to note that the value entered by the player must be an integer. Decimal values are not allowed
GetBlock
- getblock variable Message
- Requests a block ID, providing the prompt "[BLOCK INPUT] Message"
- This can be converted to a block name using $bname($variable)
GetYN
- getyn variable Message
- Requests either Y or N, providing the prompt "[Y / N] Message"
- This value is case-insensitive and is stored in variable as lowercase
Other functions
A less well-known change made in the anniversary update was the ability to specify coordinates in common commands such as blb, teamspawn and replace. Any command available in the command list may be used.
Variables
Variables are one of the most important features of a command block. They obtain data from the person who is using it, (such as their team, their name, etc) but also extend to global information (such as the time left in the round, the date, etc.) They even extend to checking for randomizing and evaluating values. A variable may be used in a command in any fashion, be it a team or persons name, the remaining round time or the server time. In fact, the server entry message is simply a command block holding a world variable it initialises when someone first activates it through $exist
Text-based and numeric variables should be compared in two different ways. A text-based variablevae, (such as $name or $time) must be surrounded with quotation marks when being compared; a numeric variable doesn't need these.
| Variable | Type | Contents |
|---|---|---|
| $name | Text-based | The person's name |
| $time | Text-based | The current server time, in the format "HH:MM:SS" |
| $rt | Numeric | The remaining time of the current round, starting at 599 and ending at 0 |
| $date | Text-based | The current server date, in the format "DD/MM/YYYY" |
| $rnd(min,max) | Numeric | A random number between min and max |
| $block(x,y,z) | Numeric | The block ID of the block at point [x, y, z] |
| $bname(id) | Text-based | The name of the block with ID id |
| $ranknum | Numeric | The ID of the user's rank, between 0 (player) and 9 (admin) |
| $rank | Text-based | The name of the user's rank |
| $eval(expr) | Varies | Evaluates expr and returns the results. expr is commonly a mathematical expression, such as 1+1 |
| $kby | Text-Based | Returns the name of the person who killed the one executing the command. Returns 0 if not a player. |
| $px, $py, $pz | Numeric | Returns the player's x, y, and z coordinates, respectively. |
| $bx, $by, $bz | Numeric | Returns the x, y, and z coordinates of the command block running, respectively. |
| $pnum | Numeric | The number of players currently online. |
| $kills, $deaths | Numeric | The number of kills or deaths the user has for the current round. |
| $team | Text-Based | The team the user is on. |
| $points | Numeric | The number of points the user has. |
| $warn | Numeric | The warning level of the player. |
| $pistol, $laser, $shotgun, etc. | Numeric | The number of items of the given type in the user's inventory. |
| $red, $blue | Numeric | The number of players on the given team. |
| $exist(variable) | Numeric | Checks whether variable or "$variable" (those in the above list) exists, and returns 1 if it does. Otherwise, returns 0 |
| $wrp / $wbp | Numeric | Returns the number of blocks the payload cart has moved. |
Special $evals
The $eval variable can be very easily manipulated to do some maths which involve python functions.
- $eval(random.choice(["OPTION 1", "OPTION 2"]))
- Will randomly choose between OPTION 1 and OPTION 2 in a single script, basically a one-line version of worldvar ¶ $rnd(1,5) and writing an if for each $w¶==#: action.
- It is easy to add more options.
- Options can be consisted of coordinates. For example, OPTION 1 could be 3 5 10 128, and we could use goto $eval(random.choice(["3 5 10 128", "5 3 10 128"])) to goto between either.
World Variables
The most powerful tool at TNT Wars' disposal are world variables. These operate in the same manner as normal variables, but their values persist between command blocks in the same world. World variables always start with the prefix $w, to avoid confusion with block-level variables.
A variable is defined through the command: worldvar variable value. variable can be numbers, letters and symbols (although the latter is advised against.) value can be anything from a number to a variable as discussed in the sections above. Assigning someone's name to the variable $wx is therefore worldvar x $name. This is the fundamental principle of CTF on TNT Wars. The names of the people carrying the flags are assigned to the variables $wr and $wb (for carrying the red and blue flags respectively).
IF Block
IF blocks are a check between two (or more through "and") expressions. For instance, a check to see if the person's team is red and they are called Bob would be written as: if "$team"=="red" and "$name"=="Bob": ... An IF block is declared by: if v1comparatorv2: action. Breaking this down, you may specify v1 to be any expression, such as a world variable or your own value. You may also specify v2 to be anything. The comparator may be one of several programming operations, which are as follows:
| Comparator | Operation |
|---|---|
| == | Equal to |
| != | Not equal to |
| < | Less than |
| > | Greater than |
| => | Less than or equal to |
| <= | Greater than or equal to |
Following the IF check, you must place a semicolon (:) and then describe the action. For instance, you may want the command to exit, in which case you'd write if $rnd(1,2)==1: exit.
When comparing numbers, you don't need to add quotation marks. If you are comparing any form of text in the variable, quotation marks must be included.
CI
CI is a command generated to allow more than twenty commands to be entered into a single block on the TNT Wars server, without asking for KingSam to update the map's metadata. In a CI command, the entire command is called in one line through the following syntax: OFFSET = /COMMANDTYPE command&n /COMMANDTYPE command. The offset is obtainable by typing /info and modifying the block you want to become a command block, and substituting that into the CI script. Commands in CI are separated by a single line. Once your CI is ready to be pushed into the server, you need to upload it to PasteBin.com using PLAIN TEXT. Ensuring that there are no lines after the uploaded text, you simply type /CI PasteBinID.txt on the world you want the commands to be imported on. If you don't like the commands you made, you can delete them individually, or you can type /cmddelall to completely clear the world of any command blocks (this should never be used in Default!) When you're using CI, colours do not function as they do in the server; while the server works with colours in the format %colour, CI will use &colour. Make sure all %'s are &'s, so %c becomes &c for red to work properly.
This is an example of a PasteHTML script - Can you figure out what this script does? Because yes, blb x y z x2 y2 z2 can also refer to world variables. Note that this would make a command at the 0,0,0 block and have to be clicked to activate. - Note from Razinao: Pastehtml sucks, so we're now on pastebin. The link is outdated and needs fixing
EI
One of the most problematic issues with command blocks, although for the greater good, is that only one can be run at a time. If you're currently running a command block, you cannot run into a random spawning portal (or fall into one, for most of the maps). This led to the introduction of events, which can be imported similarly to CI, except that commands end with ; instead of &n. Beyond this difference, events function almost identically to command blocks; in particular, exit can be used to terminate the execution of an event.
Events can be one of the following: every #, at # and on leave.
Every
- every # command
- The command specified will be run every # seconds while a map is active in TNTWars.
At
- at # command
- The command specified will be run when # seconds are remaining. Maps which do not use the number of kills per team to determine a win use 'at 2' to prevent rounds ending twice and problems with skin appearances.
OnLeave
- on leave command
- The command specified will be run when a player leaves the world or server. In this context, the text-based variable $leaver can be used to determine who has just left.
OnRoundEnd
- on roundend command
- The command specified will be run when the round is meant to end. However, the presence of the roundend event means that the round is also incapable of ending automatically and thus /gcmd endround has to be incorporated into the event to ensure that the round will be ended properly with kills taken into account.
Conclusions
Those are the essentials. Now comes the understanding of how they can be interconnected and used to create entirely new gamemodes, such as CTF, KOTH and Payload. Op+ can read up on how these gamemodes work in the staff chatter, as they are a mixture of everything that has been covered in this tutorial. LaserDrill and Volcanic can also be picked up if you ask KingSam and are an OP+, although they are now very event orientated.
Command Examples
In all cases of these examples, the world variable used will be ¶ for visibility.
Random Specific Spawns
- /gscmd worldvar ¶ $rnd(1,5)
- /gscmd if $w¶==1: goto 1 1 1
- /gscmd if $w¶==2: goto 2 1 1
- /gscmd if $w¶==3: goto 3 1 1
- /gscmd if $w¶==4: goto 4 1 1
- /gscmd if $w¶==5: goto 5 1 1
Entirely Random Spawns
On a 64x64x64 map, change 63 values depending on map scale
- /gscmd goto $rnd(0,63) 63 $rnd(0,63)
Openable / Closable Door
- /gcmd if $exist(¶)==0: worldvar ¶ 0
- /gcmd if $w¶==0: blb adminium air 0 0 0 1 1 1
- /gcmd if $w¶==1: replace air adminium 0 0 0 1 1 1
- /gcmd if $w¶==1: worldvar ¶ 2
- /gcmd if $w¶==0: worldvar ¶ 1
- /gcmd if $w¶==2: worldvar ¶ 0
Or in a more compact form
- /gcmd if $exist(¶)==0: worldvar ¶ 0
- /gcmd if $w¶==0: blb adminium air 0 0 0 1 1 1
- /gcmd if $w¶==1: replace air adminium 0 0 0 1 1 1
- /gcmd worldvar ¶ $eval($w¶+1)
- /gcmd if $w¶>1: worldvar ¶ 0
Random Events
- /gcmd if $rnd(1,4)!=1: exit
- /gcmd kill $name being unlucky
Disable Cannons
- /gcmd if $exist(¶)==0: worldvar ¶ 0
- /gcmd if $w¶==1: exit
- /gcmd if $w¶==0: worldvar ¶ 1
- /gcmd znew dcannon1 0 0 0 0 1 0
- /gcmd znew dcannon2 1 0 0 1 1 0
- /gcmd znew dcannon3 2 0 0 2 1 0
- /gcmd znew dcannon4 3 0 0 3 1 0
- /gcmd say %4Cannons Disabled for 10 seconds!
- /gcmd wait 10
- /gcmd zremove cannon1
- /gcmd zremove cannon2
- /gcmd zremove cannon3
- /gcmd zremove cannon4
- /gcmd wait 20
- /gcmd worldvar ¶ 0
Trapdoor Ground
- /gscmd blb air 0 0 0 10 0 10
- /gscmd wait 0.5
- /gscmd blb adminium 0 0 0 10 0 10