メインコンテンツまでスキップ

Luaスクリプティング:ワールドと環境

webapp_banner.jpg

このページでは、context.worldcontext.vectorscontext.settingscontext.eventで利用可能なすべてのメソッドを説明します。これらにより、LuaパワーがMinecraftワールドとやり取りできます -- エンティティのスポーン、エフェクトの再生、ブロックの照会など。Luaパワーが初めての場合は、まずはじめにから始めてください。

EliteMobs boss context

EliteMobs のボスパワーは MagmaCore の Lua サンドボックスを再利用しています。ボスの context.world は共有された MagmaCore の world テーブルを起点としているため、get_block_at(...)set_block_at(...)spawn_particle(...) といった汎用の座標ヘルパーも引き続き利用できます。このページでは、EliteMobs のボス固有の context.worldcontext.vectorscontext.settingscontext.event の追加分と上書き分を扱います。汎用のワールド API については MagmaCore Lua スクリプティングエンジンを参照してください。


context.world

world テーブルは、エンティティのスポーン、エフェクトの再生、ブロックの変更、ワールド状態の変更を行うメソッドを提供します。すべてのメソッドはコロン構文(world:method())で呼び出します。


world:spawn_particle_at_location(location, particleSpec)

指定した位置にパーティクルを生成します。第2引数には、単純なパーティクル名の文字列か、詳細に制御するための完全なパーティクル仕様テーブルを渡せます。

パラメータ備考
locationlocationテーブルパーティクルを生成する位置
particleSpecstring または tableパーティクル名 またはパーティクル仕様テーブル(下記参照)
return {
api_version = 1,
on_enter_combat = function(context)
-- Simple particle by name
context.world:spawn_particle_at_location(context.boss:get_location(), "FLAME")

-- Full particle spec table with red dust
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "DUST",
amount = 10,
x = 0.5,
y = 0.5,
z = 0.5,
speed = 0.02,
red = 255,
green = 0,
blue = 0,
})
end
}

パーティクル仕様テーブルの形式

キーデフォルト備考
particlestring必須パーティクル名
amountint1パーティクルの数
x, y, znumber0各軸方向の広がり/オフセット
speednumber0パーティクルの速度
red, green, blueint255DUSTDUST_COLOR_TRANSITION 用の RGB カラー
toRed, toGreen, toBlueint255DUST_COLOR_TRANSITION の遷移先カラー
ヒント

DUST_COLOR_TRANSITION では、スネークケースのキー to_redto_greento_blue も使用できます。

警告

EliteScript YAMLの設定とは異なり、Luaのパーティクル名はレガシーパーティクル名の変換をサポートしていません。現在のSpigot API名を使用する必要があります(例:FIREWORKS_SPARK ではなく FIREWORKSMOKE_NORMAL ではなく SMOKEREDSTONE ではなく DUST)。現在の名前とレガシー名の対応表は有効なパーティクルリストを参照してください。


world:play_sound_at_location(location, sound, volume, pitch)

指定した位置でサウンドを再生します。

パラメータデフォルト備考
locationlocationテーブルサウンドを再生する位置
soundstringMinecraftのサウンドキー(例:"entity.blaze.shoot")または Spigot の Sound enum 名。リソースパックのキーも使用できます。
volumenumber1.0音量
pitchnumber1.0ピッチ
return {
api_version = 1,
on_spawn = function(context)
context.world:play_sound_at_location(
context.boss:get_location(),
"entity.wither.spawn",
1.0,
0.5
)
end
}

world:strike_lightning_at_location(location)

指定した位置に落雷を発生させます(視覚効果とダメージの両方)。

パラメータ備考
locationlocationテーブル落雷させる位置
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("lightning", 100) then return end
context.world:strike_lightning_at_location(context.player:get_location())
context.player:send_message("&eA bolt of lightning strikes you!")
end
}

world:spawn_entity_at_location(entityType, location, options)

バニラのMinecraftエンティティをスポーンさせます。

