Dateien nach "/" hochladen

This commit is contained in:
2026-03-07 12:16:36 +00:00
parent c9d5922ef6
commit 4ab1cb87e3
2 changed files with 16 additions and 18 deletions

4
ai.lua
View File

@@ -113,11 +113,11 @@ local function try_fire(self_ent, target_pos)
local cd = weapon == "plasma" and SHOOT_COOLDOWN_PLASMA or SHOOT_COOLDOWN_BULLET local cd = weapon == "plasma" and SHOOT_COOLDOWN_PLASMA or SHOOT_COOLDOWN_BULLET
if (now - (self_ent._ai_last_shot or 0)) < cd then return false end if (now - (self_ent._ai_last_shot or 0)) < cd then return false end
-- Spider-Ammo pruefen -- Spider ammo check
if weapon == "plasma" then if weapon == "plasma" then
local ammo = self_ent._spider_ammo or SPIDER_AMMO_MAX local ammo = self_ent._spider_ammo or SPIDER_AMMO_MAX
if ammo < SPIDER_AMMO_MIN_TO_FIRE then return false end if ammo < SPIDER_AMMO_MIN_TO_FIRE then return false end
-- Ammo verbrauchen -- Consume ammo
self_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST) self_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST)
end end

View File

@@ -45,13 +45,11 @@ local function remove_mech_scope(player)
end end
end end
-- ── Spider Ammo HUD ────────────────────────────────────────────────────────── -- ── Spider Ammo HUD ──────────────────────────────────────────────────────────
-- Text-only bar, no external textures required.
-- Renders as: [||||||....] 60% (green when enough ammo, red when empty)
-- ── Ammo HUD (text-only, keine externen Texturen noetig) ───────────────────── local AMMO_BAR_WIDTH = 10 -- number of segments in the bar
-- 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 function ammo_bar_string(ammo_pct)
local filled = math.floor((ammo_pct / 100) * AMMO_BAR_WIDTH + 0.5) local filled = math.floor((ammo_pct / 100) * AMMO_BAR_WIDTH + 0.5)
@@ -64,7 +62,7 @@ local function add_ammo_hud(player)
if not player then return end if not player then return end
local meta = player:get_meta() local meta = player:get_meta()
-- Label "PLASMA" -- Label
local label_id = player:hud_add({ local label_id = player:hud_add({
type = "text", type = "text",
position = {x = 0.5, y = 0.88}, position = {x = 0.5, y = 0.88},
@@ -76,7 +74,7 @@ local function add_ammo_hud(player)
}) })
meta:set_int("ammo_hud_label", label_id) meta:set_int("ammo_hud_label", label_id)
-- Balken + Prozentzahl als Text -- Bar + percentage as text
local bar_id = player:hud_add({ local bar_id = player:hud_add({
type = "text", type = "text",
position = {x = 0.5, y = 0.88}, position = {x = 0.5, y = 0.88},
@@ -290,7 +288,7 @@ local function register_mech(mech)
self._mech_stand_anim = mech.stand_animation self._mech_stand_anim = mech.stand_animation
self._mech_head_name = mech.head_name self._mech_head_name = mech.head_name
self._mech_name = mech.name self._mech_name = mech.name
-- Spider-Ammo initialisieren (gilt fuer alle Mechs mit head_spider) -- Initialize spider ammo (applies to all mechs using head_spider)
if mech.head_name == "assorted_mecha:head_spider" then if mech.head_name == "assorted_mecha:head_spider" then
self._spider_ammo = self._spider_ammo or SPIDER_AMMO_MAX self._spider_ammo = self._spider_ammo or SPIDER_AMMO_MAX
end end
@@ -346,7 +344,7 @@ local vel = self.object:get_velocity() or {x=0, y=0, z=0}
vel.y = vel.y - (dtime * 9.8) vel.y = vel.y - (dtime * 9.8)
self.object:set_velocity(vel) self.object:set_velocity(vel)
-- Spider-Ammo: passiver Regen (alle Mechs mit head_spider) -- Spider ammo: passive regen (all mechs using head_spider)
if mech.head_name == "assorted_mecha:head_spider" then if mech.head_name == "assorted_mecha:head_spider" then
if (self._spider_ammo or SPIDER_AMMO_MAX) < SPIDER_AMMO_MAX then if (self._spider_ammo or SPIDER_AMMO_MAX) < SPIDER_AMMO_MAX then
self._spider_ammo = math.min( self._spider_ammo = math.min(
@@ -354,7 +352,7 @@ self.object:set_velocity(vel)
(self._spider_ammo or 0) + SPIDER_AMMO_REGEN * dtime (self._spider_ammo or 0) + SPIDER_AMMO_REGEN * dtime
) )
end end
-- HUD beim Fahrer aktualisieren -- Update HUD for the current driver
if self.driver then if self.driver then
update_ammo_hud(self.driver, self._spider_ammo or SPIDER_AMMO_MAX) update_ammo_hud(self.driver, self._spider_ammo or SPIDER_AMMO_MAX)
end end
@@ -507,7 +505,7 @@ clicker:set_properties({visual_size = {x=1, y=1, z=1}})
clicker:hud_set_flags({crosshair = true, wielditem = true}) clicker:hud_set_flags({crosshair = true, wielditem = true})
clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0}) clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
clicker:get_meta():set_int("mech_third_person", 0) clicker:get_meta():set_int("mech_third_person", 0)
-- Ammo-HUD entfernen (nur Spider) -- Remove ammo HUD on dismount (spider only)
if mech.head_name == "assorted_mecha:head_spider" then if mech.head_name == "assorted_mecha:head_spider" then
remove_ammo_hud(clicker) remove_ammo_hud(clicker)
end end
@@ -542,7 +540,7 @@ clicker:set_properties({visual_size = {x=1, y=1, z=1}})
-- Scope overlay replaces crosshair; hide ingame crosshair & wielditem -- Scope overlay replaces crosshair; hide ingame crosshair & wielditem
clicker:hud_set_flags({crosshair = false, wielditem = false}) clicker:hud_set_flags({crosshair = false, wielditem = false})
clicker:get_meta():set_int("mech_third_person", 0) clicker:get_meta():set_int("mech_third_person", 0)
-- Ammo-HUD anzeigen (nur Spider) -- Show ammo HUD on mount (spider only)
if mech.head_name == "assorted_mecha:head_spider" then if mech.head_name == "assorted_mecha:head_spider" then
add_ammo_hud(clicker) add_ammo_hud(clicker)
update_ammo_hud(clicker, self._spider_ammo or SPIDER_AMMO_MAX) update_ammo_hud(clicker, self._spider_ammo or SPIDER_AMMO_MAX)
@@ -854,7 +852,7 @@ on_step = function(self, dtime)
local control = target_player:get_player_control() local control = target_player:get_player_control()
if control.aux1 and not self.is_firing then if control.aux1 and not self.is_firing then
-- Ammo-Check: zugehoerigen mech1-Body in der Naehe suchen -- Ammo check: find the mech1 body near the head (head_offset.y = 4.75)
local mech_ent = nil local mech_ent = nil
local hp = self.object:get_pos() local hp = self.object:get_pos()
for _, obj in ipairs(minetest.get_objects_inside_radius(hp, 6)) do for _, obj in ipairs(minetest.get_objects_inside_radius(hp, 6)) do
@@ -869,13 +867,13 @@ on_step = function(self, dtime)
local ammo = mech_ent and (mech_ent._spider_ammo or SPIDER_AMMO_MAX) or SPIDER_AMMO_MAX local ammo = mech_ent and (mech_ent._spider_ammo or SPIDER_AMMO_MAX) or SPIDER_AMMO_MAX
if ammo < SPIDER_AMMO_MIN_TO_FIRE then if ammo < SPIDER_AMMO_MIN_TO_FIRE then
-- Leer: kein Schuss, kurzer Click-Sound als Feedback -- Empty: no shot, play a dry-fire click as feedback
minetest.sound_play("bullet", {pos = self.object:get_pos(), gain = 0.3, max_hear_distance = 8}) minetest.sound_play("bullet", {pos = self.object:get_pos(), gain = 0.3, max_hear_distance = 8})
return return
end end
self.is_firing = true self.is_firing = true
-- Ammo verbrauchen und HUD aktualisieren -- Consume ammo and update HUD
if mech_ent then if mech_ent then
mech_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST) mech_ent._spider_ammo = math.max(0, ammo - SPIDER_AMMO_COST)
update_ammo_hud(target_player, mech_ent._spider_ammo) update_ammo_hud(target_player, mech_ent._spider_ammo)