From c9d5922ef697865a8779a350ed1005b1a220bc69 Mon Sep 17 00:00:00 2001 From: H5N3RG Date: Sat, 7 Mar 2026 12:10:34 +0000 Subject: [PATCH] Dateien nach "/" hochladen --- init.lua | 62 +++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/init.lua b/init.lua index bf5c944..fc4bc16 100644 --- a/init.lua +++ b/init.lua @@ -47,53 +47,52 @@ end -- ── Spider Ammo HUD ─────────────────────────────────────────────────────────── +-- ── Ammo HUD (text-only, keine externen Texturen noetig) ───────────────────── +-- Wir bauen den Balken aus ASCII-Zeichen: [|||||||| ] + Prozentzahl +-- Das funktioniert in jeder Minetest/Luanti-Version zuverlaessig. + +local AMMO_BAR_WIDTH = 10 -- Anzahl Segmente im Balken + +local function ammo_bar_string(ammo_pct) + local filled = math.floor((ammo_pct / 100) * AMMO_BAR_WIDTH + 0.5) + filled = math.max(0, math.min(AMMO_BAR_WIDTH, filled)) + local bar = string.rep("|", filled) .. string.rep(".", AMMO_BAR_WIDTH - filled) + return "[" .. bar .. "] " .. math.floor(ammo_pct) .. "%" +end + local function add_ammo_hud(player) if not player then return end local meta = player:get_meta() - -- Label + -- Label "PLASMA" local label_id = player:hud_add({ type = "text", position = {x = 0.5, y = 0.88}, - offset = {x = 0, y = -28}, - text = "PLASMA AMMO", + offset = {x = 0, y = -18}, + text = "PLASMA", alignment = {x = 0, y = 0}, - scale = {x = 100, y = 30}, + scale = {x = 200, y = 60}, number = 0x00FF99, }) meta:set_int("ammo_hud_label", label_id) - -- Statbar (0-20 Halbsymbole = 10 volle Symbole) + -- Balken + Prozentzahl als Text local bar_id = player:hud_add({ - type = "statbar", - position = {x = 0.5, y = 0.88}, - offset = {x = -95, y = 0}, - text = "ammo_charge.png", - text2 = "ammo_charge_empty.png", - number = 20, - item = 20, - direction = 0, - size = {x = 24, y = 24}, - }) - meta:set_int("ammo_hud_bar", bar_id) - - -- Prozentanzeige - local pct_id = player:hud_add({ type = "text", position = {x = 0.5, y = 0.88}, - offset = {x = 112, y = 0}, - text = "100%", - alignment = {x = -1, y = 0}, - scale = {x = 80, y = 20}, - number = 0xFFFFFF, + offset = {x = 0, y = 6}, + text = ammo_bar_string(100), + alignment = {x = 0, y = 0}, + scale = {x = 300, y = 60}, + number = 0x00FF99, }) - meta:set_int("ammo_hud_pct", pct_id) + meta:set_int("ammo_hud_bar", bar_id) end local function remove_ammo_hud(player) if not player then return end local meta = player:get_meta() - for _, key in ipairs({"ammo_hud_label", "ammo_hud_bar", "ammo_hud_pct"}) do + for _, key in ipairs({"ammo_hud_label", "ammo_hud_bar"}) do local id = meta:get_int(key) if id and id > 0 then player:hud_remove(id) @@ -106,15 +105,10 @@ local function update_ammo_hud(player, ammo_pct) if not player then return end local meta = player:get_meta() local bar_id = meta:get_int("ammo_hud_bar") - local pct_id = meta:get_int("ammo_hud_pct") if bar_id and bar_id > 0 then - local bar_val = math.floor((ammo_pct / 100) * 20 + 0.5) - player:hud_change(bar_id, "number", bar_val) - end - if pct_id and pct_id > 0 then local color = ammo_pct >= SPIDER_AMMO_MIN_TO_FIRE and 0x00FF99 or 0xFF4444 - player:hud_change(pct_id, "text", math.floor(ammo_pct) .. "%") - player:hud_change(pct_id, "number", color) + player:hud_change(bar_id, "text", ammo_bar_string(ammo_pct)) + player:hud_change(bar_id, "number", color) end end @@ -863,7 +857,7 @@ on_step = function(self, dtime) -- Ammo-Check: zugehoerigen mech1-Body in der Naehe suchen local mech_ent = nil local hp = self.object:get_pos() - for _, obj in ipairs(minetest.get_objects_inside_radius(hp, 2)) do + for _, obj in ipairs(minetest.get_objects_inside_radius(hp, 6)) do if not obj:is_player() then local e = obj:get_luaentity() if e and e.name == "assorted_mecha:mech1" then