mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Gave the player_create feature the same as diggy SetupPlayer
This commit is contained in:
parent
0a076b5e1f
commit
7800fab345
62
config.lua
62
config.lua
@ -14,6 +14,8 @@ global.config = {
|
||||
-- New Scenario Features, appears in the "What's new" tab
|
||||
new_info_key = 'Nothing is new. The world is at peace',
|
||||
|
||||
-- Adds a command to scale UPS and movement speed. Use with caution
|
||||
-- as it might break scenarios that modify movement speed
|
||||
performance = {
|
||||
enabled = true,
|
||||
},
|
||||
@ -97,6 +99,66 @@ global.config = {
|
||||
mentions = {
|
||||
enabled = true,
|
||||
},
|
||||
|
||||
player_create = {
|
||||
enabled = true,
|
||||
|
||||
-- items automatically inserted into the player inventory
|
||||
starting_items = {
|
||||
{name = 'iron-gear-wheel', count = 8},
|
||||
{name = 'iron-plate', count = 16},
|
||||
},
|
||||
|
||||
-- opens the scenario popup when the player joins
|
||||
show_info_at_start = true,
|
||||
|
||||
-- prints messages when the player joins
|
||||
join_messages = {
|
||||
'Welcome to this map created by the RedMew team. You can join our discord at: redmew.com/discord',
|
||||
'Click the question mark in the top left corner for server information and map details.',
|
||||
},
|
||||
|
||||
-- format is a table: {{message, weight}, {message, weight}}, where a higher weight has more chance to be shown
|
||||
random_join_message_set = require 'resources.join_messages',
|
||||
|
||||
-- applied when cheat_mode is set to true
|
||||
cheats = {
|
||||
-- Sets the manual mining speed for the player force. A value of 1 = 100% faster. Setting it
|
||||
-- to 0.5 would make it 50% faster than the base speed.
|
||||
manual_mining_speed_modifier = 1000,
|
||||
|
||||
-- increase the amount of inventory slots for the player force
|
||||
character_inventory_slots_bonus = 0,
|
||||
|
||||
-- increases the run speed of all characters for the player force
|
||||
character_running_speed_modifier = 5,
|
||||
|
||||
-- a flat health bonus to the player force
|
||||
character_health_bonus = 1000000,
|
||||
|
||||
-- unlock all research by default, only useful when testing
|
||||
unlock_all_research = true,
|
||||
|
||||
-- starts with a fully slotted power armor mk2
|
||||
start_with_power_armor = true,
|
||||
|
||||
-- adds additional items to the player when _CHEATS is true
|
||||
starting_items = {
|
||||
{name = 'steel-axe', count = 10},
|
||||
{name = 'submachine-gun', count = 1},
|
||||
{name = 'uranium-rounds-magazine', count = 200},
|
||||
{name = 'construction-robot', count = 250},
|
||||
{name = 'electric-energy-interface', count = 50},
|
||||
{name = 'substation', count = 50},
|
||||
{name = 'roboport', count = 10},
|
||||
{name = 'infinity-chest', count = 10},
|
||||
{name = 'small-plane', count = 2},
|
||||
{name = 'coin', count = 20000},
|
||||
{name = 'rocket-part', count = 2},
|
||||
{name = 'computer', count = 2},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return global.config
|
||||
|
@ -1,71 +1,99 @@
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Info = require 'features.gui.info'
|
||||
local get_random_weighted = table.get_random_weighted
|
||||
|
||||
local info = require 'features.gui.info'
|
||||
local join_msgs = require 'resources.join_messages'
|
||||
local memory = {
|
||||
forces_initialized = {
|
||||
player = false, -- default force for everyone
|
||||
}
|
||||
}
|
||||
|
||||
Global.register({
|
||||
memory = memory,
|
||||
}, function (tbl)
|
||||
memory = tbl.memory
|
||||
end)
|
||||
|
||||
local function player_created(event)
|
||||
local config = global.config.player_create
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
player.insert {name = 'iron-gear-wheel', count = 8}
|
||||
player.insert {name = 'iron-plate', count = 16}
|
||||
|
||||
player.print('Welcome to this map created by the RedMew team. You can join our discord at: redmew.com/discord')
|
||||
player.print('Click the question mark in the top left corner for server information and map details.')
|
||||
player.print(table.get_random_weighted(join_msgs, 1, 2))
|
||||
local force = player.force
|
||||
|
||||
-- ensure the top menu is correctly styled
|
||||
local gui = player.gui
|
||||
gui.top.style = 'slot_table_spacing_horizontal_flow'
|
||||
gui.left.style = 'slot_table_spacing_vertical_flow'
|
||||
if info ~= nil then
|
||||
info.show_info({player = player})
|
||||
|
||||
local player_insert = player.insert
|
||||
|
||||
for _, item in pairs(config.starting_items) do
|
||||
player_insert(item)
|
||||
end
|
||||
|
||||
local p = player.print
|
||||
for _, message in pairs(config.join_messages) do
|
||||
p(message)
|
||||
end
|
||||
|
||||
local random_messages = config.random_join_message_set
|
||||
if #random_messages > 0 then
|
||||
p(get_random_weighted(random_messages, 1, 2))
|
||||
end
|
||||
|
||||
if config.show_info_at_start then
|
||||
if Info ~= nil then
|
||||
Info.show_info({player = player})
|
||||
end
|
||||
end
|
||||
|
||||
if _CHEATS then
|
||||
local force = player.force
|
||||
local i = player.insert
|
||||
|
||||
i {name = 'power-armor-mk2', count = 1}
|
||||
local p_armor = player.get_inventory(5)[1].grid
|
||||
local p = p_armor.put
|
||||
p({name = 'fusion-reactor-equipment'})
|
||||
p({name = 'fusion-reactor-equipment'})
|
||||
p({name = 'fusion-reactor-equipment'})
|
||||
p({name = 'fusion-reactor-equipment'})
|
||||
p({name = 'personal-roboport-mk2-equipment'})
|
||||
p({name = 'personal-roboport-mk2-equipment'})
|
||||
p({name = 'personal-laser-defense-equipment'})
|
||||
p({name = 'personal-laser-defense-equipment'})
|
||||
p({name = 'energy-shield-mk2-equipment'})
|
||||
p({name = 'energy-shield-mk2-equipment'})
|
||||
p({name = 'night-vision-equipment'})
|
||||
p({name = 'battery-mk2-equipment'})
|
||||
p({name = 'battery-mk2-equipment'})
|
||||
p({name = 'battery-mk2-equipment'})
|
||||
p({name = 'belt-immunity-equipment'})
|
||||
p({name = 'solar-panel-equipment'})
|
||||
i {name = 'steel-axe', count = 10}
|
||||
i {name = 'submachine-gun', count = 1}
|
||||
i {name = 'uranium-rounds-magazine', count = 1000}
|
||||
i {name = 'construction-robot', count = 250}
|
||||
i {name = 'electric-energy-interface', count = 50}
|
||||
i {name = 'substation', count = 50}
|
||||
i {name = 'roboport', count = 10}
|
||||
i {name = 'infinity-chest', count = 10}
|
||||
i {name = 'small-plane', count = 2}
|
||||
i {name = 'coin', count = 20000}
|
||||
i {name = 'rocket-part', count = 2}
|
||||
i {name = 'computer', count = 2}
|
||||
|
||||
player.cheat_mode = true
|
||||
force.manual_mining_speed_modifier = 10
|
||||
force.character_running_speed_modifier = 5
|
||||
force.character_health_bonus = 100000
|
||||
local cheats = config.cheats
|
||||
|
||||
if cheats.start_with_power_armor then
|
||||
player_insert({name = 'power-armor-mk2', count = 1})
|
||||
local armor_put = player.get_inventory(5)[1].grid.put
|
||||
armor_put({name = 'fusion-reactor-equipment'})
|
||||
armor_put({name = 'fusion-reactor-equipment'})
|
||||
armor_put({name = 'fusion-reactor-equipment'})
|
||||
armor_put({name = 'fusion-reactor-equipment'})
|
||||
armor_put({name = 'personal-roboport-mk2-equipment'})
|
||||
armor_put({name = 'personal-roboport-mk2-equipment'})
|
||||
armor_put({name = 'personal-laser-defense-equipment'})
|
||||
armor_put({name = 'personal-laser-defense-equipment'})
|
||||
armor_put({name = 'energy-shield-mk2-equipment'})
|
||||
armor_put({name = 'energy-shield-mk2-equipment'})
|
||||
armor_put({name = 'night-vision-equipment'})
|
||||
armor_put({name = 'battery-mk2-equipment'})
|
||||
armor_put({name = 'battery-mk2-equipment'})
|
||||
armor_put({name = 'battery-mk2-equipment'})
|
||||
armor_put({name = 'belt-immunity-equipment'})
|
||||
armor_put({name = 'solar-panel-equipment'})
|
||||
end
|
||||
for _, item in pairs(cheats.starting_items) do
|
||||
player_insert(item)
|
||||
end
|
||||
|
||||
if not memory.forces_initialized[force.name] then
|
||||
force.manual_mining_speed_modifier = cheats.manual_mining_speed_modifier
|
||||
force.character_inventory_slots_bonus = cheats.character_inventory_slots_bonus
|
||||
force.character_running_speed_modifier = cheats.character_running_speed_modifier
|
||||
force.character_health_bonus = cheats.character_health_bonus
|
||||
|
||||
if cheats.unlock_all_research then
|
||||
force.research_all_technologies()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
memory.forces_initialized[force.name] = true
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_created, player_created)
|
||||
|
@ -1,33 +1,19 @@
|
||||
--[[-- info
|
||||
Provides the ability to setup a player when first joined.
|
||||
]]
|
||||
|
||||
-- dependencies
|
||||
local Event = require 'utils.event'
|
||||
local Debug = require 'map_gen.Diggy.Debug'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
-- 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.get_player_by_index(event.player_index)
|
||||
local force = player.force
|
||||
local player_insert = player.insert
|
||||
local position = {0, 0}
|
||||
local surface = player.surface
|
||||
|
||||
for _, item in pairs(config.starting_items) do
|
||||
player_insert(item)
|
||||
end
|
||||
local redmew_player_create = global.config.player_create
|
||||
|
||||
if global.SetupPlayer.first_player_spawned then
|
||||
position = surface.find_non_colliding_position('player', position, 3, 0.1)
|
||||
@ -35,23 +21,24 @@ function SetupPlayer.register(config)
|
||||
global.SetupPlayer.first_player_spawned = true
|
||||
end
|
||||
|
||||
if #config.starting_items > 0 then
|
||||
redmew_player_create.starting_items = config.starting_items
|
||||
end
|
||||
|
||||
force.set_spawn_position(position, surface)
|
||||
player.teleport(position)
|
||||
|
||||
Debug.cheat(function()
|
||||
local cheats = config.cheats
|
||||
force.manual_mining_speed_modifier = cheats.manual_mining_speed_modifier
|
||||
force.character_inventory_slots_bonus = cheats.character_inventory_slots_bonus
|
||||
force.character_running_speed_modifier = cheats.character_running_speed_modifier
|
||||
force.character_health_bonus = cheats.character_health_bonus
|
||||
if cheats.unlock_all_research then
|
||||
force.research_all_technologies()
|
||||
end
|
||||
local cheats = config.cheats
|
||||
local redmew_cheats = redmew_player_create.cheats
|
||||
redmew_cheats.manual_mining_speed_modifier = cheats.manual_mining_speed_modifier
|
||||
redmew_cheats.character_inventory_slots_bonus = cheats.character_inventory_slots_bonus
|
||||
redmew_cheats.character_running_speed_modifier = cheats.character_running_speed_modifier
|
||||
redmew_cheats.character_health_bonus = cheats.character_health_bonus
|
||||
redmew_cheats.unlock_all_research = cheats.unlock_all_research
|
||||
|
||||
for _, item in pairs(cheats.starting_items) do
|
||||
player_insert(item)
|
||||
end
|
||||
end)
|
||||
if #cheats.starting_items > 0 then
|
||||
redmew_cheats.starting_items = cheats.starting_items
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user