パラメータ備考
entityTypestringエンティティタイプ名(例:"FIREBALL""ARROW"
locationlocationテーブルスポーンさせる位置
optionstable(省略可)スポーンオプション(下記参照)

エンティティのスポーンオプション

キーデフォルト備考
velocityvectorテーブルnil初速度 {x, y, z}
effectstringnilスポーン時に再生する EntityEffect
durationint0このティック数の後に自動削除(0 = 削除しない)
on_landfunctionnilエンティティが地面に着地したときのコールバック
max_ticksint6000on_land コールバックを強制するまでに監視する最大ティック数

エンティティのラッパーテーブルを返します。

return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("fireball_spawn", 100) then return end
-- Spawn a fireball aimed at the player
local boss_loc = context.boss:get_location()
local dir = context.vectors.get_vector_between_locations(boss_loc, context.player:get_location())
dir = context.vectors.normalize_vector(dir)

context.world:spawn_entity_at_location("FIREBALL", boss_loc, {
velocity = { x = dir.x * 2, y = dir.y * 2, z = dir.z * 2 },
duration = 100,
})
end
}
return {
api_version = 1,
on_enter_combat = function(context)
-- Spawn a primed TNT with a landing callback
context.world:spawn_entity_at_location("TNT", context.boss:get_location(), {
velocity = { x = 0, y = 1.5, z = 0 },
on_land = function(land_location, entity_ref)
context.world:spawn_particle_at_location(land_location, {
particle = "EXPLOSION_EMITTER",
amount = 1,
})
end,
})
end
}

world:spawn_falling_block_at_location(location, material, options)

落下ブロックのエンティティをスポーンさせます。

