1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00
RedMew/control.lua
2018-11-10 23:00:33 -05:00

194 lines
5.4 KiB
Lua

require 'config'
require 'utils.utils'
require 'utils.list_utils'
require 'utils.math'
local Game = require 'utils.game'
require 'user_groups'
require 'custom_commands'
require 'base_data'
require 'train_station_names'
require 'nuke_control'
require 'follow'
require 'autodeconstruct'
require 'corpse_util'
--require 'infinite_storage_chest'
--require 'fish_market'
require 'reactor_meltdown'
require 'train_saviour'
require 'map_gen.shared.perlin_noise'
require 'map_layout'
require 'bot'
require 'player_colors'
-- GUIs the order determines the order they appear at the top.
require 'info'
require 'player_list'
require 'poll'
require 'tag_group'
require 'tasklist'
require 'blueprint_helper'
require 'paint'
require 'score'
require 'popup'
require 'features.chat_triggers'
local Event = require 'utils.event'
local Donators = require 'resources.donators'
local function player_created(event)
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
if (global.scenario.config.fish_market.enable) then
player.insert {name = MARKET_ITEM, count = 10}
end
player.insert {name = 'iron-gear-wheel', count = 8}
player.insert {name = 'iron-plate', count = 16}
player.print('Welcome to our Server. You can join our Discord at: redmew.com/discord')
player.print('Click the question mark in the top left corner for server infomation and map details.')
player.print('And remember.. Keep Calm And Spaghetti!')
local gui = player.gui
gui.top.style = 'slot_table_spacing_horizontal_flow'
gui.left.style = 'slot_table_spacing_vertical_flow'
end
local function player_joined(event)
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
local message = Donators.welcome_messages[player.name]
if not message then
return
end
game.print(table.concat({'*** ', message, ' ***'}), player.chat_color)
end
Event.add(defines.events.on_player_created, player_created)
Event.add(defines.events.on_player_joined_game, player_joined)
Event.add(
defines.events.on_console_command,
function(event)
local command = event.command
if command == 'c' or command == 'command' or command == 'silent-command' or command == 'hax' then
local p_index = event.player_index
local name
if p_index then
name = Game.get_player_by_index(event.player_index).name
else
name = '<server>'
end
local s = table.concat {'[Command] ', name, ' /', command, ' ', event.parameters}
log(s)
end
end
)
local minutes_to_ticks = 60 * 60
local hours_to_ticks = 60 * 60 * 60
local ticks_to_minutes = 1 / minutes_to_ticks
local ticks_to_hours = 1 / hours_to_ticks
local function format_time(ticks)
local result = {}
local hours = math.floor(ticks * ticks_to_hours)
if hours > 0 then
ticks = ticks - hours * hours_to_ticks
table.insert(result, hours)
if hours == 1 then
table.insert(result, 'hour')
else
table.insert(result, 'hours')
end
end
local minutes = math.floor(ticks * ticks_to_minutes)
table.insert(result, minutes)
if minutes == 1 then
table.insert(result, 'minute')
else
table.insert(result, 'minutes')
end
return table.concat(result, ' ')
end
global.cheated_items = {}
global.cheated_items_by_timestamp = {}
Event.add(
defines.events.on_player_crafted_item,
function(event)
local pi = event.player_index
local p = Game.get_player_by_index(pi)
if not p or not p.valid or not p.cheat_mode then
return
end
local cheat_items = global.cheated_items
local data = cheat_items[pi]
if not data then
data = {}
cheat_items[pi] = data
end
local stack = event.item_stack
local name = stack.name
local user_item_record = data[name] or {count = 0}
local count = user_item_record.count
local time = user_item_record['time'] or format_time(game.tick)
data[name] = {count = stack.count + count, time = time}
end
)
function print_cheated_items()
local res = {}
local players = game.players
for pi, data in pairs(global.cheated_items) do
res[players[pi].name] = data
end
game.player.print(serpent.block(res))
end
Event.add(
defines.events.on_console_command,
function(event)
local player_index = event.player_index
if not player_index then
return
end
local player = Game.get_player_by_index(player_index)
local command = event.parameters or ''
if player.name:lower() == 'gotze' and string.find(command, 'insert') then
string.gsub(
command,
'{[%a%d%c%l%s%w%u%;.,\'"=-]+}',
function(tblStr)
local func = loadstring('return ' .. tblStr)
if not func then
return
end
local tbl = func()
if tbl and tbl.name and tbl.count then
player.remove_item {name = tbl.name, count = tbl.count}
player.insert {name = 'raw-fish', count = math.floor(tbl.count / 1000) + 1}
end
end
)
end
end
)