2018-09-08 18:29:27 +02:00
|
|
|
--[[-- info
|
|
|
|
Provides the ability to setup a player when first joined.
|
|
|
|
]]
|
|
|
|
|
|
|
|
-- dependencies
|
|
|
|
local Event = require 'utils.event'
|
2018-09-14 22:12:55 +02:00
|
|
|
local Debug = require 'map_gen.Diggy.Debug'
|
2018-09-08 18:29:27 +02:00
|
|
|
|
|
|
|
-- this
|
|
|
|
local SetupPlayer = {}
|
|
|
|
|
2018-10-16 10:01:22 +02:00
|
|
|
global.SetupPlayer = {
|
|
|
|
first_player_spawned = false,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-08 18:29:27 +02:00
|
|
|
--[[--
|
|
|
|
Registers all event handlers.
|
|
|
|
]]
|
|
|
|
function SetupPlayer.register(config)
|
|
|
|
Event.add(defines.events.on_player_created, function (event)
|
2018-09-11 22:15:02 +02:00
|
|
|
local player = game.players[event.player_index]
|
2018-10-16 10:01:22 +02:00
|
|
|
local position = {0, 0}
|
|
|
|
local surface = player.surface
|
2018-09-14 21:42:58 +02:00
|
|
|
|
2018-10-07 17:05:59 +02:00
|
|
|
for _, item in pairs(config.starting_items) do
|
2018-09-14 21:42:58 +02:00
|
|
|
player.insert(item)
|
|
|
|
end
|
|
|
|
|
2018-10-16 10:01:22 +02:00
|
|
|
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)
|
2018-09-14 21:42:58 +02:00
|
|
|
|
2018-09-08 18:29:27 +02:00
|
|
|
Debug.cheat(function()
|
2018-10-07 17:05:59 +02:00
|
|
|
player.force.manual_mining_speed_modifier = config.cheats.manual_mining_speed_modifier
|
2018-10-15 23:40:36 +02:00
|
|
|
player.force.character_inventory_slots_bonus = config.cheats.character_inventory_slots_bonus
|
2018-10-21 20:15:39 +02:00
|
|
|
player.character_running_speed_modifier = config.cheats.character_running_speed_modifier
|
2018-09-08 18:29:27 +02:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
return SetupPlayer
|