パラメータ備考
locationlocationテーブルスポーンさせる位置
materialstringマテリアル名(例:"STONE""MAGMA_BLOCK"
optionstable(省略可)スポーンオプション(下記参照)

落下ブロックのオプション

キーデフォルト備考
velocityvectorテーブルnil初速度 {x, y, z}
drop_itembooleanfalseブロックがアイテムとしてドロップするかどうか
hurt_entitiesbooleanfalseブロックが着地先のエンティティにダメージを与えるかどうか
on_landfunctionnilブロックが着地したときのコールバック function(land_location, entity_ref)

エンティティ参照テーブルを返します。

return {
api_version = 1,
on_enter_combat = function(context)
-- Rain magma blocks from above
local loc = context.boss:get_location()
for i = 1, 5 do
local offset_loc = {
x = loc.x + math.random(-3, 3),
y = loc.y + 10,
z = loc.z + math.random(-3, 3),
world = loc.world
}
context.world:spawn_falling_block_at_location(offset_loc, "MAGMA_BLOCK", {
velocity = { x = 0, y = -0.5, z = 0 },
hurt_entities = true,
on_land = function(land_location, entity_ref)
context.world:spawn_particle_at_location(land_location, { particle = "LAVA", amount = 8 })
end,
})
end
end
}

world:spawn_custom_boss_at_location(filename, location, options)

設定ファイルから EliteMobs のカスタムボスをスポーンさせます。

パラメータ備考
filenamestringボスの設定ファイル名(例:"my_boss.yml"
locationlocationテーブルスポーンさせる位置
optionstable(省略可)スポーンオプション(下記参照)

カスタムボスのスポーンオプション

キーデフォルト備考
levelintボスのレベルスポーンするボスのレベルを上書きします
silentbooleanfalseスポーンメッセージを抑制します
velocityvectorテーブルnil初速度
add_as_reinforcementbooleanfalse現在のボスの増援として登録します

エンティティのラッパーテーブルを返します。ボスを生成できなかった場合は nil を返します。

return {
api_version = 1,
on_enter_combat = function(context)
local minion = context.world:spawn_custom_boss_at_location(
"skeleton_minion.yml",
context.boss:get_location(),
{ level = 10, add_as_reinforcement = true }
)
if minion ~= nil then
context.boss:send_message("&cMinions, arise!")
end
end
}

world:spawn_boss_at_location(filename, location, level)

より簡易なボススポーン用メソッドです。任意のレベルを指定して、指定位置にカスタムボスをスポーンさせます。

パラメータデフォルト備考
filenamestringボスの設定ファイル名
locationlocationテーブルボスの位置スポーンさせる位置(省略可、既定ではボスの位置)
levelintボスのレベルスポーンレベルを上書きします(省略可)

エンティティのラッパーテーブル、または nil を返します。

return {
api_version = 1,
on_enter_combat = function(context)
context.world:spawn_boss_at_location("zombie_guard.yml", context.boss:get_location(), 5)
context.boss:send_message("&cGuards, defend me!")
end
}

world:spawn_reinforcement_at_location(filename, location, inheritLevel, velocity)

EliteMobs の増援システムによって管理される増援をスポーンさせます。

パラメータデフォルト備考
filenamestringボスの設定ファイル名
locationlocationテーブルスポーンさせる位置
inheritLevelint0レベル継承モード(0 = デフォルト)
velocityvectorテーブルnil初速度(省略可)

エンティティのラッパーテーブル、または nil を返します。

return {
api_version = 1,
on_enter_combat = function(context)
context.world:spawn_reinforcement_at_location(
"necro_skeleton.yml",
context.boss:get_location(),
0,
{ x = 0, y = 0.5, z = 0 }
)
context.boss:send_message("&5Rise, my servant!")
end
}

world:spawn_fireworks_at_location(location, spec)

エフェクトを細かく制御できる花火エンティティをスポーンさせます。

パラメータ備考
locationlocationテーブルスポーンさせる位置
spectable花火の仕様(下記参照)

花火の仕様テーブル

キーデフォルト備考
powerint1飛行力(高さ)
velocityvectorテーブルnil初速度
shot_at_anglebooleantrue花火を角度をつけて打ち出すかどうか(velocity 設定時に使用)
effectsテーブルのテーブルnil花火エフェクト仕様の配列。省略した場合、トップレベルの仕様が単一のエフェクトとして扱われます。

花火エフェクトの仕様

キーデフォルト備考
typestring"BALL_LARGE""BALL""BALL_LARGE""STAR""BURST""CREEPER"
flickerbooleantrue明滅エフェクト
trailbooleantrue軌跡エフェクト
colorstablenilカラー名または {red, green, blue} テーブルの配列
fade_colorstablenilフェード先のカラー名または {red, green, blue} テーブルの配列

カラー名: "WHITE", "SILVER", "GRAY", "BLACK", "RED", "MAROON", "YELLOW", "OLIVE", "LIME", "GREEN", "AQUA", "TEAL", "BLUE", "NAVY", "FUCHSIA", "PURPLE", "ORANGE"

エンティティ参照テーブルを返します。そのテーブルに対して :detonate() を呼び出すと、即座に爆発させられます。

return {
api_version = 1,
on_spawn = function(context)
local fw = context.world:spawn_fireworks_at_location(context.boss:get_location(), {
power = 0,
effects = {
{
type = "STAR",
flicker = true,
trail = true,
colors = { "RED", "ORANGE", { red = 255, green = 200, blue = 0 } },
fade_colors = { "YELLOW" },
},
},
})

-- Detonate immediately for a visual burst
context.scheduler:run_after(1, function()
fw:detonate()
end)
end
}

world:spawn_splash_potion_at_location(location, spec)

投げられたスプラッシュポーションのエンティティをスポーンさせます。

パラメータ備考
locationlocationテーブルスポーンさせる位置
spectableポーションの仕様(下記参照)

スプラッシュポーションの仕様テーブル

キー備考
velocityvectorテーブル投げられるポーションの初速度
effectsテーブルのテーブルポーション効果仕様の配列

ポーション効果の仕様

キーデフォルト備考
typestring必須ポーション効果タイプ名(例:"SLOWNESS""POISON"
durationint0持続時間(ティック)
amplifierint0効果の強さ(0 = レベル I)
overwritebooleantrue同じ種類の既存効果を上書きするかどうか

エンティティ参照テーブル、または nil を返します。

return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("potion_throw", 200) then return end

local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
dir = context.vectors.normalize_vector(dir)

context.world:spawn_splash_potion_at_location(context.boss:get_location(), {
velocity = { x = dir.x * 1.5, y = 0.5, z = dir.z * 1.5 },
effects = {
{ type = "SLOWNESS", duration = 100, amplifier = 1 },
{ type = "WEAKNESS", duration = 60, amplifier = 0 },
},
})
end
}

world:place_temporary_block_at_location(location, material, duration, requireAir)

一定時間後に自動で元に戻る一時的なブロックを設置します。

パラメータデフォルト備考
locationlocationテーブル設置する位置
materialstringマテリアル名
durationint0ブロックが元に戻るまでのティック数(0 = 恒久)
requireAirbooleanfalsetrue の場合、そのブロックが現在空気のときにのみ設置します
return {
api_version = 1,
on_enter_combat = function(context)
-- Create a temporary ice floor under the boss
local loc = context.boss:get_location()
for dx = -2, 2 do
for dz = -2, 2 do
context.world:place_temporary_block_at_location(
{ x = loc.x + dx, y = loc.y - 1, z = loc.z + dz, world = loc.world },
"PACKED_ICE",
100,
false
)
end
end
end
}

world:set_block_at_location(location, material, requireAir)

ブロックを恒久的に設置します。元に戻したい場合は place_temporary_block_at_location を使用してください。

パラメータデフォルト備考
locationlocationテーブル設置する位置
materialstringマテリアル名
requireAirbooleanfalsetrue の場合、そのブロックが現在空気のときにのみ設置します
return {
api_version = 1,
on_enter_combat = function(context)
-- Place fire at the boss's location
context.world:set_block_at_location(context.boss:get_location(), "FIRE", true)
end
}

world:get_block_type_at_location(location)

指定位置のブロックのマテリアル名を文字列として返します。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
local block_type = context.world:get_block_type_at_location(context.boss:get_location())
if block_type == "WATER" then
context.boss:send_message("&bThe boss is empowered by water!")
context.boss:apply_potion_effect("SPEED", 200, 1)
end
end
}

world:get_highest_block_y_at_location(location)

指定した X/Z 位置において、空気でない最も高いブロックの Y 座標を返します。

パラメータ備考
locationlocationテーブル照会する位置(X と Z が使用されます)
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("skyport", 200) then return end
local loc = context.player:get_location()
local ground_y = context.world:get_highest_block_y_at_location(loc)
-- Teleport the player to the surface
context.player:teleport_to_location({
x = loc.x, y = ground_y + 1, z = loc.z, world = loc.world
})
context.player:send_message("&eYou are teleported to the surface!")
end
}

