Luaスクリプティング:ボスとエンティティ
このページでは、EliteMobsのLuaパワーにおけるボスおよびエンティティのラッパー(context.boss、context.player、context.players、context.entities)と、それらが返すエンティティラッパーテーブルについてすべて解説します。Luaパワーが初めての方は、まずはじめにから始めてください。
エンティティラッパー
Lua APIを通じてエンティティにアクセスする際 -- context.boss、context.player、context.players:nearby_players()のようなクエリ結果、またはイベントのフィールドのいずれからでも -- 常にラッパーテーブルを受け取ります。これらは生のBukkitオブジェクトではありません。各ラッパーはフィールド(作成時に取得されたスナップショット値)とメソッド(呼び出すたびにサーバーに問い合わせるライブ呼び出し)のセットを提供します。
覚えておくべき2つのルール:
- フィールド(
health、current_location、maximum_healthなど)はスナップショットです。ラッパーが作成された瞬間の状態を反映し、自動更新されません。 - メソッド(
get_location()、get_health()、is_alive()など)は呼び出すたびにライブチェックを実行します。
共通のエンティティフィールド
すべてのリビングエンティティラッパーには以下のフィールドが含まれます。
| フィールド | 型 | 備考 |
|---|---|---|
entity.name | string | 表示名 |
entity.uuid | string | テキスト形式のUUID |
entity.entity_type | string | BukkitのEntityType名(例:"ZOMBIE"、"PLAYER") |
entity.is_player | boolean | プレイヤーの場合true |
entity.is_elite | boolean | EliteMobsがエリートとして追跡している場合true |
entity.is_mount | boolean | このラッパーがボスのマウントを表す場合true |
entity.is_monster | boolean | モンスタータイプのエンティティの場合true |
entity.is_valid | boolean | スナップショットの有効性フラグ |
entity.health | number | 現在の体力(スナップショット) |
entity.maximum_health | number | 最大体力(スナップショット) |
entity.current_location | locationテーブル | ラッパー作成時の位置 |
ボスレベルなどのエリート固有のデータを読み取るには、下記のcontext.bossセクションで説明するcontext.bossのフィールドとメソッドを使用してください。スクリプトからエリートをデスポーンさせるには、entity:remove_elite()メソッドを呼び出してください。
例
return {
api_version = 1,
on_enter_combat = function(context)
context.log:info("Boss level: " .. context.boss.level)
end
}
例
return {
api_version = 1,
on_enter_combat = function(context)
local target = context.players:current_target()
if target ~= nil then
context.log:info("Target: " .. target.name .. " HP: " .. target.health)
end
end
}
共通のエンティティメソッド
すべてのリビングエンティティラッパーは以下のメソッドをサポートします。各メソッドはサーバーへのライブ呼び出しを実行します。
entity:is_alive()
エンティティがまだ有効で死亡していない場合にtrueを返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if context.player:is_alive() then
context.player:send_message("&aYou're still standing!")
end
end
}
entity:get_location()
現在のライブ位置をlocationテーブルとして返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local loc = context.player:get_location()
context.world:play_sound_at_location(loc, "entity.experience_orb.pickup")
end
}
entity:get_eye_location()
目線の高さの位置をlocationテーブルとして返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local eye = context.player:get_eye_location()
context.world:spawn_particle_at_location(eye, "FLAME")
end
}
entity:get_health() / entity:get_maximum_health()
ライブの現在体力または最大体力を返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local pct = context.player:get_health() / context.player:get_maximum_health()
if pct < 0.25 then
context.player:send_message("&cYou're running low!")
end
end
}
entity:get_velocity()
エンティティの現在の速度をvectorテーブルとして返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local vel = context.player:get_velocity()
context.log:info("Player speed Y: " .. vel.y)
end
}
entity:send_message(text)
エンティティにチャットメッセージを送信します。EliteMobsのカラーフォーマットをサポートします。
| パラメータ | 型 | 備考 |
|---|---|---|
text | string | カラーコード付きのメッセージ |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:send_message("&6[Boss] &fPrepare yourself!")
end
}
entity:show_action_bar(message)
エンティティにアクションバーメッセージを送信します。
| パラメータ | 型 | 備考 |
|---|---|---|
message | string | カラーコード付きのアクションバーテキスト |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:show_action_bar("&c&lDANGER ZONE")
end
}
entity:show_title(title[, subtitle][, fadeIn][, stay][, fadeOut])
エンティティにタイトルとオプションのサブタイトルを送信します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
title | string | タイトルテキスト | |
subtitle | string | "" | サブタイトルテキスト |
fadeIn | number | 10 | フェードインのティック数 |
stay | number | 40 | 表示維持のティック数 |
fadeOut | number | 10 | フェードアウトのティック数 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local nearby = context.players:nearby_players(20)
for _, p in ipairs(nearby) do
p:show_title("&4PHASE 2", "&7The boss is enraged!", 10, 40, 10)
end
end
}
entity:show_boss_bar(title[, color][, style][, duration])
エンティティに一時的なボスバーを表示します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
title | string | バーのタイトルテキスト | |
color | string | "WHITE" | BarColorの値 |
style | string | "SOLID" | BarStyleの値 |
duration | number | 40 | ティック単位の持続時間 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local nearby = context.players:nearby_players(20)
for _, p in ipairs(nearby) do
p:show_boss_bar("&cIncoming Attack!", "RED", "SOLID", 100)
end
end
}
entity:teleport_to_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("teleport_pull", 200) then return end
context.player:teleport_to_location(context.boss:get_location())
context.player:send_message("&cThe boss pulls you in!")
end
}
entity:set_velocity_vector(vector)
エンティティの速度を即座に設定します。
| パラメータ | 型 | 備考 |
|---|---|---|
vector | vectorテーブル | { x, y, z }または{ x = 0, y = 1, z = 0 } |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("launch", 100) then return end
context.player:set_velocity_vector({ x = 0, y = 1.5, z = 0 })
context.player:send_message("&cYou are launched into the air!")
end
}
entity:apply_push_vector(vector[, additive][, delay])
短い遅延(デフォルト1ティック)の後に速度の押し出しを適用します。ノックバックを上書きするのに便利です。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
vector | vectorテーブル | 方向と強さ | |
additive | boolean | false | 置き換える代わりに既存の速度に加算する |
delay | number | 1 | 適用するまでのティック単位の遅延 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("push_up", 100) then return end
context.player:apply_push_vector({ x = 0, y = 2.0, z = 0 })
context.player:send_message("&cUpward blast!")
end
}
entity:face_direction_or_location(directionOrLocation)
エンティティを方向ベクトルまたは位置の方を向かせます。
| パラメータ | 型 | 備考 |
|---|---|---|
directionOrLocation | vectorまたはlocationテーブル | 向く対象 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:face_direction_or_location(context.boss:get_location())
context.player:send_message("&cThe boss forces you to look at it!")
end
}
entity:set_fire_ticks(ticks)
指定した時間だけエンティティを燃やします。
| パラメータ | 型 | 備考 |
|---|---|---|
ticks | number | ティック単位の燃焼時間(20ティック = 1秒) |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("ignite", 100) then return end
context.player:set_fire_ticks(60)
context.player:send_message("&cYou catch fire!")
end
}
entity:add_visual_freeze_ticks([ticks])
エンティティに視覚的な凍結ティック(青いオーバーレイエフェクト)を追加します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
ticks | number | 1 | 凍結ティック量 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("freeze", 200) then return end
context.player:add_visual_freeze_ticks(100)
context.player:send_message("&bYou feel a chilling frost!")
end
}
entity:apply_potion_effect(effect, duration[, amplifier])
エンティティにポーション効果を適用します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
effect | string | PotionEffectType名 | |
duration | number | ティック単位の持続時間 | |
amplifier | number | 0 | 効果のレベル(0 = レベルI) |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("slow", 200) then return end
context.player:apply_potion_effect("SLOWNESS", 60, 1)
context.player:send_message("&7You feel sluggish...")
end
}
remove_potion_effect(effect)はEliteMobsのLuaパワーでは利用できません。これはMagmacore/FMMにのみ存在します。回避策として、持続時間0でapply_potion_effectを使用するか、効果を削除する必要がないようにパワーを設計してください。
entity:deal_damage(amount) / entity:deal_custom_damage(amount) / entity:deal_damage_from_boss(amount)
エンティティにダメージを与えます。3つのバリアントが利用できます。
| メソッド | 備考 |
|---|---|
deal_damage(amount) | 汎用のダメージソース |
deal_custom_damage(amount) | ボスのBossCustomAttackDamageを使用します |
deal_damage_from_boss(amount) | ボスエンティティがダメージを与えた者として設定されます |
例
return {
api_version = 1,
on_enter_combat = function(context)
local nearby = context.players:nearby_players(10)
for _, p in ipairs(nearby) do
p:deal_custom_damage(10)
p:send_message("&cThe boss unleashes a shockwave!")
end
end
}
entity:restore_health(amount)
エンティティを最大体力まで回復させます。
| パラメータ | 型 | 備考 |
|---|---|---|
amount | number | 回復量 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
-- Heal the player slightly when they hit the boss
context.player:restore_health(5)
context.player:send_message("&aYou drain life from the boss!")
end
}
entity:set_invulnerable(enabled[, duration])
エンティティの無敵状態を切り替えます。オプションで持続時間後に元に戻します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
enabled | boolean | 無敵を有効にする場合true | |
duration | number | 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("shield", 200) then return end
context.player:set_invulnerable(true, 40)
context.player:send_message("&6A brief shield protects you!")
end
}
entity:set_ai_enabled(enabled[, duration])
エンティティのAIを切り替えます。オプションで持続時間後に元に戻します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
enabled | boolean | AIを有効にする場合true | |
duration | number | nil | これだけのティック数の後に自動で元に戻す |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Disable boss AI for 3 seconds at combat start
context.boss:set_ai_enabled(false, 60)
context.boss:send_message("&7The boss is stunned!")
end
}
entity:add_tag(tag[, duration]) / entity:remove_tag(tag) / entity:has_tag(tag)
エンティティのタグを管理します。タグはEliteMobsによって追跡され、エンティティの存続期間中保持されます。
| メソッド | パラメータ | 備考 |
|---|---|---|
add_tag(tag[, duration]) | string、オプションのnumber | タグを追加し、オプションでティック後に自動削除します |
remove_tag(tag) | string | タグを削除します |
has_tag(tag) | string | タグが存在する場合trueを返します |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.player:has_tag("marked") then
context.player:add_tag("marked", 200)
context.player:send_message("&cYou have been marked!")
end
end
}
entity:run_command(command)
エンティティにコマンドを実行させます。プレイヤーの場合はそのプレイヤーとして実行されます。コマンドテキストには先頭の/を付けないでください。
| パラメータ | 型 | 備考 |
|---|---|---|
command | string | 先頭の/なしのコマンドテキスト |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("curse_cmd", 200) then return end
context.player:run_command("say I have been cursed!")
end
}
entity:set_scale(scale[, duration])
エンティティのgeneric_scale属性を設定します。オプションで持続時間後に1.0に戻します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
scale | number | スケール倍率 | |
duration | number | nil | これだけのティック数の後に自動で元に戻す |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Boss grows to double size for 5 seconds
context.boss:set_scale(2.0, 100)
context.boss:send_message("&4The boss grows in size!")
end
}
entity:set_gravity(enabled)
エンティティの重力を切り替えます。
| パラメータ | 型 | 備考 |
|---|---|---|
enabled | boolean | 通常の重力の場合true |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("levitate", 200) then return end
-- Disable player gravity briefly and re-enable after 3 seconds
local player = context.player
player:set_gravity(false)
player:send_message("&dYou begin to float!")
context.scheduler:run_after(60, function()
if player:is_alive() then
player:set_gravity(true)
end
end)
end
}
entity:play_sound_at_entity(sound[, volume][, pitch])
エンティティの位置でサウンドを再生します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
sound | string | Minecraftのサウンドキー(例:"entity.ender_dragon.growl") | |
volume | number | 1.0 | 音量 |
pitch | number | 1.0 | ピッチ |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:play_sound_at_entity("entity.ender_dragon.growl", 1.0, 0.5)
end
}
entity:play_sound_at_self(sound[, volume][, pitch])
play_sound_at_entityのエイリアスです。エンティティの位置でサウンドを再生します。
entity:spawn_particle_at_self(particleOrSpec[, count])
エンティティの位置にパーティクルを生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
particleOrSpec | stringまたはtable | パーティクル名または仕様テーブル | |
count | number | 1 | パーティクルの数 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:spawn_particle_at_self("HEART", 5)
end
}
entity:spawn_particles_at_location(location, particle[, count])
特定の位置にパーティクルを生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 対象位置 | |
particle | string | パーティクルタイプ名 | |
count | number | 1 | パーティクルの数 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local loc = context.player:get_location()
context.player:spawn_particles_at_location(loc, "FLAME", 10)
end
}
entity:play_model_animation(name)
エンティティがそれをサポートするカスタムモデルを持っている場合、カスタムモデルアニメーションを再生します。
| パラメータ | 型 | 備考 |
|---|---|---|
name | string | アニメーション名 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.boss:play_model_animation("attack_swing")
end
}
乗り物および搭乗者メソッド
リビングエンティティラッパーは、Bukkitの乗り物/搭乗者ヘルパーも公開します。これらは、スクリプト化されたマウント、一時的な騎乗エフェクト、エンティティがすでに別のエンティティに取り付けられているかどうかのチェックに便利です。
| メソッド | 戻り値 | 備考 |
|---|---|---|
entity:is_inside_vehicle() | boolean | エンティティが別のエンティティに乗っている場合true。 |
entity:has_vehicle() | boolean | エンティティが現在乗り物を持っている場合true。 |
entity:get_vehicle() | エンティティラッパーまたはnil | 現在の乗り物ラッパーを返します。 |
entity:set_vehicle(vehicle) | boolean | このエンティティをvehicleに乗せます。 |
entity:leave_vehicle() | boolean | このエンティティを現在の乗り物から降ろします。 |
entity:has_passengers() | boolean | このエンティティに搭乗者がいる場合true。 |
entity:get_passenger_count() | number | 搭乗者の数。 |
entity:get_passengers() | table | 搭乗者ラッパーの配列。 |
entity:add_passenger(passenger) | boolean | このエンティティに搭乗者を追加します。 |
entity:remove_passenger(passenger) | boolean | このエンティティから搭乗者を削除します。 |
entity:eject_passengers() | boolean | すべての搭乗者を排出します。 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if context.player:has_vehicle() then
context.player:leave_vehicle()
end
end
}
entity:push_relative_to(source[, strength][, xOffset][, yOffset][, zOffset])
ソースの位置またはエンティティラッパーからエンティティを押し離します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
source | locationまたはラッパー | 押し出しの起点 | |
strength | number | 1.0 | 押し出しの強さ倍率 |
xOffset | number | 0 | 追加のXオフセット |
yOffset | number | 0 | 追加のYオフセット |
zOffset | number | 0 | 追加の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("knockback", 60) then return end
context.player:push_relative_to(context.boss:get_location(), 2.0, 0, 0.5, 0)
context.player:send_message("&cThe boss knocks you back!")
end
}
entity:set_custom_name(name) / entity:reset_custom_name()
エンティティのカスタム表示名を設定またはリセットします。カラーコードをサポートします。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("mark", 200) then return end
local player = context.player
player:set_custom_name("&c&lMarked Target")
player:send_message("&cYou have been marked!")
-- Reset after 5 seconds
context.scheduler:run_after(100, function()
if player:is_alive() then
player:reset_custom_name()
end
end)
end
}
entity:place_temporary_block(material[, duration][, requireAir])
エンティティの現在の位置に一時的なブロックを設置します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
material | string | ブロックのマテリアル名 | |
duration | number | 0 | 削除までのティック数 |
requireAir | boolean | false | ブロックが現在空気の場合のみ設置する |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("ice_trap", 200) then return end
context.player:place_temporary_block("ICE", 60, true)
context.player:send_message("&bIce forms at your feet!")
end
}
entity:get_height()
エンティティの高さをブロック単位で返します。
entity:is_on_ground()
エンティティが現在固い地面の上に立っている場合にtrueを返します。
entity:is_frozen()
エンティティ(カスタムボスとして追跡されている場合)に凍結フラグが設定されている場合にtrueを返します。
entity:set_awareness_enabled(aware[, duration])
Mobの認識を切り替えます。Mobタイプのエンティティにのみ影響します。オプションで持続時間後に元に戻します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
aware | boolean | 認識を有効にする場合true | |
duration | number | nil | これだけのティック数の後に自動で元に戻す |
entity:is_healing() / entity:set_healing(enabled)
エリートエンティティの回復状態をチェックまたは切り替えます。
entity:overlaps_box_at_location(center[, halfX][, halfY][, halfZ])
エンティティのバウンディングボックスが、指定した位置にある軸並行ボックスと重なる場合にtrueを返します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
center | locationテーブル | テストボックスの中心 | |
halfX | number | 0.5 | X軸の半幅 |
halfY | number | halfXと同じ | Y軸の半分の高さ |
halfZ | number | halfXと同じ | Z軸の半幅 |
entity:remove_elite()
エリートエンティティをEliteMobsの追跡から削除します。エンティティがエリートの場合、これによりEliteMobsを通じて適切にデスポーンします。
entity:set_custom_name_visible(visible)
エンティティのカスタム名を常に表示するか、見たときのみ表示するかを設定します。
| パラメータ | 型 | 備考 |
|---|---|---|
visible | boolean | 常に表示する場合true |
entity:set_equipment(slot, material[, options])
エンティティに装備を設定します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
slot | string | 装備スロット:"HEAD"、"CHEST"、"LEGS"、"FEET"、"HAND"、"OFF_HAND" | |
material | string | マテリアル名(例:"DIAMOND_SWORD"、"IRON_HELMET") | |
options | table | {} | オプション設定(下記参照) |
Optionsテーブル:
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
enchantments | テーブルの配列 | nil | 各エントリ:{ type = "SHARPNESS", level = 2 } |
unbreakable | boolean | false | アイテムが壊れないかどうか |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Give the boss a glowing diamond sword
context.boss:set_equipment("HAND", "DIAMOND_SWORD", {
unbreakable = true,
enchantments = {
{ type = "SHARPNESS", level = 5 }
}
})
end
}
entity:is_ai_enabled()
エンティティが現在AIを有効にしている場合にtrueを返すメソッドです。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.boss:is_ai_enabled() then
context.log:info("Boss AI is active")
else
context.log:info("Boss AI is disabled (stunned?)")
end
end
}
非リビングエンティティの参照ラッパー
スポーンしたエンティティがLivingEntityでない場合 -- 例えば落下ブロック、発射物、火の玉など -- より軽量な参照ラッパーを受け取ります。これらはcontext.world:spawn_falling_block_at_location()やcontext.boss:summon_projectile()などのメソッドによって返されます。
フィールド: name、uuid、entity_type、is_player、is_elite、current_location
メソッド:
| メソッド | 備考 |
|---|---|
is_valid() | ライブの有効性チェック |
get_location() | 現在のライブ位置 |
get_velocity() | 現在の速度ベクトル |
is_on_ground() | 地面の上にいるかどうか |
teleport_to_location(location) | エンティティをテレポートします |
set_velocity_vector(vector) | 速度を設定します |
set_direction_vector(vector) | 方向を設定します(火の玉のみ) |
set_yield(value) | 爆発の威力を設定します(火の玉のみ) |
set_gravity(enabled) | 重力を切り替えます |
detonate() | 花火エンティティを起爆します |
remove() | ワールドからエンティティを削除します |
unregister([reason]) | エンティティトラッカーから登録解除します |
例
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", 100) then return end
local fb = context.boss:summon_projectile("FIREBALL",
context.boss:get_eye_location(),
context.player:get_location(),
1.5
)
-- fb is a non-living reference wrapper; remove it after 5 seconds if still alive
context.scheduler:run_after(100, function()
if fb:is_valid() then
fb:remove()
end
end)
end
}
context.player
プレイヤーが直接関与するフック(on_boss_damaged_by_player、on_player_damaged_by_bossなど)で利用できます。プレイヤーラッパーには、上記にリストされたすべての共通エンティティフィールドとメソッドに加えて、以下の追加項目が含まれます。
context.playerは、on_spawn、スケジュールされたコールバック、タイマーフックなど、関連するプレイヤーがいないフックではnilになります。使用する前に必ずnilガードを行ってください。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.player:send_message("&cHello!")
end
}
プレイヤー専用フィールド
| フィールド | 型 | 備考 |
|---|---|---|
game_mode | string | 現在のゲームモード名(例:"SURVIVAL") |
プレイヤー専用メソッド
| メソッド | 備考 |
|---|---|
send_message(message) | EliteMobsのカラーフォーマット付きチャットメッセージ |
show_action_bar(message) | アクションバーテキスト |
show_title(title[, subtitle][, fadeIn][, stay][, fadeOut]) | タイトル画面オーバーレイ |
show_boss_bar(title[, color][, style][, duration]) | 一時的なボスバー |
run_command(command) | プレイヤーとしてコマンドを実行します(先頭の/なし) |
例
return {
api_version = 1,
on_player_damaged_by_boss = function(context)
if context.player == nil then return end
local hp_pct = context.player:get_health() / context.player:get_maximum_health()
if hp_pct < 0.3 then
context.player:show_title("&4LOW HEALTH", "&7Find cover!", 5, 30, 10)
context.player:show_boss_bar("&cBoss Enrage Incoming", "RED", "SEGMENTED_6", 80)
end
end
}
context.boss
このLuaパワーを所有するエリートMobのボスラッパーです。すべてのフックで常に利用できます。
ボスラッパーは、上記にリストされたすべての共通エンティティメソッド(例:push_relative_to、apply_push_vector、set_gravity、set_scale、set_invulnerable、spawn_particle_at_self、overlaps_box_at_locationなど)を継承します。このセクションで説明するメソッドは、ボス固有のものか、EliteEntityレイヤーを通じて異なる動作をするものです。
ボスフィールド
| フィールド | 型 | 備考 |
|---|---|---|
boss.name | string | 表示名 |
boss.uuid | string | ボスエリートのUUID |
boss.entity_type | string | BukkitのEntityType名 |
boss.is_monster | boolean | 基盤となるエンティティがMonsterの場合true |
boss.level | number | エリートレベル |
boss.health | number | 現在の体力(スナップショット) |
boss.maximum_health | number | 最大体力(スナップショット) |
boss.damager_count | number | ダメージを与えた者の数(スナップショット) |
boss.is_in_combat | boolean | 戦闘状態 |
boss.exists | boolean | エリートがまだ存在するかどうか |
boss.current_location | locationテーブル | ラッパー作成時の位置(スナップショット) |
例
return {
api_version = 1,
on_spawn = function(context)
context.log:info(context.boss.name .. " level " .. context.boss.level)
end
}
ボスメソッド
boss:is_alive()
ボスエンティティが有効で、死亡しておらず、エリートがまだ存在する場合にtrueを返します。ライブチェックにはexistsフィールドの代わりにこれを使用してください。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if not context.boss:is_alive() then return end
context.boss:send_message("&cI still live!")
end
}
boss:get_location()
ボスの現在のライブ位置をlocationテーブルとして返します。
例
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
context.world:spawn_particle_at_location(loc, "FLAME")
end
}
boss:get_eye_location()
ボスの目線の高さの位置を返します。
例
return {
api_version = 1,
on_enter_combat = function(context)
local eye = context.boss:get_eye_location()
context.world:spawn_particle_at_location(eye, "SMOKE")
end
}
boss:set_ai_enabled(enabled[, duration])
ボスのAIを切り替えます。オプションで持続時間後に元に戻します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
enabled | boolean | AIを有効にする場合true | |
duration | number | nil | これだけのティック数の後に自動で元に戻す |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if not context.cooldowns:check_local("stun", 200) then return end
context.boss:set_ai_enabled(false, 60)
context.boss:send_message("&7The boss is stunned for 3 seconds!")
end
}
boss:teleport_to_location(location)
ボスを指定した位置にテレポートします。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 目的地 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if not context.cooldowns:check_local("retreat", 300) then return end
local spawn = context.entities:get_boss_spawn_location()
context.boss:teleport_to_location(spawn)
context.boss:send_message("&7The boss retreats to its lair!")
end
}
boss:set_velocity_vector(vector)
ボスの速度を即座に設定します。
| パラメータ | 型 | 備考 |
|---|---|---|
vector | vectorテーブル | { x, y, z }または{ x = 0, y = 1, z = 0 } |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Boss leaps into the air at combat start
context.boss:set_velocity_vector({ x = 0, y = 2.0, z = 0 })
context.boss:send_message("&cThe boss leaps!")
end
}
boss:restore_health(amount)
ボスを最大体力まで回復させます。
| パラメータ | 型 | 備考 |
|---|---|---|
amount | number | 回復量 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if not context.cooldowns:check_local("heal", 200) then return end
context.boss:restore_health(20)
context.boss:send_message("&aThe boss regenerates!")
context.boss:spawn_particle_at_self("HEART")
end
}
boss:play_sound_at_self(sound[, volume][, pitch])
ボスの位置でサウンドを再生します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
sound | string | Minecraftのサウンドキー(例:"entity.wither.spawn") | |
volume | number | 1.0 | 音量 |
pitch | number | 1.0 | ピッチ |
例
return {
api_version = 1,
on_spawn = function(context)
context.boss:play_sound_at_self("entity.wither.spawn", 1.0, 0.8)
end
}
boss:spawn_particle_at_self(particleOrSpec[, count])
ボスの位置にパーティクルを生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
particleOrSpec | stringまたはtable | パーティクル名または仕様テーブル | |
count | number | 1 | パーティクルの数 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.boss:spawn_particle_at_self("SMOKE", 20)
context.boss:send_message("&8Smoke billows from the boss!")
end
}
boss:play_model_animation(name)
利用可能な場合、ボスでカスタムモデルアニメーションを再生します。
| パラメータ | 型 | 備考 |
|---|---|---|
name | string | アニメーション名 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.boss:play_model_animation("slam")
end
}
boss:has_mount() / boss:get_mount()
このボスが現在乗っているエンティティをチェックまたは返します。boss:get_mount()は、ボスがマウントを持っていない場合にnilを返します。マウントが返された場合、そのラッパーにはis_mount = trueが設定されています。
例
return {
api_version = 1,
on_enter_combat = function(context)
local mount = context.boss:get_mount()
if mount ~= nil then
context.log:info("Boss is mounted on " .. mount.entity_type)
end
end
}
boss:set_mount(entity) / boss:clear_mount() / boss:dismount()
ボスを乗せるか降ろします。boss:set_mount(entity)は、ボスを指定したエンティティラッパーに乗せ、Bukkitが搭乗者の変更を受け入れた場合にtrueを返します。boss:clear_mount()とboss:dismount()はどちらも、ボスを現在の乗り物から降ろします。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if not context.cooldowns:check_local("mount_check", 100) then return end
if context.boss:has_mount() then
context.boss:dismount()
end
end
}
boss:face_direction_or_location(vectorOrLocation)
ボスを方向または位置の方を向かせます。
| パラメータ | 型 | 備考 |
|---|---|---|
vectorOrLocation | vectorまたはlocationテーブル | 向く方向 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
context.boss:face_direction_or_location(context.player:get_location())
end
}
boss:navigate_to_location(location[, speed][, follow][, timeout])
パスファインディングを使用して、ボスを指定した位置まで歩かせます。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 目的地 | |
speed | number | 1.0 | 移動速度倍率 |
follow | boolean | false | ターゲットを継続的に追従する |
timeout | number | 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("charge", 200) then return end
context.boss:navigate_to_location(context.player:get_location(), 1.5)
context.boss:send_message("&cThe boss charges at you!")
end
}
boss:add_tag(tag[, duration]) / boss:remove_tag(tag) / boss:has_tag(tag)
ボスのタグを管理します。
例
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("phase2") then
context.boss:add_tag("phase2")
context.boss:send_message("&4Entering Phase 2!")
end
end
}
boss:send_message(message[, range])
近くのすべてのプレイヤーにチャットメッセージを送信します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
message | string | カラーコード付きのメッセージテキスト | |
range | number | 20 | ブロック単位の半径 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.boss:send_message("&4You dare challenge me?!")
end
}
boss:summon_projectile(entityType, origin, destination[, speed][, options])
ボスから発射物のようなエンティティを発射します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
entityType | string | エンティティタイプ(例:"FIREBALL"、"ARROW") | |
origin | locationテーブル | 発射位置 | |
destination | locationテーブル | 目標位置 | |
speed | number | 1.0 | 発射物の速度 |
options | table | {} | 下記のオプションを参照 |
Optionsテーブル:
| キー | 型 | 備考 |
|---|---|---|
duration | number | ティック後に自動削除する |
max_ticks | number | 着地を監視する最大ティック数 |
custom_damage | number | 着弾時のダメージ |
detonation_power | string | 着弾時の爆発の威力 |
yield | number | 爆発の威力(火の玉) |
persistent | boolean | 発射物が永続するかどうか(デフォルトtrue) |
effect | string | スポーン時に再生するEntityEffect名 |
incendiary | boolean | 爆発が焼夷性かどうか |
gravity | boolean | 発射物に重力があるかどうか |
glowing | boolean | 発光エフェクト |
invulnerable | boolean | 発射物が無敵かどうか |
track | boolean | ターゲットを追跡するかどうか |
spawn_at_origin | boolean | オフセットの代わりに起点でスポーンする |
direction_only | boolean | 方向のみを使用し、ターゲットを無視する |
on_land | function | コールバック (landing_location, spawned_entity) |
例
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", 100) then return end
context.boss:summon_projectile(
"FIREBALL",
context.boss:get_eye_location(),
context.player:get_location(),
1.5,
{
custom_damage = 10,
on_land = function(loc, entity)
context.world:spawn_particle_at_location(loc, "EXPLOSION")
end
}
)
end
}
boss:summon_reinforcement(filename[, zoneOrLocation][, level])
設定ファイルから増援ボスを召喚します。
| パラメータ | 型 | 備考 |
|---|---|---|
filename | string | ボス設定ファイル名 |
zoneOrLocation | locationテーブルまたはゾーン | オプションのスポーン位置またはゾーン定義。デフォルトはボスの位置。 |
level | number | オプションの増援レベル。デフォルトは0で、召喚ヘルパーが通常通りレベルを継承/解決できるようにします。 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.boss:summon_reinforcement("my_minion.yml", context.boss:get_location(), 0)
context.boss:send_message("&cMinions, come to my aid!")
end
}
boss:despawn()
ボスをワールドから削除します。
例
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.1 then
context.boss:send_message("&7The boss vanishes into thin air!")
context.boss:despawn()
end
end
}
boss:get_nearby_players(range)
ボスの範囲内にいるプレイヤーラッパーの配列を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
range | number | ブロック単位の半径 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local players = context.boss:get_nearby_players(30)
for _, p in ipairs(players) do
p:show_action_bar("&cThe boss sees you!")
end
end
}
boss:get_damager_count()
このボスにダメージを与えたプレイヤーのライブな数を返します。damager_countフィールドとは異なり、これはライブチェックを実行します。
boss:get_target_player()
ボスの現在のMobターゲットをプレイヤーラッパーとして返します。ターゲットがプレイヤーでない場合や未設定の場合はnilを返します。
ゾーンおよびパーティクルメソッド
これらのメソッドはゾーンとパーティクルエフェクトを組み合わせます。入力としてゾーンテーブルが必要です。
boss:get_nearby_players_in_zone(zone)
指定したゾーンの内部に現在いるすべてのプレイヤーのプレイヤーラッパーの配列を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
zone | zoneテーブル | ゾーン形状の定義 |
boss:spawn_particles_in_zone(zone, particle, ..., coverage?)
ゾーンの内部をパーティクルで満たします。
| パラメータ | 型 | 備考 |
|---|---|---|
zone | zoneテーブル | 満たすゾーン形状 |
particle | string | パーティクルタイプ名 |
... | 追加のパーティクルパラメータ | |
coverage | number(オプション) | パーティクル密度のカバー率係数 |
boss:spawn_particles_in_zone_border(zone, particle, ..., coverage?)
ゾーンの境界をパーティクルで縁取ります。
| パラメータ | 型 | 備考 |
|---|---|---|
zone | zoneテーブル | 縁取るゾーン形状 |
particle | string | パーティクルタイプ名 |
... | 追加のパーティクルパラメータ | |
coverage | number(オプション) | パーティクル密度のカバー率係数 |
boss:get_particles_from_self_toward_zone(zone, particle, speed?)
ボスからゾーンに向かって進む指向性パーティクルを生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
zone | zoneテーブル | 対象ゾーン | |
particle | string | パーティクルタイプ名 | |
speed | number | nil | パーティクルの移動速度 |
boss:get_particles_toward_self(zone, particle, speed?)
ゾーンからボスに向かって進む指向性パーティクルを生成します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
zone | zoneテーブル | ソースゾーン | |
particle | string | パーティクルタイプ名 | |
speed | number | nil | パーティクルの移動速度 |
boss:spawn_particles_with_vector(particles)
それぞれが独自の位置と速度ベクトルを持つ指向性パーティクルの配列を生成します。
| パラメータ | 型 | 備考 |
|---|---|---|
particles | テーブルの配列 | 各エントリが位置と方向を持つパーティクルを定義します |
エンダードラゴンメソッド
これらのメソッドは、ボスエンティティがエンダードラゴンの場合にのみ適用されます。
boss:get_ender_dragon_phase()
現在のEnderDragon.Phase名を文字列として返します。ボスがエンダードラゴンでない場合はnilを返します。
boss:set_ender_dragon_phase(phase)
エンダードラゴンのフェーズを設定します。
| パラメータ | 型 | 備考 |
|---|---|---|
phase | string | EnderDragon.Phase名(例:"CIRCLING"、"CHARGE_PLAYER") |
特殊パワーサポートメソッド
これらのメソッドは、Luaスクリプトから組み込みのEliteMobsパワーメカニクスをサポートします。
boss:start_tracking_fireball_system(speed?)
ボスで追跡火の玉AIシステムを開始します。ボスは定期的に、そのターゲットを追跡する火の玉を発射します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
speed | number | 0.5 | 火の玉の速度 |
boss:handle_spirit_walk_damage(cause)
指定したダメージ原因に対してスピリットウォークの動作を処理します。スピリットウォークは、ボスを特定のダメージタイプに対して無敵にし、攻撃者の背後にテレポートさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
cause | string | BukkitのDamageCause名(例:"ENTITY_ATTACK"、"PROJECTILE") |
boss:shield_wall_is_active()
ボスが現在アクティブなシールドウォールを持っている場合にtrueを返します。
boss:initialize_shield_wall(charges?)
受けるダメージを吸収できるシールドウォールをボスで起動します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
charges | number | 1 | シールドが吸収できる攻撃回数 |
boss:shield_wall_absorb_damage(player, damage)
シールドウォールでダメージを吸収しようとします。ダメージが吸収された場合はtrueを、シールドが非アクティブまたは枯渇している場合はfalseを返します。
| パラメータ | 型 | 備考 |
|---|---|---|
player | プレイヤーラッパー | 攻撃しているプレイヤー |
damage | number | 吸収するダメージ量 |
boss:deactivate_shield_wall()
ボスのシールドウォールを非アクティブにし、残っているチャージをすべて削除します。
boss:start_zombie_necronomicon(target, file)
ターゲットに対してゾンビネクロノミコンパワーを開始し、設定ファイルからアンデッドの増援をスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
target | エンティティラッパー | ネクロノミコンの対象エンティティ |
file | string | 召喚するアンデッドのボス設定ファイル名 |
context.players
ボスを中心としたプレイヤークエリヘルパーです。イベントから特定のプレイヤーを必要とせずにプレイヤーを見つけるために使用します。
| メソッド | 戻り値 | 備考 |
|---|---|---|
players:current_target() | プレイヤーラッパーまたはnil | イベントプレイヤー、またはボスのMobターゲットがプレイヤーの場合はそれ |
players:nearby_players(radius) | プレイヤーラッパーの配列 | ボスの半径内のすべてのプレイヤー |
players:all_players_in_world() | プレイヤーラッパーの配列 | ボスのワールド内のすべてのプレイヤー |
例
return {
api_version = 1,
on_enter_combat = function(context)
local nearby = context.players:nearby_players(20)
for _, player in ipairs(nearby) do
player:send_message("&cThe boss is enraged!")
player:apply_potion_effect("GLOWING", 60, 0)
end
end
}
例
return {
api_version = 1,
on_spawn = function(context)
-- Warn everyone in the world
local everyone = context.players:all_players_in_world()
for _, p in ipairs(everyone) do
p:show_title("&4WARNING", "&7A world boss has spawned!", 10, 60, 20)
end
end
}
context.entities
ボスを中心とした汎用のエンティティクエリヘルパーです。
| メソッド | 戻り値 | 備考 |
|---|---|---|
entities:get_nearby_entities(radius[, filter]) | エンティティラッパーの配列 | ボスの周囲の近くのエンティティ |
entities:get_entities_in_box(center, halfX, halfY, halfZ[, filter]) | エンティティラッパーの配列 | 軸並行ボックス内のエンティティ |
entities:get_all_entities([filter]) | エンティティラッパーの配列 | ボスのワールド内のすべての一致するエンティティ |
entities:get_direct_target_entity() | エンティティラッパーまたはnil | 現在のイベントのダイレクトターゲット |
entities:get_boss_spawn_location() | locationテーブル | ボスの元のスポーン位置 |
有効なフィルター: living(デフォルト)、player / players、elite / elites、mob / mobs、all / entities
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Damage all nearby elites
local elites = context.entities:get_nearby_entities(10, "elites")
for _, elite in ipairs(elites) do
elite:deal_damage(5)
end
end
}
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Find players in a box area
local center = context.boss:get_location()
local players = context.entities:get_entities_in_box(center, 10, 5, 10, "players")
for _, p in ipairs(players) do
p:send_message("&eYou are in the danger zone!")
end
end
}
次のステップ
- はじめに | フックとライフサイクル | ワールドと環境 | ゾーンとターゲティング | 例 | 列挙型 | トラブルシューティング
- APIリファレンス | スクリプティングエンジン
