From caab35040a19c9d73e9630e8b9eceb122ab3cd1d Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 26 Aug 2020 11:49:36 +0200 Subject: [PATCH 1/4] Use assembler for finding new car position Change the entity name used to find a non-colliding position to assembling-machine-1. This moves the car away from close obstacles it could get stuck in due to the non-colliding position algorithm not taking account to the rotation of the car. --- modules/mini-games/Race.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mini-games/Race.lua b/modules/mini-games/Race.lua index a993366..4f5e308 100644 --- a/modules/mini-games/Race.lua +++ b/modules/mini-games/Race.lua @@ -417,7 +417,7 @@ end) local respawn_car respawn_car = Token.register(function(name) local player = dead_cars[name].player - local position = surface[1].find_non_colliding_position('car', dead_cars[name].position, 5, 0.5) + local position = surface[1].find_non_colliding_position('assembling-machine-1', dead_cars[name].position, 5, 0.5) if not position then return task.set_timeout_in_ticks(30, respawn_car, name) end From 2f10d882ac34c884072e658dcfcc720f2f189900 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 26 Aug 2020 11:52:02 +0200 Subject: [PATCH 2/4] Add /unstuck command Add unstuck command for the Race game which moves the player's car away from nearby obstacles. --- config/expcore/roles.lua | 1 + modules/mini-games/Race.lua | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 2f2e5e7..cd28061 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -108,6 +108,7 @@ local default = Roles.new_role('Guest','') 'command/warp', 'command/join-UFE', 'command/join-UFW', + 'command/unstuck', 'command/lobby', } diff --git a/modules/mini-games/Race.lua b/modules/mini-games/Race.lua index 4f5e308..4a6e797 100644 --- a/modules/mini-games/Race.lua +++ b/modules/mini-games/Race.lua @@ -5,6 +5,7 @@ local Permission_Groups = require "expcore.permission_groups" local Global = require 'utils.global' --Used to prevent desyncing. local interface = require 'modules.commands.interface' local Gui = require 'expcore.gui._require' +local Commands = require 'expcore.commands' local config = require "config.mini_games.Race" local surface = {} @@ -413,6 +414,19 @@ local kill_biters = Token.register(function(name) end end) +--- Unstuck yourself +Commands.new_command('unstuck', 'Unstuck your car from walls') +:register(function(player) + local car = cars[player.name] + if not car or not car.valid then + player.print("Not in a car!") + return Commands.error + end + + local new_position = surface[1].find_non_colliding_position('assembling-machine-1', car.position, 5, 0.5) + car.teleport(new_position, surface[1]) +end) + --- Respawn the car for a player local respawn_car respawn_car = Token.register(function(name) @@ -557,4 +571,6 @@ race:add_event(defines.events.on_player_driving_changed_state, back_in_car) race:add_event(Mini_games.events.on_participant_added, on_player_added) race:add_event(Mini_games.events.on_participant_created, on_player_created) race:add_event(Mini_games.events.on_participant_left, on_player_left) -race:add_event(Mini_games.events.on_participant_removed, on_player_removed) \ No newline at end of file +race:add_event(Mini_games.events.on_participant_removed, on_player_removed) + +race:add_command('unstuck') \ No newline at end of file From 91ae920139217387eb9972e8eef486445e43ef32 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 26 Aug 2020 12:06:12 +0200 Subject: [PATCH 3/4] Fix mini-games commands not being disabled Fix the commands part of mini-games not being disabled when the game is over. --- expcore/Mini_games.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expcore/Mini_games.lua b/expcore/Mini_games.lua index 529ba7f..d97592d 100644 --- a/expcore/Mini_games.lua +++ b/expcore/Mini_games.lua @@ -820,7 +820,7 @@ function Mini_games.stop_game() -- Disable all commands for this mini game for _, command_name in ipairs(mini_game.commands) do - Commands.enable(command_name) + Commands.disable(command_name) end if skip_timeout then From 0072e558b93659db08ea31a827cd010c66ed2f6d Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 26 Aug 2020 12:52:37 +0200 Subject: [PATCH 4/4] Pass error to Command.error Pass the missing car error message to Command.error and let the command system print it to the user. --- modules/mini-games/Race.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/mini-games/Race.lua b/modules/mini-games/Race.lua index 4a6e797..4c899af 100644 --- a/modules/mini-games/Race.lua +++ b/modules/mini-games/Race.lua @@ -419,8 +419,7 @@ Commands.new_command('unstuck', 'Unstuck your car from walls') :register(function(player) local car = cars[player.name] if not car or not car.valid then - player.print("Not in a car!") - return Commands.error + return Commands.error("Not in a car.") end local new_position = surface[1].find_non_colliding_position('assembling-machine-1', car.position, 5, 0.5)