advanced-scripting/Environment Variables

Environment Variables

Environment Variables are a poorly named way to retrieve data from the minecraft server. These variables can range all over the place, from the location of the player, to the name of the world, to whether it is storming, to other variables from other (participating) plugins! You can even do functions with a call to the environment variable (hence why it's a bad name)!

To get the value of a variable, use the following syntax anywhere where variables and back references can be used:

$(namespace.variable)
  • namespace - This is the top-level name of what you are calling. Things like "server", "world", and "plugin" are namespaces.
  • variable - This can be a lot of things, and "variable" is, again, a bad name for it. It can be a dot separated sub-variable like "position.x" or a function call like "random 2". You'll see below.

Built-In Variables

What follows is a list of supported namespaces and their supplied variables. If you attempt to get a variable that is not supplied, Commander will print the error out on the console and return null to your script.

The Server Namespace

This namespace covers properties about the minecraft server itself.

  • server.players - Returns a collection of the names of all currently online players.
    • server.players.online - does the same.
    • server.players.offline - Returns a collection of the names of every player that has ever played on this server.
    • server.players.banned - Returns a collection of the names of all banned players, excluding those that are IP banned.
    • server.players.whitelisted - Returns a collection of the names of all whitelisted players.
    • server.players.ops - Returns a collection of the names of all Operators on the server.
  • server.name - Returns the name of this server.
  • server.version - Returns the version of this server
  • server.gamemode - Returns the default game mode of this server
  • server.motd - Returns the message of the day.
  • server.ip - Returns the IP address of the server.
  • server.port - Returns the port address of the server.

The World Namespace

This namespace covers properties from the current world. (Note: currently there is no way to pull from a world other than the one the player is in.)

  • world.time - Returns the time of day in minecraft ticks.
  • world.name - Returns the name of this world.
  • world.difficulty - Returns the difficulty level of this world (ie, easy, medium, hard)
  • world.players - Returns a collection of names of players currently online and inhabiting this world.
  • world.worldtype - Returns the type of this world (ie, normal, flat)
  • world.sealevel - Returns the height of sea level in this world, in block units
  • world.maxheight - Returns the maximum height of this world
  • world.seed - Returns the world seed.
  • world.ispvp - Returns true or false as to whether PVP is enabled in this world.
  • world.spawn.x - Returns the X block coordinate of the spawn point
  • world.spawn.y - Returns the Y block coordinate of the spawn point
  • world.spawn.z - Returns the Z block coordinate of the spawn point
  • world.weather.storm - Returns true or false as to whether there is currently a storm on this world.
  • world.weather.thundering - Returns true or false as to whether it is currently thundering on this world.
  • world.weather.ticksleft - Returns the number of ticks remaining in the current weather pattern.
  • world.weather.thunderleft - Returns number of ticks remaining in the current thunder pattern.

The Player and Me Namespaces

The player namespace contains properties for a particular player. The "me" namespace is the same, but only pertaining to the current player. To access a property in the player namespace, replace "me" in any of the below with "player.<PlayerName>".

  • me.name - Returns the player's name
  • me.displayname - Returns the player's display name.
  • me.murderer - Returns the name of the thing that killed the player. (experimental)
  • me.level - Returns the player's experience level (the number in the middle of the experience meter in survival mode)
  • me.health - Returns the player's health level
    • me.health.max - Returns the player's maximum health
  • me.air - Returns the player's air level
    • me.air.max - Returns the player's maximum air
  • me.food - Returns the player's food level
  • me.potions - Returns a collection of the names of the currently active potion effects
  • me.ismoving - Returns true or false as to whether the player is currently moving (experimental)

The following properties have Y, and Z properties as well:

  • me.location.x - Returns the X block coordinate where the player is currently situated (aliases: position, at)
  • me.crossheir.x - Returns the X block coordinate where the player is currently looking at (aliases: reticle, lookat)
  • me.compass.x - Returns the X block coordinate where the player's compass points to

The Command Namespace

The command namespace is used to get the status of the most recently executed command:

  • command.return - Gets the return value of the last command (unsupported at this time, here for future reference)
  • command.found - Returns true or false as to whether the last command was successfully found and executed.
  • command.error - Returns true of false as to whether the last command threw an error during execution. Note, in order to use this, the ?continueonerror directive must be set to on.

The Function Namespace

The function namespace provides a few functions that can be used. Generally the functions path is followed by a space and then the arguments it may need.

  • function.random (1) (2) - Returns a random number between 0 and 100, exclusive. Both parameters are optional and must be numbers if passed. If one parameter is provided, then the random function will return from 0 to the passed number. If two parameters are provided, it will return a random number between the first parameter and the second.
  • function.substr (1) (2) (3) - Returns the substring of a passed string. All three parameters are required: first parameter is the start index (zero-based), second is the stop index (zero-based, exclusive), and third is the string to cut. For example: $(function.substr 2 8 Hello World) returns "llo Wo".

The Plugin Namespace


Comments

Posts Quoted:
Reply
Clear All Quotes