mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
merged #295
This commit is contained in:
commit
9ce662daf9
124
control.lua
124
control.lua
@ -4,14 +4,9 @@ require 'utils.utils'
|
|||||||
require 'utils.list_utils'
|
require 'utils.list_utils'
|
||||||
require 'utils.math'
|
require 'utils.math'
|
||||||
|
|
||||||
local Game = require 'utils.game'
|
|
||||||
local Event = require 'utils.event'
|
|
||||||
local Donators = require 'resources.donators'
|
|
||||||
|
|
||||||
require 'map_gen.shared.perlin_noise'
|
require 'map_gen.shared.perlin_noise'
|
||||||
require 'map_layout'
|
require 'map_layout'
|
||||||
|
|
||||||
|
|
||||||
-- Specific to RedMew hosts, can be disabled safely if not hosting on RedMew servers
|
-- Specific to RedMew hosts, can be disabled safely if not hosting on RedMew servers
|
||||||
require 'features.bot'
|
require 'features.bot'
|
||||||
|
|
||||||
@ -46,7 +41,9 @@ require 'features.gui.paint'
|
|||||||
require 'features.gui.score'
|
require 'features.gui.score'
|
||||||
require 'features.gui.popup'
|
require 'features.gui.popup'
|
||||||
require 'features.donator_messages'
|
require 'features.donator_messages'
|
||||||
|
require 'features.free_item_logging'
|
||||||
|
|
||||||
|
local Game = require 'utils.game'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
|
|
||||||
local function player_created(event)
|
local function player_created(event)
|
||||||
@ -179,120 +176,3 @@ end
|
|||||||
Event.add(defines.events.on_player_created, player_created)
|
Event.add(defines.events.on_player_created, player_created)
|
||||||
Event.add(defines.events.on_console_chat, hodor)
|
Event.add(defines.events.on_console_chat, hodor)
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
64
features/free_item_logging.lua
Normal file
64
features/free_item_logging.lua
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
local Utils = require 'utils.utils'
|
||||||
|
local Event = require 'utils.event'
|
||||||
|
local Game = require 'utils.game'
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
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 Utils.format_time(game.tick)
|
||||||
|
data[name] = {count = stack.count + count, time = time}
|
||||||
|
local s = table.concat {'[Cheated item] ', p.name, ' - ', stack.count, ' x ', name}
|
||||||
|
log(s)
|
||||||
|
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
|
@ -12,7 +12,6 @@ Module.donators = {
|
|||||||
['aldldl'] = d.rank,
|
['aldldl'] = d.rank,
|
||||||
['Geostyx'] = d.rank,
|
['Geostyx'] = d.rank,
|
||||||
['Linaori'] = d.rank,
|
['Linaori'] = d.rank,
|
||||||
['Terarink'] = d.rank + d.train,
|
|
||||||
['Xertez'] = d.rank,
|
['Xertez'] = d.rank,
|
||||||
['Chevalier1200'] = d.rank + d.train,
|
['Chevalier1200'] = d.rank + d.train,
|
||||||
['DraugTheWhopper'] = d.rank + d.train,
|
['DraugTheWhopper'] = d.rank + d.train,
|
||||||
@ -36,4 +35,4 @@ Module.welcome_messages = {
|
|||||||
['shoghicp'] = 'Need more servers!'
|
['shoghicp'] = 'Need more servers!'
|
||||||
}
|
}
|
||||||
|
|
||||||
return Module
|
return Module
|
||||||
|
Loading…
Reference in New Issue
Block a user