Skip to content
McHorse edited this page Jul 29, 2021 · 10 revisions

Events are basically programmable node systems that allows you to program logic for your adventure maps without writing any scripts or code. The way it works is you have multiple types of nodes at your disposal that you can create logic with them. Connecting these nodes together can produce a meaningful program that can do something with the world, player, NPCs and etc.

Events can be triggered either from triggers or via /mp event trigger command.

Events can be managed in Mappet dashboard. The third panel in the left sidebar opens event editor.

Editing

Once you pick or create an event, you'd see an editor like this:

Node editor

Event system supports following types of nodes:

  • Command node allows to execute commands, and depending on the result of command execution direct the flow
  • Condition node allows to check an expression, and depending on the evaluated result of the expression direct the flow
  • Switch node allows to direct the execution flow depending on the output of the given expression
  • Timer node allows to delay the execution
  • Cancel node allows to cancel trigger's execution
  • Trigger node allows to trigger a trigger, which allows you to trigger commands, sounds, events, dialogues, scripts and etc.

Command node

Command node executes a command from the perspective of the subject that triggered it. The subject could be a player, if the event was triggered through /mp event trigger, trigger block, or a region block, or an NPC if it was triggered from one of the NPC triggers.

Beside that, commands within command node can use special formatting to evaluate an expression within ${...}. For example, if you want to use /setblock command to put a block, however, you want it to place a fire block during the night, but stone block during the day. To do that, you can simply input following command:

/setblock -1514 4 1981 minecraft:${world_is_day() ? "stone" : "fire"}

And it will replace the ${world_is_day() ? "stone" : "fire"} depending on what time of the day it is. I.e. fire during the night, and stone during the day. Also, if you ever need to reference the subject player/NPC in commands, you can use ${subject} expression (which is UUID of the subject entity) which works with all commands that provide target selector arguments.

When command gets executed, if there was no error, then it will pass the execution to all of its input (child) nodes. However, if the command errored, then it will won't continue the execution. Binary toggle allows to change this behavior. Instead of all on success, or none on failure, binary instead works like this: on success it will pass the execution to the first node (denoted by 0 and green flow), while on error it will pass the execution to the second node (denoted by 1 and red flow). All other connected nodes will be ignored (as depicted by node 2 with yellow semitransparent flow).

Binary mode in action

Condition node

Condition node evaluates its expression, and depending on the resulted value it will pass the execution. If the resulted value is a non-zero (anything but 0) then it will execute all of its connected input (child) nodes. If the expression evaluates to 0, then no nodes will be executed. Same as with command node, Binary toggle allows to change the behavior from all-or-none execution to first-or-second node.

Using binary, you can create if-elseif-else like this:

if-elseif-else execution

Switch node

Switch node is similar to condition node, but instead of passing execution using either to all-or-none or binary model, it instead evaluates its expression and passes the execution to the child node at index of the resulted value. For example, let's say you want to randomly pass the execution to one of 3 command nodes. This can be achieved by inputting floor(random(0, 3)) into the switch node, and you get something like this:

Random execution

Timer node

Timer node allows to delay the execution of the node system by given amount of ticks. If you want to execute some commands gradually, you can use this node to delay commands.

Cancel node

Cancel node allows to cancel trigger's default behavior (like canceling sending message to the players' chat on chat trigger).

Trigger node

Trigger node triggers a user configured trigger. The cool thing about it is that you can do multiple things with triggers like playing sounds; trigger events, dialogues, and scripts; give and take items, and change states without using commands.

Trigger's cancel toggle

Cancel toggle changes the behavior the way trigger node treats canceled value from its trigger blocks. For example, event, dialogue, script, and item trigger blocks can cancel the trigger (event and dialogue trigger blocks can cancel by using Cancel node, script trigger block can call IScriptEvent.cancel(), and item trigger block can cancel when there is no item in player's inventory).

This canceling behavior trigger node can use in two ways:

  • When Cancel toggle is enabled: then the event or dialogue will also send cancel signal
  • When Cancel toggle is disabled: then the cancel signal from triggers will be used as signal that will affect the further execution, i.e. if the trigger was canceled, then the execution will halt down the line (unless binary toggle is enabled, then it will use output node at index 1 to pass the execution instead of output node 0)

Custom data

In custom data field, you can input an NBT compound tag like {a:"string",b:10}. That data will be passed to the event, dialogue or script, which can be accessed in expressions, Condition and Switch nodes in events and dialogues trigger blocks. For scripts trigger blocks, IScriptEvent.getValue(key) or IScriptEvent.getValues() can be used to read that custom data.

You can also use parsed expression within this field. For example, if you want to pass random value as a variable, you can input:

{var:${floor(random(0, 10))}}

And in trigger's events, dialogues and scripts trigger blocks, var variable will be available.

Hierarchy

There are no restriction to the hierarchy, or how the nodes should be arranged in a specific order, however, for the event node to start, you need to specify the main node as described on the Nodes page.

Event context

When events (or dialogues) get triggered from somewhere some data gets passed into the event. There are some variables that get into the context which are:

  • subject is the initiator of the event, for example, it's player on whom upon event was triggered via /mp event trigger.
  • subject_name is subject's name, for players it would be their username.
  • object is an additional entity that was triggered with an event, for example in case with On NPC interact trigger the NPC which got right clicked is subject and object is the player that right clicked that NPC.
  • object_name is object's name, for players it would be their username.
  • player, is the UUID of the first player, either subject or object, if no player found, it will be an empty string.
  • player_name, is the username of the first player, either subject_name or object_name, if no player found, it will be an empty string.
  • npc, is the UUID of the first NPC, either subject or object, if no NPC found, it will be an empty string.
  • npc_name, is the display name of the first NPC, either subject_name or object_name, if no NPC found, it will be an empty string.

subject and object are UUID strings that can be used in commands or expressions. Target buttons within condition blocks in Subject and Object states can be used in the same way.

Using with commands

Let's say you have an event that has a Command node which you want to teleport the player two blocks up. You can input following command into the node:

/tp ${subject} ~ ~2 ~

And execute /mp event trigger @r EVENT and it should teleport a random player two blocks up.

Using with expressions

Let's say you have an event that has a Condition node which you want to use to check whether player has 10 HP (5 hearts):

player_hp(subject) >= 10

And execute /mp event trigger @r EVENT and if the player has more than or 5 hearts, then that Condition node will continue execution, and if not then not.

Passing custom data

/mp event trigger command has an optional argument called [data]. There you can pass some arbitrary NBT data which can be used within the event. For example, let's say I have a Switch node somewhere within the event that I want to control from outside, something like this:

Custom variable

So now, I can pass that variable using the last argument through NBT like this:

/mp event trigger @r fire {input:2}

This particular command will pass the input with value of 2, and according to the switch node, it will pass the execution to the node at index 2 (the most right). You can input only numerical and string values into [data]. Compound and list tags are not supported!