Var: Create a variable and assign it a value.
var [name] [name]...[name]
var [name] = [value] op [value]...op [value]
There are two forms of the var command. One declares one or more variable names, the other assigns a value to a single variable, based on an expression.
[name] - The name of the variable. Variable names cannot have spaces or contain any of the following characters: :~`!@#$%^&*()-=+|\\/?<>,.
Variable names cannot be one of the following: var, true, false, on, off, player, clan, history, syshistory, clanhistory, health, maxhealth, reach.
Variable names are not case sensitive.
[value] op [value]...op [value] - An expression made up of one or more values and operators. Operators do not need to be surrounded by square brackets.
[value] may be a numeric literal, another variable or a built in value type as listed below.
[op] Operators:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
Built in [value] types:
Note: All built in value type names must be succeeded by a : colon before the closing square bracket, even if they don't have parameters.
Note: If the built in value type requires more than one parameter, then all of it's parameters must be enclosed in square brackets.
[Abs:x] - The absolute value of x.
[Sin:x] - The sine of x.
[Cos:x] - The cosine of x.
[Tan:x] - The tangent of x.
[Single:x] - x converted to single precision.
[Clock:] - The current clock.
[Health:] - The players current health.
[MaxHealth:] - The players current max health.
[Reach:] - The players current reach.
[Pos:x|y|z] - The players current X, Y or Z position.
[Vel:x|y|z] - The players current X, Y or Z velocity.
[View:x|y|z] - The players current X, Y or Z view direction.
[Rel:x|y|z] - The scripts relative block X, Y or Z.
[PRel:x|y|z] - The players block position X, Y or Z.
[CRel:x|y|z] - The players cursor X, Y or Z.
[Script:x|y|z] - The scripts X, Y or Z offset.
[Skill:x] - The players current skill level.
[Skillxp:x] - The players current skill xp.
[Rand:x] - A random number between 0 - x inclusive.
[History:key] - The value of the player history [key].
[SysHistory:key] - The value of the system history [key].
[ClanHistory:key] - The value of the clan history [key].
[Inv:[Item][x,y,z]] - Inventory. If x,y,z is omitted, player inventory is used.
[Distance:[x,y,z][x,y,z]] - Get the distance between the two points.
[GamerCount:all|local|remote] - Get the number of gamers in the world.
[GamerCount:[all|local|remote][x,y,z][x,y,z]] - Get the number of gamers in a cubic area.
[GamerCount:[all|local|remote][x,y,z][radius]] - Get the number of gamers in a spherical area.
[MobCount:MobType] - Get the number of mobs in the world.
[MobCount:[MobType][x,y,z][x,y,z]] - Get the number of mobs in a cubic area.
[MobCount:[MobType][x,y,z][radius]] - Get the number of mobs in a spherical area.
Differences between variables and history:
* Variables can be used anywhere a numeric literal can be used. History cannot.
* Variables can be calculated using math expressions and built in values: History cannot.
* Variables only exist during the execution of the script: History is persistent.
* Variables are local to the script instance: History is global to all scripts/instances.
* Variables support fractional numbers: History supports whole (integer) numbers only.
Examples:
var [velx] [vely] [velz] [length] [distance] [dir]
Declares 6 variable names. If these variables have not been passed from a calling script, they are assigned a value of zero.
All variables used in a script must be at least declared and optionally assigned to before they are used.
Variables can be declared anywhere in the script, as long as it is before they are used.
var [toxicity] = [10.5]
Assigns the value of 10.5 to the variable [toxicity].
var [poison] = [5] * [toxicity] + [20]
Assigns it the value of 5 * toxicity + 20 = 5 * 10.5 + 20 = 72.5 to the variable [poison].
var [str] = [history:str]
Assigns the value from the players 'str' history to the variable [str].
var [str] = [syshistory:str]
Assigns the value from the system 'str' history to the variable [str].
var [str] = [clanhistory:str]
Assigns the value from the 'str' clan history to the variable [str].
var [r] = [rand:3]
Assigns a random value between 0 and 3 inclusive to the variable [r], i.e. either 0, 1, 2 or 3.
var [h] = [health:]
Assigns the players current health value to the variable [h].
var [h] = [maxhealth:]
Assigns the players current max health value to the variable [h].
var [x] = [pos:x]
Assigns the players current X position to the variable [x].
var [level] = [skill:Cooking]
Assigns the players current cooking skill level to the variable [level].
var [xp] = [skillxp:Mining]
Assigns the players current mining skill xp to the variable [xp].
var [count] = [inv:grass]
Assigns the number of grass blocks in the players inventory to the variable [count].
var [count] = [inv:[goldpieces][x,y,z]]
Assigns the number of gold pieces in the chests inventory at location x,y,z to the variable [count].
var [d] = [distance:[x1,y1,z1][x2,y2,z2]]
Assigns the distance between positions [x1,y1,z1] and [x2,y2,z2] to the variable [d].
var [count] = [gamercount:remote]
Assigns the number of remote gamers in the session to the variable [count].
var [count] = [mobcount:[none][prel:0,0,0][20]]
Assigns the number of mobs within a 20 block radius of the player to the variable [count].
var [count] = [mobcount:[spider][100,110,120][200,210,220]]
Assigns the number of spiders within the [100,110,120][200,210,220] region to the variable [count].
var [HealthAsPerc] = [health:] / [maxhealth:] * [100]
Assigns the players current health as a percentage of max health to the variable [HealthAsPerc].