From caba716520434ba28716ad3436228b908ae52043 Mon Sep 17 00:00:00 2001 From: MewMew Date: Wed, 22 Jul 2020 12:25:33 +0200 Subject: [PATCH] map ping when chest is unlocked --- maps/expanse/functions.lua | 6 ++++-- maps/expanse/main.lua | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/maps/expanse/functions.lua b/maps/expanse/functions.lua index f18a741e..a8d9a4fe 100644 --- a/maps/expanse/functions.lua +++ b/maps/expanse/functions.lua @@ -202,7 +202,9 @@ function Public.set_container(expanse, entity) if #container.price == 0 then Public.expand(expanse, container.left_top) - expanse.containers[entity.unit_number] = nil + local a = math.floor(expanse.square_size * 0.5) + local expansion_position = {x = expanse.containers[entity.unit_number].left_top.x + a, y = expanse.containers[entity.unit_number].left_top.y + a} + expanse.containers[entity.unit_number] = nil if not inventory.is_empty() then for name, count in pairs(inventory.get_contents()) do entity.surface.spill_item_stack(entity.position, {name = name, count = count}, true, nil, false) @@ -213,7 +215,7 @@ function Public.set_container(expanse, entity) end entity.destructible = true entity.die() - return + return expansion_position end for slot = 1, 30, 1 do diff --git a/maps/expanse/main.lua b/maps/expanse/main.lua index 8e2ebc50..bd7dbbf8 100644 --- a/maps/expanse/main.lua +++ b/maps/expanse/main.lua @@ -108,22 +108,26 @@ local function on_chunk_generated(event) event.surface.set_tiles(tiles, true) end -local function on_gui_opened(event) +local function container_opened(event) local entity = event.entity if not entity then return end if not entity.valid then return end if not entity.unit_number then return end - if entity.force.index ~= 3 then return end - Functions.set_container(expanse, entity) + if entity.force.index ~= 3 then return end + local expansion_position = Functions.set_container(expanse, entity) + if expansion_position then + local player = game.players[event.player_index] + local colored_player_name = table.concat({"[color=", player.color.r * 0.6 + 0.35, ",", player.color.g * 0.6 + 0.35, ",", player.color.b * 0.6 + 0.35, "]", player.name, "[/color]"}) + game.print(colored_player_name .. " unlocked new grounds! [gps=" .. math.floor(expansion_position.x) .. "," .. math.floor(expansion_position.y) .. ",expanse]") + end +end + +local function on_gui_opened(event) + container_opened(event) end local function on_gui_closed(event) - local entity = event.entity - if not entity then return end - if not entity.valid then return end - if not entity.unit_number then return end - if entity.force.index ~= 3 then return end - Functions.set_container(expanse, entity) + container_opened(event) end local ores = {"iron-ore", "iron-ore", "copper-ore", "coal"} @@ -171,7 +175,7 @@ local function on_player_left_game(event) for _ = 1, removed_count, 1 do player.surface.spill_item_stack(player.position, {name = "small-plane", count = 1}, false, nil, false) end - game.print(player.name .. " dropped their tokens! [gps=" .. math.floor(player.position.x) .. "," .. math.floor(player.position.y) .. "]") + game.print(player.name .. " dropped their tokens! [gps=" .. math.floor(player.position.x) .. "," .. math.floor(player.position.y) .. "," .. player.surface.name .. "]") end end