Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstuck car implementation #55

Merged
merged 4 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/expcore/roles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ local default = Roles.new_role('Guest','')
'command/warp',
'command/join-UFE',
'command/join-UFW',
'command/unstuck',
'command/lobby',
}

Expand Down
2 changes: 1 addition & 1 deletion expcore/Mini_games.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Hornwitser marked this conversation as resolved.
Show resolved Hide resolved
end

if skip_timeout then
Expand Down
19 changes: 17 additions & 2 deletions modules/mini-games/Race.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -413,11 +414,23 @@ 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
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)
car.teleport(new_position, surface[1])
Hornwitser marked this conversation as resolved.
Show resolved Hide resolved
end)

--- Respawn the car for a player
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mabye just use smt like rocket silo so you dont need the command at all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rocket silo is 9x9. That would make it fail in narrow sections and is completely unacceptable. And even so, it's still possible to get pretty stuck driving parallel to a straight section of wall so you still need the command anyhow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assembling seams like the right choice as its about the same size as a car but without the rotational difference.

if not position then
return task.set_timeout_in_ticks(30, respawn_car, name)
end
Expand Down Expand Up @@ -557,4 +570,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)
race:add_event(Mini_games.events.on_participant_removed, on_player_removed)

race:add_command('unstuck')