From f12a3d7d16a6f6f5d3017febd49ca78624bee312 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 4 Oct 2022 17:51:22 +0200 Subject: [PATCH] Towny - fix bugs --- maps/scrap_towny_ffa/market.lua | 2 +- maps/scrap_towny_ffa/spaceship.lua | 20 +++++++++++++------ maps/scrap_towny_ffa/spawn.lua | 4 ++-- .../spawners_contain_biters.lua | 2 +- maps/scrap_towny_ffa/team.lua | 6 ++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/maps/scrap_towny_ffa/market.lua b/maps/scrap_towny_ffa/market.lua index c19025c6..a8304fcc 100644 --- a/maps/scrap_towny_ffa/market.lua +++ b/maps/scrap_towny_ffa/market.lua @@ -83,7 +83,7 @@ local upgrade_functions = { local force = market.force local surface = market.surface local spawn_point = force.get_spawn_position(surface) - this.spawn_point[player.name] = spawn_point + this.spawn_point[player.index] = spawn_point surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1}) return false end diff --git a/maps/scrap_towny_ffa/spaceship.lua b/maps/scrap_towny_ffa/spaceship.lua index ee2ab671..92788448 100644 --- a/maps/scrap_towny_ffa/spaceship.lua +++ b/maps/scrap_towny_ffa/spaceship.lua @@ -2,6 +2,11 @@ local table_insert = table.insert local ScenarioTable = require 'maps.scrap_towny_ffa.table' local Event = require 'utils.event' + +local function position_tostring(position) + return '[x=' .. position.x .. ',y=' .. position.y .. ']' +end + local upgrade_functions = { -- Upgrade Backpack [1] = function(player) @@ -64,7 +69,7 @@ local upgrade_functions = { local position = player.position position = surface.find_non_colliding_position('character', position, 0, 0.25) if position ~= nil and player ~= nil then - this.spawn_point[player.name] = {x = position.x, y = position.y} + this.spawn_point[player.index] = {x = position.x, y = position.y} surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1}) else surface.create_entity( @@ -179,8 +184,9 @@ local function refresh_offers(event) if market.name ~= 'crash-site-spaceship-market' then return end - local position = market.position - local spaceship = this.spaceships[position.x][position.y] + + local key = position_tostring(market.position) + local spaceship = this.spaceships[key] if not spaceship then return end @@ -197,7 +203,8 @@ local function offer_purchased(event) if not upgrade_functions[offer_index] then return end - local spaceship = this.spaceships[market.position.x][market.position.y] + local key = position_tostring(market.position) + local spaceship = this.spaceships[key] if not spaceship then return end @@ -243,9 +250,10 @@ end local function kill_spaceship(entity) local this = ScenarioTable.get_table() - local spaceship = this.spaceships[entity.position.x][entity.position.y] + local key = position_tostring(entity.position) + local spaceship = this.spaceships[key] if spaceship ~= nil then - this.spaceships[entity.position.x][entity.position.y] = nil + this.spaceships[key] = nil end end diff --git a/maps/scrap_towny_ffa/spawn.lua b/maps/scrap_towny_ffa/spawn.lua index 1b3e1d6b..a13d1c92 100644 --- a/maps/scrap_towny_ffa/spawn.lua +++ b/maps/scrap_towny_ffa/spawn.lua @@ -172,7 +172,7 @@ function Public.get_new_spawn_point(player, surface) end end -- should never be invalid or blocked - this.spawn_point[player.name] = position + this.spawn_point[player.index] = position --log("player " .. player.name .. " assigned new spawn point at {" .. position.x .. "," .. position.y .. "}") return position end @@ -180,7 +180,7 @@ end -- gets a new or existing spawn point for the player function Public.get_spawn_point(player, surface) local this = ScenarioTable.get_table() - local position = this.spawn_point[player.name] + local position = this.spawn_point[player.index] -- if there is a spawn point and less than three strikes if position ~= nil and this.strikes[player.name] < 3 then -- check that the spawn point is not blocked diff --git a/maps/scrap_towny_ffa/spawners_contain_biters.lua b/maps/scrap_towny_ffa/spawners_contain_biters.lua index d5c00054..d0b726eb 100644 --- a/maps/scrap_towny_ffa/spawners_contain_biters.lua +++ b/maps/scrap_towny_ffa/spawners_contain_biters.lua @@ -20,7 +20,7 @@ local function on_entity_died(event) if not event.entity.valid then return end - if event.entity.type ~= 'unit-spawner' then + if event.entity.name ~= 'biter-spawner' then return end local e = math.ceil(Evolution.get_biter_evolution(event.entity) * 10) diff --git a/maps/scrap_towny_ffa/team.lua b/maps/scrap_towny_ffa/team.lua index 11057f16..688314e4 100644 --- a/maps/scrap_towny_ffa/team.lua +++ b/maps/scrap_towny_ffa/team.lua @@ -245,11 +245,17 @@ local function set_player_to_rogue(player) log('player nil or not valid!') return end + player.force = 'rogue' local group = game.permissions.get_group('rogue') if group == nil then group = game.permissions.create_group('rogue') end + + if not player.object_name == 'LuaPlayer' then + log('Given object is not of LuaPlayer!') + return + end group.add_player(player) player.tag = '[Rogue]' Map.disable_world_map(player)