Check triggers||doc135692

September 20, 2022

Format

 Trigger.CheckTriggers(cfg, name, context)
  • The class to which the function belongs:Trigger

Description

Triggers a server-defined trigger, and a global trigger is triggered by default. You can also trigger the object's trigger individually by passing in the configuration information of the specified object, but this will still trigger the global trigger. How to register global triggers available at hereCheck.


Objects that can trigger triggers in the game

In the game, as long as the object has configuration information, the trigger can be triggered, including entity objects, game world (global), maps, regions, blocks, and so on.


Precautions

  • If the return parameter of the object trigger's handler is true, the global trigger will not fire.

Parameters

Variable name type Description
cfg config The configuration information of the object that needs to trigger the event
name string event name
context variant Context information carried when the callback function is triggered


Code Samples

Register a trigger named "BLOCK_TRIGGER" in the server script

local blcokCfg = Block:GetNameCfg("myplugin/grass")
Trigger.RegisterHandler(blcokCfg, "BLOCK_TRIGGER", function(context)
    print("Block trigger !")
end)

Check triggers

local blcokCfg = Block:GetNameCfg("myplugin/grass")
Trigger.CheckTriggers(blcokCfg, "BLOCK_TRIGGER", {})