mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Fix spawn location for players (#238)
This commit is contained in:
parent
49c22dc765
commit
c9380a1661
@ -5,23 +5,36 @@
|
||||
-- dependencies
|
||||
local Event = require 'utils.event'
|
||||
local Debug = require 'map_gen.Diggy.Debug'
|
||||
local math_random = math.random
|
||||
|
||||
-- this
|
||||
local SetupPlayer = {}
|
||||
|
||||
global.SetupPlayer = {
|
||||
first_player_spawned = false,
|
||||
}
|
||||
|
||||
|
||||
--[[--
|
||||
Registers all event handlers.
|
||||
]]
|
||||
function SetupPlayer.register(config)
|
||||
Event.add(defines.events.on_player_created, function (event)
|
||||
local player = game.players[event.player_index]
|
||||
local position = {0, 0}
|
||||
local surface = player.surface
|
||||
|
||||
for _, item in pairs(config.starting_items) do
|
||||
player.insert(item)
|
||||
end
|
||||
|
||||
player.teleport({x = math_random(-4, 4) / 10, y = math_random(-4, 4) / 10})
|
||||
if (global.SetupPlayer.first_player_spawned) then
|
||||
position = surface.find_non_colliding_position('player', position, 3, 0.1)
|
||||
else
|
||||
global.SetupPlayer.first_player_spawned = true
|
||||
end
|
||||
|
||||
player.force.set_spawn_position(position, surface)
|
||||
player.teleport(position)
|
||||
|
||||
Debug.cheat(function()
|
||||
player.force.manual_mining_speed_modifier = config.cheats.manual_mining_speed_modifier
|
||||
|
Loading…
Reference in New Issue
Block a user