Luaスクリプティング:ワールドと環境
このページでは、context.world、context.vectors、context.settings、context.eventで利用可能なすべてのメソッドを説明します。これらにより、LuaパワーがMinecraftワールドとやり取りできます -- エンティティのスポーン、エフェクトの再生、ブロックの照会など。Luaパワーが初めての場合は、まずはじめにから始めてください。
EliteMobs のボスパワーは MagmaCore の Lua サンドボックスを再利用しています。ボスの context.world は共有された MagmaCore の world テーブルを起点としているため、get_block_at(...)、set_block_at(...)、spawn_particle(...) といった汎用の座標ヘルパーも引き続き利用できます。このページでは、EliteMobs のボス固有の context.world、context.vectors、context.settings、context.event の追加分と上書き分を扱います。汎用のワールド API については MagmaCore Lua スクリプティングエンジンを参照してください。
context.world
world テーブルは、エンティティのスポーン、エフェクトの再生、ブロックの変更、ワールド状態の変更を行うメソッドを提供します。すべてのメソッドはコロン構文(world:method())で呼び出します。
world:spawn_particle_at_location(location, particleSpec)
指定した位置にパーティクルを生成します。第2引数には、単純なパーティクル名の文字列か、詳細に制御するための完全なパーティクル仕様テーブルを渡せます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | パーティクルを生成する位置 |
particleSpec | string または 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
}
パーティクル仕様テーブルの形式
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
particle | string | 必須 | パーティクル名 |
amount | int | 1 | パーティクルの数 |
x, y, z | number | 0 | 各軸方向の広がり/オフセット |
speed | number | 0 | パーティクルの速度 |
red, green, blue | int | 255 | DUST と DUST_COLOR_TRANSITION 用の RGB カラー |
toRed, toGreen, toBlue | int | 255 | DUST_COLOR_TRANSITION の遷移先カラー |
DUST_COLOR_TRANSITION では、スネークケースのキー to_red、to_green、to_blue も使用できます。
EliteScript YAMLの設定とは異なり、Luaのパーティクル名はレガシーパーティクル名の変換をサポートしていません。現在のSpigot API名を使用する必要があります(例:FIREWORKS_SPARK ではなく FIREWORK、SMOKE_NORMAL ではなく SMOKE、REDSTONE ではなく DUST)。現在の名前とレガシー名の対応表は有効なパーティクルリストを参照してください。
world:play_sound_at_location(location, sound, volume, pitch)
指定した位置でサウンドを再生します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | サウンドを再生する位置 | |
sound | string | Minecraftのサウンドキー(例:"entity.blaze.shoot")または Spigot の Sound enum 名。リソースパックのキーも使用できます。 | |
volume | number | 1.0 | 音量 |
pitch | number | 1.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)
指定した位置に落雷を発生させます(視覚効果とダメージの両方)。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 落雷させる位置 |
例
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エンティティをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
entityType | string | エンティティタイプ名(例:"FIREBALL"、"ARROW") |
location | locationテーブル | スポーンさせる位置 |
options | table(省略可) | スポーンオプション(下記参照) |
エンティティのスポーンオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
velocity | vectorテーブル | nil | 初速度 {x, y, z} |
effect | string | nil | スポーン時に再生する EntityEffect |
duration | int | 0 | このティック数の後に自動削除(0 = 削除しない) |
on_land | function | nil | エンティティが地面に着地したときのコールバック |
max_ticks | int | 6000 | on_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)
落下ブロックのエンティティをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
material | string | マテリアル名(例:"STONE"、"MAGMA_BLOCK") |
options | table(省略可) | スポーンオプション(下記参照) |
落下ブロックのオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
velocity | vectorテーブル | nil | 初速度 {x, y, z} |
drop_item | boolean | false | ブロックがアイテムとしてドロップするかどうか |
hurt_entities | boolean | false | ブロックが着地先のエンティティにダメージを与えるかどうか |
on_land | function | nil | ブロックが着地したときのコールバック 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 のカスタムボスをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
filename | string | ボスの設定ファイル名(例:"my_boss.yml") |
location | locationテーブル | スポーンさせる位置 |
options | table(省略可) | スポーンオプション(下記参照) |
カスタムボスのスポーンオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
level | int | ボスのレベル | スポーンするボスのレベルを上書きします |
silent | boolean | false | スポーンメッセージを抑制します |
velocity | vectorテーブル | nil | 初速度 |
add_as_reinforcement | boolean | false | 現在のボスの増援として登録します |
エンティティのラッパーテーブルを返します。ボスを生成できなかった場合は 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)
より簡易なボススポーン用メソッドです。任意のレベルを指定して、指定位置にカスタムボスをスポーンさせます。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
filename | string | ボスの設定ファイル名 | |
location | locationテーブル | ボスの位置 | スポーンさせる位置(省略可、既定ではボスの位置) |
level | int | ボスのレベル | スポーンレベルを上書きします(省略可) |
エンティティのラッパーテーブル、または 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 の増援システムによって管理される増援をスポーンさせます。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
filename | string | ボスの設定ファイル名 | |
location | locationテーブル | スポーンさせる位置 | |
inheritLevel | int | 0 | レベル継承モード(0 = デフォルト) |
velocity | vectorテーブル | 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)
エフェクトを細かく制御できる花火エンティティをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
spec | table | 花火の仕様(下記参照) |
花火の仕様テーブル
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
power | int | 1 | 飛行力(高さ) |
velocity | vectorテーブル | nil | 初速度 |
shot_at_angle | boolean | true | 花火を角度をつけて打ち出すかどうか(velocity 設定時に使用) |
effects | テーブルのテーブル | nil | 花火エフェクト仕様の配列。省略した場合、トップレベルの仕様が単一のエフェクトとして扱われます。 |
花火エフェクトの仕様
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
type | string | "BALL_LARGE" | "BALL"、"BALL_LARGE"、"STAR"、"BURST"、"CREEPER" |
flicker | boolean | true | 明滅エフェクト |
trail | boolean | true | 軌跡エフェクト |
colors | table | nil | カラー名または {red, green, blue} テーブルの配列 |
fade_colors | table | nil | フェード先のカラー名または {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)
投げられたスプラッシュポーションのエンティティをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
spec | table | ポーションの仕様(下記参照) |
スプラッシュポーションの仕様テーブル
| キー | 型 | 備考 |
|---|---|---|
velocity | vectorテーブル | 投げられるポーションの初速度 |
effects | テーブルのテーブル | ポーション効果仕様の配列 |
ポーション効果の仕様
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
type | string | 必須 | ポーション効果タイプ名(例:"SLOWNESS"、"POISON") |
duration | int | 0 | 持続時間(ティック) |
amplifier | int | 0 | 効果の強さ(0 = レベル I) |
overwrite | boolean | true | 同じ種類の既存効果を上書きするかどうか |
エンティティ参照テーブル、または 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)
一定時間後に自動で元に戻る一時的なブロックを設置します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 設置する位置 | |
material | string | マテリアル名 | |
duration | int | 0 | ブロックが元に戻るまでのティック数(0 = 恒久) |
requireAir | boolean | false | true の場合、そのブロックが現在空気のときにのみ設置します |
例
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 を使用してください。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 設置する位置 | |
material | string | マテリアル名 | |
requireAir | boolean | false | true の場合、そのブロックが現在空気のときにのみ設置します |
例
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)
指定位置のブロックのマテリアル名を文字列として返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 座標を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置(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)
指定位置のブロックの爆発耐性を数値として返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 判定に基づきます)。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
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 を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
material | string | 確認するマテリアル名 |
例
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 を渡せます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル(省略可) | 対象とするワールド。既定ではボスのワールドです。 |
time | int | ワールド時間(ティック)(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)
ボスのワールドの天候を設定します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル(省略可) | ボスのワールド | 対象とするワールド |
weather | string | "CLEAR"、"RAIN"(または "PRECIPITATION")、"THUNDER" | |
duration | int | 6000 | 天候の継続時間(ティック) |
例
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 の爆発再生システムを使って、偽の爆発の視覚効果を作ります(ブロックが壊れて再生します)。
| パラメータ | 型 | 備考 |
|---|---|---|
blockLocations | locationテーブルのテーブル | 「爆発」させるブロック位置の配列 |
sourceLocation | locationテーブル(省略可) | 方向計算に使う爆発の発生源 |
例
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)
サーバーとしてコンソールコマンドを実行します。
| パラメータ | 型 | 備考 |
|---|---|---|
command | string | 実行するコマンド(先頭の / は不要) |
例
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)
強化された落雷の視覚演出タスクを実行します(エンダードラゴンのパワーで使用されます)。追加のエフェクトを伴う、より派手な落雷を発生させます。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 落雷させる位置 |
例
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)
弾幕システムで使用される、偽の金塊の投射物をスポーンさせます。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | スポーン位置 | |
velocity | vectorテーブル | 初速度 | |
hasGravity | boolean | false | 投射物に重力を適用するかどうか |
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)
偽の金塊投射物のテーブルについて、近くのエンティティに対するダメージ処理を行います。
| パラメータ | 型 | 備考 |
|---|---|---|
projectiles | table | spawn_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)
ボスにダメージを与えたプレイヤーのために戦利品を生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
times | int | 1 | 戦利品の抽選回数 |
例
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)
ボスへのダメージに貢献したすべてのプレイヤーにボーナスコインをドロップします。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
multiplier | number | 2.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 テーブルは x、y、z のフィールドを持ちます。
vectors.get_vector_between_locations(loc1, loc2, options)
| パラメータ | 型 | 備考 |
|---|---|---|
loc1 | locationテーブル | 始点 |
loc2 | locationテーブル | 終点 |
options | table(省略可) | 後処理オプション(下記参照) |
ベクトルのオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
normalize | boolean | false | 結果のベクトルを正規化します |
multiplier | number | 1.0 | ベクトルをスケールします |
offset | vectorテーブル | 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)
| パラメータ | 型 | 備考 |
|---|---|---|
vec | vectorテーブル | 入力ベクトル |
例
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)
| パラメータ | 型 | 備考 |
|---|---|---|
vec | vectorテーブル | 入力ベクトル |
pitch | number | X 軸まわりの回転(度) |
yaw | number | Y 軸まわりの回転(度) |
例
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_reason | on_spawn | スポーン理由の enum 名 |
event.entity | on_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.eventはnilです。イベントを変更する場合はイベントフックを使用してください。
次のステップ
- はじめに | フックとライフサイクル | ボスとエンティティ | ゾーンとターゲティング | サンプル | Enum | トラブルシューティング
- APIリファレンス | スクリプティングエンジン
