From 2facdbffda9dc1ab0404b1d011880d0b48cba778 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Wed, 6 Nov 2024 22:03:23 +0100 Subject: [PATCH] Fish: fix flying-text --- maps/fish_defender_v2/main.lua | 62 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/maps/fish_defender_v2/main.lua b/maps/fish_defender_v2/main.lua index 36f8025d..d110dcaf 100644 --- a/maps/fish_defender_v2/main.lua +++ b/maps/fish_defender_v2/main.lua @@ -1111,14 +1111,13 @@ local function deny_building(event) end end - event.entity.surface.create_entity( - { - name = 'flying-text', + for _, p in pairs(game.connected_players) do + p.create_local_flying_text({ position = entity.position, text = 'Can not be built beyond the lightning wall!', color = { r = 0.98, g = 0.66, b = 0.22 } - } - ) + }) + end entity.destroy() return true @@ -1142,24 +1141,26 @@ local function on_built_entity(event) if entity_limits[entity.type].placed < entity_limits[entity.type].limit then entity_limits[entity.type].placed = entity_limits[entity.type].placed + 1 - surface.create_entity( - { - name = 'flying-text', - position = entity.position, - text = entity_limits[entity.type].placed .. ' / ' .. entity_limits[entity.type].limit .. ' ' .. entity_limits[entity.type].str .. 's', - color = { r = 0.98, g = 0.66, b = 0.22 } - } - ) + for _, p in pairs(game.connected_players) do + if p.surface == surface then + p.create_local_flying_text({ + position = entity.position, + text = entity_limits[entity.type].placed .. ' / ' .. entity_limits[entity.type].limit .. ' ' .. entity_limits[entity.type].str .. 's', + color = { r = 0.98, g = 0.66, b = 0.22 } + }) + end + end update_fd_stats() else - surface.create_entity( - { - name = 'flying-text', - position = entity.position, - text = entity_limits[entity.type].str .. ' limit reached.', - color = { r = 0.82, g = 0.11, b = 0.11 } - } - ) + for _, p in pairs(game.connected_players) do + if p.surface == surface then + p.create_local_flying_text({ + position = entity.position, + text = entity_limits[entity.type].str .. ' limit reached.', + color = { r = 0.82, g = 0.11, b = 0.11 } + }) + end + end local player = game.get_player(event.player_index) player.insert({ name = entity.name, count = 1 }) if get_score then @@ -1183,27 +1184,24 @@ local function on_robot_built_entity(event) local entity_limits = Public.get('entity_limits') if entity_limits[entity.type] then - local surface = entity.surface if entity_limits[entity.type].placed < entity_limits[entity.type].limit then entity_limits[entity.type].placed = entity_limits[entity.type].placed + 1 - surface.create_entity( - { - name = 'flying-text', + for _, p in pairs(game.connected_players) do + p.create_local_flying_text({ position = entity.position, text = entity_limits[entity.type].placed .. ' / ' .. entity_limits[entity.type].limit .. ' ' .. entity_limits[entity.type].str .. 's', color = { r = 0.98, g = 0.66, b = 0.22 } - } - ) + }) + end update_fd_stats() else - surface.create_entity( - { - name = 'flying-text', + for _, p in pairs(game.connected_players) do + p.create_local_flying_text({ position = entity.position, text = entity_limits[entity.type].str .. ' limit reached.', color = { r = 0.82, g = 0.11, b = 0.11 } - } - ) + }) + end local inventory = event.robot.get_inventory(defines.inventory.robot_cargo) inventory.insert({ name = entity.name, count = 1 }) entity.destroy()