-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset.lua
64 lines (53 loc) · 1.57 KB
/
reset.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
-- reset.lua
local reset_controller = {}
commands.add_command("reset", "Resets map with random seed. Accepts a valid seed and 'true' or 'false' for hard_mode as parameters, in any order.", function(command)
local player = game.get_player(command.player_index)
if player.admin == true then
local params = command.parameter and command.parameter:split(" ")
local seed, hard_mode_str
if params then
for _, param in ipairs(params) do
if tonumber(param) then
seed = tonumber(param)
elseif param == "true" or param == "false" then
hard_mode_str = param
else
player.print(string.format("[color=red]Invalid parameter: %s[/color]", param))
return
end
end
end
-- Handle the seed
if seed then
if seed > 0 and seed < 4294967296 then
global.reset_seed = seed
else
player.print("Invalid seed value. Seed must be between 1 and 4294967295.")
return
end
else
global.reset_seed = math.random(1111, 4294967295)
end
-- Handle the hard_mode
if hard_mode_str then
if hard_mode_str == "true" then
global.hard_mode = true
elseif hard_mode_str == "false" then
global.hard_mode = false
else
player.print("Invalid hard_mode value. Must be 'true' or 'false'.")
return
end
end
reset(string.format("%s has manually forced a reset.", player.name))
end
end)
-- Utility function to split a string by a delimiter
function string:split(delimiter)
local result = {}
for match in (self..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
return reset_controller