Zum Hauptinhalt springen

Lua-Scripting: Welt & Umgebung

webapp_banner.jpg

Diese Seite behandelt sämtliche Methoden, die auf context.world, context.vectors, context.settings und context.event verfügbar sind. Damit können deine Lua-Kräfte mit der Minecraft-Welt interagieren -- Entitäten spawnen, Effekte abspielen, Blöcke abfragen und mehr. Wenn du neu bei Lua-Kräften bist, beginne zuerst mit Erste Schritte.

EliteMobs boss context

EliteMobs-Bosskräfte verwenden die Lua-Sandbox von MagmaCore wieder. Das context.world eines Bosses geht von der gemeinsamen MagmaCore-Welttabelle aus, sodass allgemeine Koordinaten-Helfer wie get_block_at(...), set_block_at(...) und spawn_particle(...) weiterhin verfügbar sind. Diese Seite konzentriert sich auf die bossspezifischen Ergänzungen und Überschreibungen von EliteMobs für context.world, context.vectors, context.settings und context.event. Die allgemeine Welt-API findest du unter MagmaCore Lua Scripting Engine.


context.world

Die Welttabelle stellt Methoden bereit, um Entitäten zu spawnen, Effekte abzuspielen, Blöcke zu verändern und den Weltzustand zu ändern. Alle Methoden werden mit der Doppelpunkt-Syntax aufgerufen (world:method()).


world:spawn_particle_at_location(location, particleSpec)

Erzeugt Partikel an einer Position. Das zweite Argument kann ein einfacher Partikelname als Zeichenkette oder eine vollständige Partikel-Spezifikationstabelle für erweiterte Kontrolle sein.

ParameterTypHinweise
locationLocation-TabelleWo die Partikel erzeugt werden
particleSpecZeichenkette oder TabellePartikelname oder eine Partikel-Spezifikationstabelle (siehe unten)
Beispiel
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
}

Format der Partikel-Spezifikationstabelle

SchlüsselTypStandardHinweise
particleZeichenketteerforderlichPartikelname
amountint1Anzahl der Partikel
x, y, zZahl0Streuung/Versatz je Achse
speedZahl0Partikelgeschwindigkeit
red, green, blueint255RGB-Farbe für DUST und DUST_COLOR_TRANSITION
toRed, toGreen, toBlueint255Zielfarbe des Übergangs für DUST_COLOR_TRANSITION
Tipp

Für DUST_COLOR_TRANSITION kannst du auch snake_case-Schlüssel verwenden: to_red, to_green, to_blue.

Warnung

Anders als bei EliteScript-YAML-Konfigurationen unterstützen Lua-Partikelnamen keine Umwandlung alter Partikelnamen. Du musst die aktuellen Namen der Spigot-API verwenden (z. B. FIREWORK statt FIREWORKS_SPARK, SMOKE statt SMOKE_NORMAL, DUST statt REDSTONE). Die vollständige Liste der aktuellen Namen und ihrer alten Entsprechungen findest du in der Liste gültiger Partikel.


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

Spielt einen Klang an einer Position ab.

ParameterTypStandardHinweise
locationLocation-TabelleWo der Klang abgespielt wird
soundZeichenketteMinecraft-Klangschlüssel (z. B. "entity.blaze.shoot") oder ein Spigot-Sound-Enum-Name. Ressourcenpaket-Schlüssel funktionieren ebenfalls.
volumeZahl1.0Lautstärke
pitchZahl1.0Tonhöhe
Beispiel
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)

Lässt an einer Position einen Blitz einschlagen (visuell und schadensverursachend).

ParameterTypHinweise
locationLocation-TabelleWo der Blitz einschlägt
Beispiel
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)

Spawnt eine gewöhnliche Minecraft-Entität.

ParameterTypHinweise
entityTypeZeichenketteEntitätstyp-Name (z. B. "FIREBALL", "ARROW")
locationLocation-TabelleWo gespawnt wird
optionsTabelle (optional)Spawn-Optionen (siehe unten)

Spawn-Optionen für Entitäten

SchlüsselTypStandardHinweise
velocityVektortabellenilAnfangsgeschwindigkeit {x, y, z}
effectZeichenkettenilEntityEffect, der beim Spawnen abgespielt wird
durationint0Nach so vielen Ticks automatisch entfernen (0 = nie)
on_landFunktionnilRückruf, wenn die Entität auf dem Boden landet
max_ticksint6000Maximale Anzahl an Ticks zur Überwachung, bevor der on_land-Rückruf erzwungen wird