world:get_blast_resistance_at_location(location)

指定位置のブロックの爆発耐性を数値として返します。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
local resistance = context.world:get_blast_resistance_at_location(context.boss:get_location())
context.log:info("Blast resistance at boss: " .. resistance)
end
}

world:is_air_at_location(location)

指定位置のブロックが空気であれば true を返します。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local above = { x = loc.x, y = loc.y + 2, z = loc.z, world = loc.world }
if context.world:is_air_at_location(above) then
-- There is space above the boss, launch upward
context.boss:set_velocity_vector({ x = 0, y = 1.5, z = 0 })
end
end
}

world:is_passable_at_location(location)

指定位置のブロックが通過可能(エンティティがすり抜けられる)であれば true を返します。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
if context.world:is_passable_at_location(context.boss:get_location()) then
context.log:info("Boss is in a passable block")
end
end
}

world:is_passthrough_at_location(location)

指定位置のブロックが固体でなければ true を返します(passable に似ていますが、solid 判定に基づきます)。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local above = { x = loc.x, y = loc.y + 1, z = loc.z, world = loc.world }
if context.world:is_passthrough_at_location(above) then
context.log:info("Boss can move upward")
end
end
}

world:is_on_floor_at_location(location)

指定位置のブロックが固体でなく、かつその真下のブロックが固体である場合(つまりその位置が「床の上に立っている」状態の場合)に true を返します。

