Functions

Functions are a mechanic used in Command Blocks. Given an input (ex. $player), it returns an output (gold of the player). Functions can be used in commands or in ifelse conditions.

## List of Functions (as of update v0.4.18.alpha)

### $add

* Arguments: value1, value2
* Usage: Adds two numbers (1+1=2)
* Examples: /gold gain bob $add(3,15) (Give bob [3+15] gold)

### $divide

* Arguments: value1, value 2
* Usage: Divides two numbers (2/2=1)
* Examples: /health lose bob $divide(10,10) (Take away [10÷10] health from bob)

### $formatTime

* Arguments: seconds (as a number)
* Usage: Format integers to a time format (60 = 1:00)
* Examples: /sidebar set 1 $formatTime(3600) (Set sidebar row 1 to 1:00:00)

### $getArmorEquip

* Arguments: playerName (name of player)
* Usage: Gives the name of equipped armor/clothing
* Examples: /chat bob $getArmorEquip(joe) (Send "[armor of joe]" to bob)

### $getCol

* Arguments: $player
* Usage: Gives the column position of player (the second number in a set of coordinates).
* Examples: /tp bob 15 $getCol(joe) (Teleport bob to coordinates: 15, column of joe)

### $getEquip

* Arguments: $player
* Usage: Gives the name of the equipment the player is holding.
* Examples: /give bob $getEquip(bob) 1 (Give 1 of [item in bob's hand] to bob)

### $getEquipCount

* Arguments: playerName (name of player)
* Usage: Gives the amount of an equipped item that the player has.
* Examples: /chat bob Bob has $getEquipCount(bob) of $getEquip(bob) (Send "Bob has [count of items in bob's hand] of [item in bob's hand]" to bob)

### $getEquipId

* Arguments: $player
* Usage: Gives the id of the equipment the player is holding.
* Examples: /chat bob $getEquipId(joe) (Send "[id of item in joe's hand] to bob 1")

### $getGold

* Arguments: $player
* Usage: Gives the amount of gold the player currently has.
* Examples: /chat bob Bob has $getGold(bob) gold! (Send "Bob has [bob's gold] gold!")

### $getHealth

* Arguments: $player
* Usage: Gives the amount of health a player currently has.
* Examples: /chat joe Bob has $getHealth(bob) health! (Send "Bob has [bob's health] health!")

### $getHunger

* Arguments: $player
* Usage: Gives the amount of hunger a player currently has.
* Examples: /health lose bob $getHunger(bob) (Take away [bob's hunger] from bob)

### $getInventoryItemCount

* Arguments: playerName, itemName
* Usage: Gives the total count of a type of item in a player's inventory.
* Examples: /chat bob Bob has $getInventoryItemCount(bob,Potato) potato(es)! (Send "Bob has [number of potatoes from bob] potato(es)!")

### $getMaxHealth

* Arguments: $player
* Usage: Gives the maximum amount of health a player can have.
* Examples: /health lose bob $getMaxHealth(bob) (Take away [bob's health limit] health from bob)

### $getMaxHunger

* Arguments: $player
* Usage: Gives the maximum amount of hunger a player can have.
* Examples: /chat bob I can eat until my meter reaches $getMaxHunger(bob)! (Send "I can eat until my meter reaches [bob's hunger limit]!" to bob)

### $getMaxOxygen

* Arguments: $player
* Usage: Gives the maximum amount of oxygen a player can have.
* Examples: /chat bob Joe can breathe up to $getMaxOxygen(joe)! (Send "Joe can breath up to [joe's oxygen limit]!" to bob)

### $getMaxStamina

* Arguments: $player
* Usage: Gives the maximum amount of stamina a player can have.
* Examples: /chat bob You have $getStamina(bob) out of $getMaxStamina(bob) (Send "You have [bob's stamina] out of [bob's stamina limit]" to bob)

### $getOxygen

* Arguments: $player
* Usage: Gives the amount of oxygen a player has.
* Examples: /chat bob My suit has $getOxygen(bob) oxygen!! (Send "My suit has [bob's oxygen] oxygen!!" to bob)

### $getOwner

* Arguments: buildingId
* Usage: Gives the id of the owner (of a placed building, not the server)
* Examples: /health gain $getOwner(1134) 100 (Give 100 health to [get owner of building: 1134])

### $getPlayerCount

* Arguments: None
* Usage: Gives the number of players in a game.
* Examples: /chat @a $getPlayerCount() (Send "[players in colony]" to all)

### $getRegion

* Arguments: playerName, entityId
* Usage: Gives the name of the region a player or entity is in.
* Examples: /chat bob Bob is in region '$getRegion(bob)!' Wow! (Send "Bob is in region '[get region of bob]!' Wow!" to bob)

### $getRegionPlayerCount

* Arguments: regionName
* Usage: Gives the number of players in a region.
* Examples: /chat bob There are $getRegionPlayerCount($getRegion(bob)) player(s) here! (Send "There are [region player count of region bob]" to bob)

### $getRole

* Arguments: $player
* Usage: Gives the name of the role a player has.
* Examples: /chat joe Joe works as a $getRole(joe). Should've read the fine print. (Send "Joe works as a [joe's role]. Should've read the fine print." to joe)

### $getRoleMemberCount

* Arguments: roleName
* Usage: Gives the number of players with a role.
* Examples: /chat bob There are $getRoleMemberCount($getRole(joe)) working alongside Joe. (Send "There are [get count of players with role: joe's role] working alongside Joe." to joe)

### $getRow

* Arguments: $player
* Usage: Gives the row position of player (the first number in a set of coordinates).
* Examples: /tp bob 31 $add(20,$getRow(joe)) (Teleport bob to coordinates: 31, [20+[row of joe]])

### $getScore

* Arguments: $player
* Usage: Gives the score of a player.
* Examples: /chat mario My score is $getScore(mario). Wahoo! (Send "My score is [mario's score]. Wahoo!" to mario)

### $getSpeed

* Arguments: $player
* Usage: Gives the speed of a player.
* Examples: /caption bob title My speed is $getSpeed(bob)! (Announce with [title] "My speed is [bob's speed]!" to bob)

### $getStamina

* Arguments: $player
* Usage: Gives the amount of stamina a player currently has.
* Examples: /chat bob I have $getStamina(bob) stamina. (Send "I have [bob's stamina] stamina." to bob)

### $getTeam

* Arguments: playerName
* Usage: Gives the team name of a player.
* Examples: /chat bob Joe's current team is the '$getTeam(joe)', but $getTeam(bob) is better! (Send "Joe's current team is the '[joe's team]', but [bob's team] is better!" to bob)

### $getTeamMemberCount

* Arguments: teamName
* Usage: Gives the number of members in a team.
* Examples: /chat bob $getTeamMemberCount($getTeam(bob)) (Send "[get member count of team [bob's team] ]" to bob)

### $isLoggedIn

* Arguments: $player
* Usage: Gives an output if the player is logged in (true if logged in, false if not).
* Examples: /chat @a $isLoggedIn(bob) (Send message "[bob is a guest account? true/false] to all")

### $multiply

* Arguments: value1, value2
* Usage: Multiplies two numbers (1x1=1)
* Examples: /chat bob 100 x 100 equals $multiply(100,100) (Send message "100 x 100 equals [100\*100] to bob")

### $random

* Arguments: min, max
* Usage: Gives a random number between a minimum and a maximum.
* Examples: /chat joe $random(1,10) (Send message "[random number 1 - 10]" to joe)

### $round

* Arguments: value (the number that needs to be rounded)
* Usage: Rounds a number.
* Examples: /gold gain bob $round(4.9999) (Give bob [round 4.99999] gold)

### $subtract

* Arguments: value1, value2
* Usage: Subtracts two numbers (2-1=1)
* Examples: /chat bob $subtract(2,1) = 1 (Send "[2-1] = 1" to bob)