Gibt eine Entitäts-Wrappertabelle zurück. Nicht-lebende Entitäten (FIREBALL, ARROW, TNT, ...) kommen als Referenz-Wrapper für nicht-lebende Entitäten zurück, bei denen is_valid() eine Methode ist. Lebende Entitätstypen (ZOMBIE, GIANT, ...) kommen stattdessen als vollwertiger Wrapper für lebende Entitäten zurück, bei dem is_valid ein boolesches Feld ist -- ein Aufruf von entity:is_valid() auf einem solchen Wrapper löst attempt to call a boolean value aus.

Beispiel
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
}
Beispiel
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)

Spawnt eine fallende Block-Entität.

ParameterTypHinweise
locationLocation-TabelleWo gespawnt wird
materialZeichenketteMaterialname (z. B. "STONE", "MAGMA_BLOCK")
optionsTabelle (optional)Spawn-Optionen (siehe unten)

Optionen für fallende Blöcke

SchlüsselTypStandardHinweise
velocityVektortabellenilAnfangsgeschwindigkeit {x, y, z}
drop_itembooleanfalseOb der Block als Gegenstand fällt
hurt_entitiesbooleanfalseOb der Block Entitäten schadet, auf denen er landet
on_landFunktionnilRückruf function(land_location, entity_ref), wenn der Block landet

Gibt eine Entitätsreferenz-Tabelle zurück.

Beispiel
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)

Spawnt einen benutzerdefinierten EliteMobs-Boss aus einer Konfigurationsdatei.

ParameterTypHinweise
filenameZeichenketteDateiname der Boss-Konfiguration (z. B. "my_boss.yml")
locationLocation-TabelleWo gespawnt wird
optionsTabelle (optional)Spawn-Optionen (siehe unten)

Spawn-Optionen für benutzerdefinierte Bosse

SchlüsselTypStandardHinweise
levelintBosslevelÜberschreibt das Level des gespawnten Bosses
silentbooleanfalseUnterdrückt Spawn-Nachrichten
velocityVektortabellenilAnfangsgeschwindigkeit
add_as_reinforcementbooleanfalseAls Verstärkung des aktuellen Bosses registrieren

Gibt eine Entitäts-Wrappertabelle zurück oder nil, falls der Boss nicht erstellt werden konnte.

Beispiel
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)

Eine einfachere Methode zum Spawnen von Bossen. Spawnt einen benutzerdefinierten Boss an einer Position mit optionalem Level.

ParameterTypStandardHinweise
filenameZeichenketteDateiname der Boss-Konfiguration
locationLocation-TabelleBosspositionWo gespawnt wird (optional, standardmäßig die Bossposition)
levelintBosslevelÜberschreibt das Spawn-Level (optional)

Gibt eine Entitäts-Wrappertabelle zurück oder nil.

Beispiel
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, level, velocity)

Spawnt eine Verstärkung, die vom Verstärkungssystem von EliteMobs verfolgt wird.

ParameterTypStandardHinweise
filenameZeichenketteDateiname der Boss-Konfiguration
locationLocation-TabelleWo gespawnt wird
levelint0Level der Verstärkung. Bei 0 bestimmt der Beschwörungs-Helfer sein Standardverhalten für das Level.
velocityVektortabellenilAnfangsgeschwindigkeit (optional)

Gibt eine Entitäts-Wrappertabelle zurück oder nil.

Beispiel
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)

Spawnt eine Feuerwerks-Entität mit voller Kontrolle über die Effekte.

ParameterTypHinweise
locationLocation-TabelleWo gespawnt wird
specTabelleFeuerwerks-Spezifikation (siehe unten)

Feuerwerks-Spezifikationstabelle

SchlüsselTypStandardHinweise
powerint1Flugkraft (Höhe)
velocityVektortabellenilAnfangsgeschwindigkeit
shot_at_anglebooleantrueOb das Feuerwerk in einem Winkel abgeschossen wird (wird verwendet, wenn velocity gesetzt ist)
effectsTabelle aus TabellennilArray von Feuerwerkseffekt-Spezifikationen. Wird sie weggelassen, gilt die oberste Spezifikation als einzelner Effekt.

Spezifikation eines Feuerwerkseffekts

SchlüsselTypStandardHinweise
typeZeichenkette"BALL_LARGE""BALL", "BALL_LARGE", "STAR", "BURST", "CREEPER"
flickerbooleantrueFunkeleffekt
trailbooleantrueSchweifeffekt
colorsTabellenilArray von Farbnamen oder {red, green, blue}-Tabellen
fade_colorsTabellenilArray von Verblassfarben-Namen oder {red, green, blue}-Tabellen

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

Gibt eine Entitätsreferenz-Tabelle zurück. Du kannst darauf :detonate() aufrufen, um die sofortige Detonation zu erzwingen.