パラメータ備考
locationlocationテーブル照会する位置
return {
api_version = 1,
on_enter_combat = function(context)
if context.world:is_on_floor_at_location(context.boss:get_location()) then
context.boss:send_message("&aThe boss slams the ground!")
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "CLOUD",
amount = 30,
})
end
end
}

world:is_standing_on_material(location, material)

指定位置の真下のブロックが指定したマテリアルと一致する場合に true を返します。

パラメータ備考
locationlocationテーブル照会する位置
materialstring確認するマテリアル名
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if context.world:is_standing_on_material(context.player:get_location(), "SOUL_SAND") then
context.player:send_message("&8The soul sand saps your strength!")
context.player:apply_potion_effect("SLOWNESS", 60, 2)
end
end
}

world:set_world_time(time) / world:set_world_time(location, time)

ワールドの時間を設定します。どのワールドを対象にするかを指定するため、任意で location を渡せます。

パラメータ備考
locationlocationテーブル(省略可)対象とするワールド。既定ではボスのワールドです。
timeintワールド時間(ティック)(0 = 夜明け、6000 = 正午、13000 = 夜、18000 = 真夜中)
return {
api_version = 1,
on_enter_combat = function(context)
-- Set to midnight when combat starts
context.world:set_world_time(18000)
context.boss:send_message("&8Darkness falls...")
end
}

world:set_world_weather(weather, duration) / world:set_world_weather(location, weather, duration)

ボスのワールドの天候を設定します。

パラメータデフォルト備考
locationlocationテーブル(省略可)ボスのワールド対象とするワールド
weatherstring"CLEAR""RAIN"(または "PRECIPITATION")、"THUNDER"
durationint6000天候の継続時間(ティック)
return {
api_version = 1,
on_enter_combat = function(context)
-- Start a thunderstorm for 200 ticks
context.world:set_world_weather("THUNDER", 200)
context.boss:send_message("&eA storm gathers!")
end
}

world:generate_fake_explosion(blockLocations, sourceLocation)

EliteMobs の爆発再生システムを使って、偽の爆発の視覚効果を作ります(ブロックが壊れて再生します)。

パラメータ備考
blockLocationslocationテーブルのテーブル「爆発」させるブロック位置の配列
sourceLocationlocationテーブル(省略可)方向計算に使う爆発の発生源
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local blocks = {}
for dx = -1, 1 do
for dz = -1, 1 do
table.insert(blocks, { x = loc.x + dx, y = loc.y, z = loc.z + dz, world = loc.world })
end
end
context.world:generate_fake_explosion(blocks, loc)
end
}

world:run_console_command(command)

サーバーとしてコンソールコマンドを実行します。

パラメータ備考
commandstring実行するコマンド(先頭の / は不要)
return {
api_version = 1,
on_enter_combat = function(context)
context.world:run_console_command("say The boss has entered phase 2!")
end
}

world:run_empowered_lightning_task_at_location(location)

強化された落雷の視覚演出タスクを実行します(エンダードラゴンのパワーで使用されます)。追加のエフェクトを伴う、より派手な落雷を発生させます。

パラメータ備考
locationlocationテーブル落雷させる位置
return {
api_version = 1,
on_enter_combat = function(context)
context.world:run_empowered_lightning_task_at_location(context.boss:get_location())
context.boss:send_message("&eFeel the power of the storm!")
end
}

world:spawn_fake_gold_nugget_at_location(location, velocity, hasGravity)

弾幕システムで使用される、偽の金塊の投射物をスポーンさせます。

