block hit event||doc135418

September 20, 2022

Format

 BLOCK_HITTED
  • The class to which the function belongs:Block

Description

Triggers an event when a block is hit by a projectile.


Precautions

  • Only triggers the hit event when the projectile's properties are set to hit a block will only take effect.

Context

The context content of the event

name type Description
pos Vector3 the coordinates of the block
obj1 Entity the object instance that fires the projectile
missile Missile projectile example


Code Samples

on the server sideglobal script, register when a grass block is hit by a projectileCallback, remove the block

local cfg = Block.GetNameCfg("myplugin/grass")         --Get the grass block config
Trigger.RegisterHandler(cfg, "BLOCK_HITTED", function(context)
    local entity = context.obj1
    local pos =  context.pos
    local map = entity.map                             --Get the current object location map
    map:removeBlock(pos)                               --Remove block
end)