Beispiel
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)

Spawnt eine geworfene Wurftrank-Entität.

ParameterTypHinweise
locationLocation-TabelleWo gespawnt wird
specTabelleTrank-Spezifikation (siehe unten)

Spezifikationstabelle für Wurftränke

SchlüsselTypHinweise
velocityVektortabelleAnfangsgeschwindigkeit des geworfenen Tranks
effectsTabelle aus TabellenArray von Trankeffekt-Spezifikationen

Spezifikation eines Trankeffekts

SchlüsselTypStandardHinweise
typeZeichenketteerforderlichName des Trankeffekttyps (z. B. "SLOWNESS", "POISON")
durationint0Dauer in Ticks
amplifierint0Effektverstärker (0 = Stufe I)
overwritebooleantrueOb bestehende Effekte desselben Typs überschrieben werden

Gibt eine Entitätsreferenz-Tabelle zurück oder nil.

Beispiel
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)

Platziert einen temporären Block, der nach Ablauf einer Dauer automatisch zurückgesetzt wird.

ParameterTypStandardHinweise
locationLocation-TabelleWo platziert wird
materialZeichenketteMaterialname
durationint0Ticks, bis der Block zurückgesetzt wird (0 = dauerhaft)
requireAirbooleanfalseBei true wird nur platziert, wenn der Block derzeit Luft ist
Beispiel
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)

Setzt einen Block dauerhaft. Verwende place_temporary_block_at_location, wenn er zurückgesetzt werden soll.

ParameterTypStandardHinweise
locationLocation-TabelleWo platziert wird
materialZeichenketteMaterialname
requireAirbooleanfalseBei true wird nur platziert, wenn der Block derzeit Luft ist
Beispiel
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)

Gibt den Materialnamen des Blocks an einer Position als Zeichenkette zurück.

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt die Y-Koordinate des höchsten Nicht-Luft-Blocks an der angegebenen X/Z-Position zurück.

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position (X und Z werden verwendet)
Beispiel
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)

Gibt den Explosionswiderstand des Blocks an einer Position als Zahl zurück.

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt true zurück, wenn der Block an der Position Luft ist.

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt true zurück, wenn der Block an der Position passierbar ist (Entitäten können hindurchgehen).

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt true zurück, wenn der Block an der Position nicht fest ist (ähnlich wie passierbar, aber basierend auf der Festkörper-Prüfung).

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt true zurück, wenn der Block an der Position nicht fest ist UND der Block darunter fest ist (die Position "steht" also auf dem Boden).

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
Beispiel
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)

Gibt true zurück, wenn der Block direkt unterhalb der Position dem angegebenen Material entspricht.

ParameterTypHinweise
locationLocation-TabelleAbzufragende Position
materialZeichenketteZu prüfender Materialname
Beispiel
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)

Setzt die Weltzeit. Optional kannst du eine Position übergeben, um festzulegen, welche Welt gemeint ist.

ParameterTypHinweise
locationLocation-Tabelle (optional)Welche Welt betroffen ist. Standardmäßig die Bosswelt.
timeintWeltzeit in Ticks (0 = Morgengrauen, 6000 = Mittag, 13000 = Nacht, 18000 = Mitternacht)
Beispiel
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)

Setzt das Wetter in der Bosswelt.

ParameterTypStandardHinweise
locationLocation-Tabelle (optional)BossweltWelche Welt betroffen ist
weatherZeichenkette"CLEAR", "RAIN" (oder "PRECIPITATION"), "THUNDER"
durationint6000Wetterdauer in Ticks
Beispiel
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)

Erzeugt eine visuelle Schein-Explosion über das Explosions-Regenerationssystem von EliteMobs (Blöcke zerbrechen und regenerieren sich).

ParameterTypHinweise
blockLocationsTabelle aus Location-TabellenArray von Blockpositionen, die "explodieren" sollen
sourceLocationLocation-Tabelle (optional)Explosionsquelle für Richtungsberechnungen
Beispiel
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)

Führt einen Konsolenbefehl als Server aus.

ParameterTypHinweise
commandZeichenketteDer auszuführende Befehl (ohne führenden /)
Beispiel
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)

Führt die visuelle Aufgabe für verstärkte Blitze aus (wird von Enderdrachen-Kräften genutzt). Das erzeugt einen dramatischeren Blitzeinschlag mit zusätzlichen Effekten.

ParameterTypHinweise
locationLocation-TabelleWo der Blitz einschlägt
Beispiel
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)

Spawnt ein Schein-Goldklumpen-Projektil, das vom Bullet-Hell-System verwendet wird.

