docs/Triggers

Triggers

To Getting Started

Triggers are are a way to set up a reaction to some action or event in the game. If a player dies, that is an event or if a player clicks on a certain block that is an action and we can setup a reaction to these with triggers.

Triggers are set with in-game commands like /vtclick and /vtevent you add lines of script to the trigger with these same commands. Triggers are saved in the trigger files located in the /plugins/VariableTriggers/ folder. Each trigger type has its own file as in WalkTriggers.yml and EventTriggers.yml and so on..

Below is a list of the different trigger types.

Location Triggers

Triggers that are based on a block Location

ClickThis is activated when a player clicks a block, any block, at a location.
WalkThis is activated when a player walks on a block, any block, at a location.

To set a click trigger or add script to an existing click trigger you use /vtclick [Line of script]
To set a walk trigger or add script to an existing walk trigger you use /vtwalk [Line of script]

Command Triggers

Create triggers that run script when a player types a /command. You can make some extra things happen when players type commands like /heal or you can create your very own commands like /foobar or /setquest
See In-Game Commands for a list of commands to create the triggers.

Area Triggers

You can set two locations to create an area cube and set triggers on it.

EnterThis is triggered when player enters the area and runs the attached script.
ExitThis is triggered when player exits the area and runs the attached script.

To set an area trigger you first need to define an area. You do this by typing /vt setarea and then use the wand to Left click for possition 1 and Right click for possition 2. Once the two locations are set type
/vt definearea [AreaName]

To set a trigger on an area or add script to an existing trigger you use
/vtarea [AreaName] [Enter|Exit] [Line of script]

A few words about areas and how they work and remember areas ar 3D cubes so you must also set the height.

Here are the commands to create Area triggers.

Event Triggers

To set an event trigger or add script to an existing event you use
/vtevent [EventName] [Line of script]

PlayerDeathThis is triggered when a Player dies for whatever reason. The normal placeholders refer to this player.
EntityDeathThis is triggered when an Entity(other than a player) is killed by a player. The normal placeholders refer to the killing player. <triggerloc> refers to the location of the entity on death.
RespawnThis is triggerd when a player respawns after dying. <triggerloc> is the respawn location of player.
JoinThis is triggerd when a player joins the server. <triggerloc> is the player's location
QuitThis is triggerd when a player quits the server. <triggerloc> is the player's location. Remember you can't do anything to the player like @TP or <currentloc:> as they have logged out and are no longer in play.
InteractThis is triggerd when a player right clicks on an entity. <triggerloc> is the location of the clicked entity. Entity can be a Player, Mob or Animal. NPC plugins such as Citizens return type PLAYER so you can use their name to determine what NPC is being interacted with.
EntitySpawnThis is triggerd when an entity is spawned. <triggerloc> is the spawn location of the entity. Entity can be a Mob or Animal. This event is usually called A LOT(20 times a second) so keep your scripts small or use IF test and only do something under certain conditions.
ChatThis is triggered when a player types in the chat window. The normal placeholders refer to this player and ther are a few specific to this event. <chatline> <chatwordcount> and <chatword:index>. See Functional Place Holders and Place Holders specific to Chat event.
TimerThe timer will exicute any script attached to it once every minute. It is up to you to set and test your variables to decide how often to allow exicution.
Usage: /vtevent Timer [SCRIPTLINE]
One important thing to remember is that this is not triggered by a player and therefore the normal place holders are not valid. <playername> will be 'null' and <playerloc> will be 0,0,0 <health> will be 0 and so on. You may use Functional Place Holders that let you set a player name and must get it from object variables you have saved. You may not use @PLAYER as it asumes the triggering player but you may use @BROADCAST or @TELL
Inventory ClickFires when you click something in a non-standard inventory with a matching script. May require modifyworld permissions if you use PEX.
cancelled: true or false - should we stop the person from taking the item when they click it?
title: inventory title - color codes work!
slots: how many slots? It MUST be in multiples of 9!
item: [material], meta: [number], name: [name], lore: [lore, seperated by % for a new line], enchant: [enchant], slot: [slot]
name, enchant, and lore are optional
Script Example: (In EventTriggers file)
  Inventory:
    CoolDown: 0
    Script:
    - '@IF s <inventorytitle> ?= TELEPORTS'
    - '    @SWITCH i <clickedslot>'
    - '        @CASE 0'
    - '            @CMDOP spawn'
    - '        @CASE 1'
    - '            @CMDOP warp <playername> pvp'
    - '        @CASE 2'
    - '            @CMDOP warp <playername> minigames'
    - '    @ENDSWITCH'
    - '@ENDIF'
Inventories example (InventoryTriggers.yml)
  teleportInventory:
    - 'cancelled: true'
    - 'title: TELEPORTS'
    - 'slots: 9'
    - 'item: wool, meta: 5, amount: 1, name: Spawn, lore: Teleport % &a&ospawn, enchant:durability, slot: 0'
    - 'item: wool, meta: 6, amount: 1, name: PVP, lore: Teleport % &4&opvp, enchant:durability, slot: 1'
    - 'item: wool, meta: 7, amount: 1, name: Minigames, lore: Teleport % &3&ominigames, enchant:durability, slot: 2'
BlockBreakThis is triggered when a block is broken. The normal placeholders refer to the player. <triggerloc> refers to the location of the broken block.
BlockPlacedThis is triggered when a block is placed. The normal placeholders refer to the player. <triggerloc> refers to the location of the placed block.

BlockBreak and BlockPlaced Events are not called if any other block protection has cancelled it. This should be true with most severs but depending on the plugins you use it may still be cancelled after the script is called so if you experience your scripts running even though the event was cancelled you need to test for this in your script if you only want your script to run if the event was not cancelled. Since VariableTriggers Script Interpreter runs on its own thread it starts running the script faster than the other plugins have a chance to cancel the event so start your script for these two events with a pause and test like so:

For BlockBreak:

- '// Pause 1/4 second'
- '@PAUSE 0.25'
- '// Test to see if block was is still there'
- '@IF <isblocktype:<triggerloc>:<blocktype>> = false'
- '// Break was succesfull so continue with script'

For BlockPlaced:

- '// Pause 1/4 second'
- '@PAUSE 0.25'
- '// Test to see if block was is still there'
- '@IF <isblocktype:<triggerloc>:<blocktype>> = true'
- '// Place was succesfull so continue with script'
LeftClickThis is triggered when you... left click.
RightClickThis is triggered when you... right click.
WorldChangeThis is triggered when you change worlds. You will need the event in the world that you are going to. Trigger specific placeholders; <worldto> and <worldfrom>.
WeatherChangeThis is triggered when the wheather changes. <weather> - boolean - true for stormy, false for sunny.
SneakThis is triggered when you sneak or unsneak. <sneaking> - boolean - true if they entered sneak mode, and false if they went out of it.
SprintThis is triggered when you start and stop sprinting. <sprinting> - boolean - true if they started sprinting, false if they stopped.
FlightThis is triggered when you start and stop flying. <flying> - boolean - true if they started flying, false if they landed.
EnableTriggers when the plugin loads. The world must be set to "VTSYSTEM"
DisableTriggers when the plugin disables. The world must be set to "VTSYSTEM"
To Getting Started