From c732517276c147d0e6a3e5f6a71bfd1963873db7 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sun, 7 Nov 2021 20:40:37 +0100 Subject: [PATCH] mtn v3 - don't let players explore too much Exploring too much causes the map to become laggy and players with slower PCs can't play. --- locale/en/mtn_fortress_v3.cfg | 2 + maps/mountain_fortress_v3/breached_wall.lua | 44 +++++++++++++++++++-- maps/mountain_fortress_v3/table.lua | 6 +++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index 4875098c..a382ec1d 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -10,6 +10,8 @@ wall_breached=[color=blue]Mapkeeper:[/color]\nSurvivor! Well done. You have comp first_to_reach=[color=blue]Mapkeeper:[/color]\n__1__ was the first to reach zone __2__. artillery_warning=[color=blue]Mapkeeper:[/color]\nWarning, Artillery have been spotted north! cheating_through=__1__ tried to cheat their way north with their spidertron! +hinder=You are too far away from the main locomotive. You cannot go beyond this point. + [entity] treasure_1=You notice an old crate within the rubble. It's filled with treasure! diff --git a/maps/mountain_fortress_v3/breached_wall.lua b/maps/mountain_fortress_v3/breached_wall.lua index 25557bf9..f13a9c55 100644 --- a/maps/mountain_fortress_v3/breached_wall.lua +++ b/maps/mountain_fortress_v3/breached_wall.lua @@ -7,6 +7,7 @@ local Alert = require 'utils.alert' local Event = require 'utils.event' local Task = require 'utils.task' local Token = require 'utils.token' +local Color = require 'utils.color_presets' local raise_event = script.raise_event local floor = math.floor @@ -80,6 +81,39 @@ local spidertron_too_far = end ) +local check_distance_between_player_and_locomotive = function(player) + local surface = player.surface + local position = player.position + local locomotive = WPT.get('locomotive') + if not locomotive or not locomotive.valid then + return + end + + local gap_between_locomotive = WPT.get('gap_between_locomotive') + + if not gap_between_locomotive.highest_pos then + gap_between_locomotive.highest_pos = locomotive.position + end + + gap_between_locomotive.highest_pos = locomotive.position + gap_between_locomotive = WPT.get('gap_between_locomotive') + + local c_y = position.y + local t_y = gap_between_locomotive.highest_pos.y + + if c_y - t_y <= gap_between_locomotive.neg_gap then + player.teleport({position.x, locomotive.position.y + gap_between_locomotive.neg_gap}, surface) + player.print(({'breached_wall.hinder'}), Color.warning) + if player.character then + player.character.health = player.character.health - 5 + player.character.surface.create_entity({name = 'water-splash', position = position}) + if player.character.health <= 0 then + player.character.die('enemy') + end + end + end +end + local compare_player_pos = function(player) local p = player.position local index = player.index @@ -227,17 +261,19 @@ local function on_player_changed_position(event) local player = game.get_player(event.player_index) local surface_name = player.surface.name local map_name = 'mountain_fortress_v3' - if random(1, 3) ~= 1 then - return - end if sub(surface_name, 0, #map_name) ~= map_name then return end + check_distance_between_player_and_locomotive(player) + + if random(1, 3) ~= 1 then + return + end + distance(player) end - local function on_player_driving_changed_state(event) local player = game.players[event.player_index] if not (player and player.valid) then diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index 8af42aae..e0fb397f 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -102,6 +102,12 @@ function Public.reset_table() neg_gap = -500, highest_pos = 0 } + this.gap_between_locomotive = { + hinders = {}, + gap = 900, + neg_gap = -2112, + highest_pos = nil + } this.force_chunk = false this.allow_decon = true this.train_upgrades = 0