ParameterTypStandardHinweise
locationLocation-TabelleSpawn-Position
velocityVektortabelleAnfangsgeschwindigkeit
hasGravitybooleanfalseOb das Projektil der Schwerkraft unterliegt

Gibt eine Schein-Projektiltabelle mit den Methoden get_location(), set_gravity(bool), remove() und is_removed() zurück.

Beispiel
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)

Verarbeitet den Schaden einer Tabelle von Schein-Goldklumpen-Projektilen gegen nahegelegene Entitäten.

ParameterTypHinweise
projectilesTabelleArray von Schein-Projektiltabellen aus spawn_fake_gold_nugget_at_location
Beispiel
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)

Erzeugt Beute für Spieler, die dem Boss Schaden zugefügt haben.

ParameterTypStandardHinweise
timesint1Anzahl der Beutewürfe
Beispiel
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)

Lässt Bonusmünzen für alle Spieler fallen, die zum Schaden am Boss beigetragen haben.

ParameterTypStandardHinweise
multiplierZahl2.0Multiplikator für die Münzmenge
Beispiel
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

Helfer für Vektorrechnung. Diese werden als gewöhnliche Funktionen aufgerufen (Punktsyntax), nicht als Methoden.

MethodeGibt zurückHinweise
vectors.get_vector_between_locations(loc1, loc2[, options])VektortabelleRichtung von loc1 nach loc2
vectors.normalize_vector(vec)VektortabelleGibt einen Vektor der Länge 1 zurück
vectors.rotate_vector(vec, pitch, yaw)VektortabelleDreht einen Vektor um Pitch- und Yaw-Grad

Alle Vektortabellen haben die Felder x, y, z.

vectors.get_vector_between_locations(loc1, loc2, options)

ParameterTypHinweise
loc1Location-TabelleStartpunkt
loc2Location-TabelleEndpunkt
optionsTabelle (optional)Optionen zur Nachbearbeitung (siehe unten)

Vektor-Optionen

SchlüsselTypStandardHinweise
normalizebooleanfalseNormalisiert den resultierenden Vektor
multiplierZahl1.0Skaliert den Vektor
offsetVektortabellenilFügt einen Versatzvektor hinzu
Beispiel
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)

ParameterTypHinweise
vecVektortabelleEingabevektor
Beispiel
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)

ParameterTypHinweise
vecVektortabelleEingabevektor
pitchZahlDrehung um die X-Achse in Grad
yawZahlDrehung um die Y-Achse in Grad
Beispiel
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
}
Tipp

Du kannst eine Streuung von Richtungen erzeugen, indem du einen Basisvektor in einer Schleife drehst:

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

Nur-Lese-Zugriff auf kraftbezogene Konfigurationswerte.

MethodeGibt zurückHinweise
settings:warning_visual_effects_enabled()booleanOb visuelle Warneffekte in den Mob-Kampfeinstellungen aktiviert sind
Beispiel
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

Ereignisdaten für den aktuellen Hook. Welche Felder verfügbar sind, hängt davon ab, welcher Hook den Aufruf ausgelöst hat.

Feld oder MethodeVerfügbar beiHinweise
event.damage_amountSchadens-HooksDer aktuelle Schadenswert (Momentaufnahme zum Zeitpunkt des Aufrufs)
event.damage_causeSchadens-HooksName des Bukkit-DamageCause-Enums (z. B. "ENTITY_ATTACK")
event.cancel_event()Abbrechbare EreignisseBricht das Ereignis ab
event.set_damage_amount(value)Hooks auf Basis von EliteDamageEventSetzt den Schaden direkt
event.multiply_damage_amount(multiplier)Hooks auf Basis von EliteDamageEventMultipliziert den aktuellen Schaden
event.damagerSchadensereignisse mit einer schädigenden EntitätEntitätsreferenz-Wrapper für den Schadensverursacher
event.projectileSchadensereignisse, bei denen der Verursacher ein Projektil istEntitätsreferenz-Wrapper des Projektils
event.spawn_reasonon_spawnName des Spawn-Grund-Enums
event.entityon_death, ZonenereignisseDer betreffende Entitäts-Wrapper

Beispiel: Eingehenden Schaden halbieren

Beispiel
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
}

Beispiel: Schaden von Projektilen abbrechen

Beispiel
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
}

Beispiel: Schadensursache auslesen

Beispiel
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
}
Hinweis
  • damage_amount ist eine Momentaufnahme. Der Wert wird nach dem Aufruf von set_damage_amount() oder multiply_damage_amount() nicht automatisch aktualisiert.
  • Innerhalb geplanter Rückrufe ist context.event gleich nil. Verwende Ereignis-Hooks, um Ereignisse zu verändern.

Nächste Schritte