パラメータデフォルト備考
locationlocationテーブルスポーン位置
velocityvectorテーブル初速度
hasGravitybooleanfalse投射物に重力を適用するかどうか

get_location()set_gravity(bool)remove()is_removed() のメソッドを持つ、偽投射物のテーブルを返します。

return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("nugget", 60) then return end

local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
dir = context.vectors.normalize_vector(dir)

context.world:spawn_fake_gold_nugget_at_location(
context.boss:get_location(),
{ x = dir.x, y = dir.y, z = dir.z }
)
end
}

world:run_fake_gold_nugget_damage(projectiles)

偽の金塊投射物のテーブルについて、近くのエンティティに対するダメージ処理を行います。

パラメータ備考
projectilestablespawn_fake_gold_nugget_at_location が返す偽投射物テーブルの配列
return {
api_version = 1,
on_enter_combat = function(context)
-- Spawn some projectiles and store them
context.state.active_projectiles = {}
local loc = context.boss:get_location()
for i = 1, 5 do
local angle = (i / 5) * math.pi * 2
local nugget = context.world:spawn_fake_gold_nugget_at_location(
loc,
{ x = math.cos(angle) * 0.5, y = 0.3, z = math.sin(angle) * 0.5 }
)
table.insert(context.state.active_projectiles, nugget)
end

-- Process damage each tick for 3 seconds
local task_id
task_id = context.scheduler:run_every(1, function(tick_context)
tick_context.world:run_fake_gold_nugget_damage(tick_context.state.active_projectiles)
end)
context.scheduler:run_after(60, function(later_context)
later_context.scheduler:cancel_task(task_id)
end)
end
}

world:generate_player_loot(times)

ボスにダメージを与えたプレイヤーのために戦利品を生成します。

パラメータデフォルト備考
timesint1戦利品の抽選回数
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
local pct = context.boss:get_health() / context.boss:get_maximum_health()
if pct < 0.5 and not context.boss:has_tag("bonus_loot") then
context.boss:add_tag("bonus_loot")
context.world:generate_player_loot(2)
context.boss:send_message("&6Bonus loot drops!")
end
end
}

world:drop_bonus_coins(multiplier)

ボスへのダメージに貢献したすべてのプレイヤーにボーナスコインをドロップします。

パラメータデフォルト備考
multipliernumber2.0コイン量の倍率
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
local pct = context.boss:get_health() / context.boss:get_maximum_health()
if pct < 0.25 and not context.boss:has_tag("bonus_coins") then
context.boss:add_tag("bonus_coins")
context.world:drop_bonus_coins(3.0)
context.boss:send_message("&6Gold spills everywhere!")
end
end
}

context.vectors

ベクトル計算のヘルパーです。これらはメソッドではなく通常の関数として(ドット構文で)呼び出します。

メソッド戻り値備考
vectors.get_vector_between_locations(loc1, loc2[, options])vectorテーブルloc1 から loc2 への方向
vectors.normalize_vector(vec)vectorテーブル単位長のベクトルを返します
vectors.rotate_vector(vec, pitch, yaw)vectorテーブルベクトルをピッチとヨーの度数だけ回転させます

すべての vector テーブルは xyz のフィールドを持ちます。

vectors.get_vector_between_locations(loc1, loc2, options)

パラメータ備考
loc1locationテーブル始点
loc2locationテーブル終点
optionstable(省略可)後処理オプション(下記参照)

ベクトルのオプション

キーデフォルト備考
normalizebooleanfalse結果のベクトルを正規化します
multipliernumber1.0ベクトルをスケールします
offsetvectorテーブルnilオフセットベクトルを加算します
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("dash", 100) then return end
-- Compute a normalized direction from boss to player, scaled to speed 2
local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location(),
{ normalize = true, multiplier = 2.0 }
)
-- Launch the boss toward the player
context.boss:set_velocity_vector(dir)
end
}

vectors.normalize_vector(vec)

