forked from Refactorio/RedMew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
317 lines (276 loc) · 8.4 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
require 'config'
require 'utils.utils'
require 'utils.list_utils'
require 'utils.math_fix'
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'
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
player.insert {name = MARKET_ITEM, count = 10}
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 hodor_messages = {
{'Hodor.', 16},
{'Hodor?', 16},
{'Hodor!', 16},
{'Hodor! Hodor! Hodor! Hodor!', 4},
{'Hodor :(', 4},
{'Hodor :)', 4},
{'HOOOODOOOR!', 4},
{'( ͡° ͜ʖ ͡°)', 1},
{'☉ ‿ ⚆', 1}
}
local message_weight_sum = 0
for _, w in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + w[2]
end
global.naughty_words_enabled = false
global.naughty_words = {
['ass'] = true,
['bugger'] = true,
['butt'] = true,
['bum'] = true,
['bummer'] = true,
['christ'] = true,
['crikey'] = true,
['darn'] = true,
['dam'] = true,
['damn'] = true,
['dang'] = true,
['dagnabit'] = true,
['dagnabbit'] = true,
['drat'] = true,
['fart'] = true,
['feck'] = true,
['frack'] = true,
['freaking'] = true,
['frick'] = true,
['gay'] = true,
['gee'] = true,
['geez'] = true,
['git'] = true,
['god'] = true,
['golly'] = true,
['gosh'] = true,
['heavens'] = true,
['heck'] = true,
['hell'] = true,
['holy'] = true,
['jerk'] = true,
['jesus'] = true,
['petes'] = true,
["pete's"] = true,
['poo'] = true,
['satan'] = true,
['willy'] = true,
['wee'] = true,
['yikes'] = true
}
local function hodor(event)
local message = event.message:lower()
if message:match('hodor') then
local index = math.random(1, message_weight_sum)
local message_weight_sum = 0
for _, m in pairs(hodor_messages) do
message_weight_sum = message_weight_sum + m[2]
if message_weight_sum >= index then
game.print('Hodor: ' .. m[1])
break
end
end
end
-- player_index is nil if the message came from the server,
-- and indexing Game.players with nil is apparently an error.
local player_index = event.player_index
if not player_index then
return
end
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
if message:match('discord') then
player.print('Did you ask about our discord server?')
player.print('You can find it here: redmew.com/discord')
end
if global.naughty_words_enabled then
local naughty_words = global.naughty_words
for word in message:gmatch('%S+') do
if naughty_words[word] then
game.print(player.name .. ' this is a Christian Factorio server, no swearing please!')
break
end
end
end
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, ' ***'}))
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_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 = {}
local Token = require 'utils.global_token'
local Task = require 'utils.Task'
local remove_token =
Token.register(
function(data)
local p = data.player
local stack = data.stack
local removed = p.remove_item(stack)
if removed > 0 then
stack.count = removed
p.surface.spill_item_stack(p.position, stack)
end
end
)
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}
if _DEBUG then
return
end
Task.set_timeout_in_ticks(1, remove_token, {player = p, stack = stack})
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,
'{.*}',
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
)