From f989cbf6a32356831de54c8b45b1a54cf80ff399 Mon Sep 17 00:00:00 2001 From: blubFisch Date: Sun, 9 Oct 2022 12:25:22 +0100 Subject: [PATCH 1/3] Refactor --- maps/scrap_towny_ffa/player.lua | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/maps/scrap_towny_ffa/player.lua b/maps/scrap_towny_ffa/player.lua index 27df280c..52be999e 100644 --- a/maps/scrap_towny_ffa/player.lua +++ b/maps/scrap_towny_ffa/player.lua @@ -82,23 +82,21 @@ end function Public.requests(player) local this = ScenarioTable.get() if this.requests[player.index] and this.requests[player.index] == 'kill-character' then - if player.character then - if player.character.valid then - -- Clear inventories to avoid people easily getting back their stuff after a town dies offline - local inventories = { - player.get_inventory(defines.inventory.character_main), - player.get_inventory(defines.inventory.character_guns), - player.get_inventory(defines.inventory.character_ammo), - player.get_inventory(defines.inventory.character_armor), - player.get_inventory(defines.inventory.character_vehicle), - player.get_inventory(defines.inventory.character_trash) - } - for _, i in pairs(inventories) do - i.clear() - end - - player.character.die() + if player.character and player.character.valid then + -- Clear inventories to avoid people easily getting back their stuff after a town dies offline + local inventories = { + player.get_inventory(defines.inventory.character_main), + player.get_inventory(defines.inventory.character_guns), + player.get_inventory(defines.inventory.character_ammo), + player.get_inventory(defines.inventory.character_armor), + player.get_inventory(defines.inventory.character_vehicle), + player.get_inventory(defines.inventory.character_trash) + } + for _, i in pairs(inventories) do + i.clear() end + + player.character.die() end this.requests[player.index] = nil end From 26750ed6bd6b6d9b398c9dfbd7e711d3a310df98 Mon Sep 17 00:00:00 2001 From: blubFisch Date: Sun, 9 Oct 2022 15:45:14 +0100 Subject: [PATCH 2/3] Fix a wrong message --- maps/scrap_towny_ffa/pvp_shield.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps/scrap_towny_ffa/pvp_shield.lua b/maps/scrap_towny_ffa/pvp_shield.lua index 7ff810ea..283d8f46 100644 --- a/maps/scrap_towny_ffa/pvp_shield.lua +++ b/maps/scrap_towny_ffa/pvp_shield.lua @@ -63,7 +63,7 @@ function Public.add_shield(surface, force, center, lifetime_ticks, time_to_full_ if is_pause_mode then -- Freeze players to avoid AFK abuse shield.force.character_running_speed_modifier = -1 - game.print("Your AFK PvP shield is now rolling out. You will be frozen until it expires in " .. + shield.force.print("Your AFK PvP shield is now rolling out. You will be frozen until it expires in " .. string.format("%.0f", (Public.remaining_lifetime(shield)) / 60 / 60) .. ' minutes') end From 6c4621e3c7c6247111ab52a2b343ecbc970e913f Mon Sep 17 00:00:00 2001 From: blubFisch Date: Sun, 9 Oct 2022 16:02:27 +0100 Subject: [PATCH 3/3] Prevent players from being in vehicles while AFK shield --- maps/scrap_towny_ffa/pvp_shield.lua | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/maps/scrap_towny_ffa/pvp_shield.lua b/maps/scrap_towny_ffa/pvp_shield.lua index 283d8f46..95c07f38 100644 --- a/maps/scrap_towny_ffa/pvp_shield.lua +++ b/maps/scrap_towny_ffa/pvp_shield.lua @@ -63,6 +63,12 @@ function Public.add_shield(surface, force, center, lifetime_ticks, time_to_full_ if is_pause_mode then -- Freeze players to avoid AFK abuse shield.force.character_running_speed_modifier = -1 + -- Kick players out of vehicles if needed + for _, player in pairs(force.connected_players) do + if player.character.driving then + player.character.driving = false + end + end shield.force.print("Your AFK PvP shield is now rolling out. You will be frozen until it expires in " .. string.format("%.0f", (Public.remaining_lifetime(shield)) / 60 / 60) .. ' minutes') end @@ -123,7 +129,7 @@ function Public.push_enemies_out(player) center_diff.y = center_diff.y / vector_norm(center_diff) player.teleport({ player.position.x + center_diff.x, player.position.y + center_diff.y}, player.surface) - -- Kick players out of vehicles if they try to drive in + -- Kick players out of vehicles if needed if player.character.driving then player.character.driving = false end @@ -150,6 +156,27 @@ local function on_player_changed_position(event) Public.push_enemies_out(player) end +local function on_player_driving_changed_state(event) + local player = game.players[event.player_index] + if not player or not player.valid then + return + end + local this = ScenarioTable.get_table() + for _, shield in pairs(this.pvp_shields) do + if shield.force == player.force and shield.is_pause_mode then + local vehicle = player.vehicle + if vehicle and vehicle.valid then + -- Kick players out of vehicles if needed + if player.character.driving then + player.character.driving = false + player.print("Can't drive around while AFK PvP Shield is active") + end + end + end + end +end + +Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state) Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.on_nth_tick(60, update_shield_lifetime)