パラメータ備考
vecvectorテーブル入力ベクトル
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local raw = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
local unit = context.vectors.normalize_vector(raw)
context.log:info("Direction: " .. unit.x .. ", " .. unit.y .. ", " .. unit.z)
end
}

vectors.rotate_vector(vec, pitch, yaw)

パラメータ備考
vecvectorテーブル入力ベクトル
pitchnumberX 軸まわりの回転(度)
yawnumberY 軸まわりの回転(度)
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("spread_shot", 100) then return end
local forward = context.vectors.normalize_vector(
context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
)
-- Fire three fireballs in a spread pattern
for _, yaw_offset in ipairs({ -30, 0, 30 }) do
local dir = context.vectors.rotate_vector(forward, 0, yaw_offset)
context.boss:summon_projectile(
"FIREBALL",
context.boss:get_eye_location(),
{
x = context.boss:get_location().x + dir.x * 10,
y = context.boss:get_location().y + dir.y * 10,
z = context.boss:get_location().z + dir.z * 10,
world = context.boss:get_location().world
},
1.0
)
end
end
}
ヒント

基準ベクトルをループで回転させることで、方向の扇状の広がりを作れます。

local base = context.vectors.normalize_vector(
context.vectors.get_vector_between_locations(boss_loc, target_loc)
)
for angle = 0, 360, 30 do
local dir = context.vectors.rotate_vector(base, 0, angle)
-- Use dir for spawning projectiles in a ring
end

context.settings

パワー関連の設定値への読み取り専用アクセスです。

メソッド戻り値備考
settings:warning_visual_effects_enabled()booleanモブ戦闘設定で警告用の視覚エフェクトが有効かどうか
return {
api_version = 1,
on_enter_combat = function(context)
if context.settings:warning_visual_effects_enabled() then
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "DUST",
amount = 20,
red = 255, green = 0, blue = 0,
})
end
end
}

context.event

現在のフックのイベントデータです。利用できるフィールドは、呼び出しのきっかけとなったフックによって異なります。

フィールドまたはメソッド利用できる場面備考
event.damage_amountダメージ系フック現在のダメージ量(呼び出し時点のスナップショット)
event.damage_causeダメージ系フックBukkit の DamageCause enum 名(例:"ENTITY_ATTACK"
event.cancel_event()キャンセル可能なイベントイベントをキャンセルします
event.set_damage_amount(value)EliteDamageEvent ベースのフックダメージを直接設定します
event.multiply_damage_amount(multiplier)EliteDamageEvent ベースのフック現在のダメージを乗算します
event.damagerダメージを与えたエンティティがいるダメージイベントダメージを与えた側のエンティティ参照ラッパー
event.projectileダメージを与えたのが投射物であるダメージイベント投射物のエンティティ参照ラッパー
event.spawn_reasonon_spawnスポーン理由の enum 名
event.entityon_death、ゾーン系イベント該当するエンティティのラッパー

例: 受けるダメージを半減させる

return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.event ~= nil then
local dmg = context.event.damage_amount
context.log:info("Boss took " .. dmg .. " damage, halving it")
context.event.multiply_damage_amount(0.5)
end
end
}

例: 投射物によるダメージをキャンセルする

return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.event ~= nil and context.event.damage_cause == "PROJECTILE" then
context.event.cancel_event()
if context.player ~= nil then
context.player:send_message("&cThe boss deflects your projectile!")
end
end
end
}

例: ダメージ原因を読み取る

return {
api_version = 1,
on_player_damaged_by_boss = function(context)
if context.event ~= nil then
context.log:info("Damage cause: " .. (context.event.damage_cause or "unknown"))
end
end
}
注記
  • damage_amount はスナップショットです。set_damage_amount()multiply_damage_amount() を呼び出した後も自動的には更新されません。
  • スケジュールされたコールバックの内部では、context.eventnil です。イベントを変更する場合はイベントフックを使用してください。

次のステップ