-
Notifications
You must be signed in to change notification settings - Fork 11
Expressions
Expression is a special line of code (or rather mathematical expression) that allows to check for specific conditions. Expressions support full power of McLib's math parser, which supports basic arithmetic operations (+
, -
, *
, /
), math functions (abs()
, sin()
, cos()
, sqrt()
, etc.) and many other things. For more information check out this page.
Parsed expressions are present in events and dialogues. These wrapped in ${...}
allow you to substitute an expression inside of a text field, with the result of that expression. For example: if you attach to global Player: chat message
trigger (in server settings) to an event, its variable message
will be available within expressions (and also in scripts via IScriptEvent.getValue(String)
):
Where parsed expressions are supported, which should be in:
- Command's node command text field
- Trigger's node custom data text field
- Reaction's/reply's content text field
- Quest chain's subject text field
Any of the functions described below can be used. Beside that, values that came from trigger node's Custom data
and global trigger's Available particles
should be accessible via variable name, like ${message}
from the chat trigger in the screenshot above.
Beside variables mentioned above, there will be also following variables available in the context:
-
subject
, first entity's UUID (which can be used with for entity<target>
selector arguments) -
subject_name
, first entity's display name -
object
, second entity's UUID -
object_name
, second entity's display name -
player
, first player's (could be eithersubject
orobject
) UUID -
player_name
, first player's (could be eithersubject_name
orobject_name
) display_name -
npc
, first Mappet NPC's (could be eithersubject
orobject
) UUID -
npc_name
, first Mappet NPC's (could be eithersubject_name
orobject_name
) display_name
If there are no entity was passed in the context, obviously all of the variables will be empty strings. Obviously, if neither subject or object is a player entity nor an NPC, player*
and npc*
variables will be empty strings. See also this section on events page.
Beside that, expressions support special features that allow to connect it with other Mappet's features. Here is a full list of them:
Name and arguments | Return value |
---|---|
quest_present(id, target) |
Returns boolean whether one of the players by target selector has a quest by id in progress |
quest_completed(id, target) |
Returns boolean whether one of the player by target selector has completed a quest by id . Alternatively ~ can be used, for target , to check whether quest was completed globally. |
quest_present_or_completed(id) |
Returns boolean whether a quest by id was completed or one of the current players has it, this useful if you want to check whether the quest by id wasn't taken before. |
Name and arguments | Return value |
---|---|
faction_friendly(id, target) |
Returns boolean whether faction score of the faction by id of player by target selector makes it friendly. |
faction_neutral(id, target) |
Returns boolean whether faction score of the faction by id of player by target selector makes it neutral. |
faction_hostile(id, target) |
Returns boolean whether faction score of the faction by id of player by target selector makes it hostile. |
faction_has(id, target) |
Returns boolean whether player by target selector has faction score by id . |
faction_score(id, target) |
Returns faction score of faction by id of a single player by target selector. |
Name and arguments | Return value |
---|---|
state(id[, target]) |
Returns value of state by id . If target is omitted, then it would use global state, or current subject's states. If target is specified, then it will try to find by a target selector a player with that state, or ~ for global state. |
Name and arguments | Return value |
---|---|
inv_has(item_id[, target, all]) |
Returns boolean whether player(s) by target selector has an item by item_id in the inventory (not in held or equipped slots). all is a boolean that signifies whether (value 1 ) all players should be checked, or only one (value 0 ) player should have at least. |
inv_holds(item_id[, target, all]) |
Returns boolean whether player(s) by target selector holds an item by item_id in main or off hands. |
inv_armor(item_id[, target, all]) |
Returns boolean whether player(s) by target selector equipped an item by item_id in any of the armor slots. |
Name and arguments | Return value |
---|---|
player_xp(target) |
Returns target player's current total XP. |
player_xp_level(target) " |
Returns target player's current XP level. |
player_hp(target) |
Returns target player's current HP. |
player_hunger(target) |
Returns target player's hunger. |
player_armor(target) |
Returns target player's armor. |
player_is_alive(target) |
Returns whether target player(s). |
Name and arguments | Return value |
---|---|
dialogue_read(id, target) |
Returns whether given target has read dialogue by id . |
Note: [dimension_id]
argument is an optional argument in case you're using these expressions where world wasn't provided (like on server start global trigger). 0
is overworld, -1
is nether and 1
is the end.
Name and arguments | Return value |
---|---|
world_time([dimension_id]) |
Returns world time (i.e. the one that actually is day/night), whether 1000 is day and 13000 is night . |
world_total_time([dimension_id]) |
Returns total world time since the beginning of world's initialization. |
world_is_night([dimension_id]) |
Returns boolean whether it's night time (12000 - 24000). |
world_is_day([dimension_id]) |
Returns boolean whether it's day time (0 - 12000). |
Note: boolean is either 1
(true) or 0
(false).
If parts of the wiki don't make sense with Mappet's latest version, or you weren't able to recreate examples (i.e. outdated information), feel free to report the page and section that is out of date on community's Discord server (make sure to mention which Mappet’s version did you use).