diff --git a/mods/game/chatcommands/init.lua b/mods/game/chatcommands/init.lua index 4a0de63..b14226b 100644 --- a/mods/game/chatcommands/init.lua +++ b/mods/game/chatcommands/init.lua @@ -1,9 +1,9 @@ -- Chatcommands for SSG -core.register_chatcommand("load", { +core.register_chatcommand("start", { params = "", privs = {match_manager = true}, - description = "Load a map", + description = "Start a match on ", func = function(_, param) if not param or param == "" then return false, "-!- You must specify a map name!" @@ -12,19 +12,8 @@ core.register_chatcommand("load", { if match_state == "pre_match" or match_state == "post_match" or match_state == "in_progress" then return false, "-!- Match is already in progress!" end - - map_data = place_map(param) - - return true, "-!- Map loaded!" - end -}) - -core.register_chatcommand("start", { - params = "", - privs = {match_manager = true}, - description = "Start the match", - func = function() - start_match() + + start_match(param) return true, "-!- Match started!" end }) diff --git a/mods/game/functions/init.lua b/mods/game/functions/init.lua index d2ef38f..c5de023 100644 --- a/mods/game/functions/init.lua +++ b/mods/game/functions/init.lua @@ -108,16 +108,18 @@ function set_player_mode(player, mode) -- Set player mode (spectator, pre-match, core.change_player_privs(player_name, privs) end -function start_match() -- Start the match +function start_match(map) -- Start the match if match_state ~= "not_started" then return end set_match_state("pre_match") - map_data = place_map(map_data.name or "forest") -- default to forest if no map is specified + map_data = place_map(map or "forest") -- default to forest if no map is specified - core.chat_send_all(core.colorize("green", "Match about to start in 30 seconds!\nOpen inventory to change class!")) + assert(loadstring(map_data.scripts.on_start or ""))() + + core.chat_send_all(core.colorize("green", string.format("Match about to start in %d seconds!\nOpen inventory to change class!", map_data.start_time))) for _, player in pairs(core.get_connected_players()) do set_player_mode(player, "pre_match") @@ -129,12 +131,12 @@ function start_match() -- Start the match end for i = 10, 1, -1 do -- count down from 10 to 1 (yes you are free to set me on fire for this horrible solution) - core.after(20 + i, function() - core.chat_send_all(core.colorize("green", "Match starts in " .. (11 - i) .. " seconds.")) + core.after(map_data.start_time - 10 + i, function() + core.chat_send_all(core.colorize("green", string.format("Match starts in %d second%s.", (11 - i), 11 - i == 1 and "" or "s"))) -- <-- RIP readability end) end - core.after(30, function() + core.after(map_data.start_time, function() set_match_state("in_progress") core.chat_send_all(core.colorize("green", "Match started!")) @@ -223,6 +225,8 @@ function kill_player(player, reason) -- Handle killed/disconnected players prope if #alive_player_names == 1 then local winner_name = alive_player_names[1] core.chat_send_all(core.colorize("green", winner_name .. " is the winner!")) + + assert(loadstring(map_data.scripts.on_end or ""))() set_match_state("post_match") diff --git a/mods/game/maps/README.md b/mods/game/maps/README.md index 374f5c2..8bf3fc5 100644 --- a/mods/game/maps/README.md +++ b/mods/game/maps/README.md @@ -40,7 +40,15 @@ local map_data = { spawn_x = nil, spawn_y = nil, - spawn_z = nil + spawn_z = nil, + + start_time = (Amount of time in seconds before the barrier is removed) + + scripts = { + on_start = "(Lua script to be run after /start is run, leave blank unless you know what you are doing!)", + on_barrier_remove = "(Lua script to be run after the barrier is removed, leave blank unless you know what you are doing!)", + on_end = "(Lua script to be run after the match has ended, leave blank unless you know what you are doing!)" + } } return map_data diff --git a/mods/game/maps/init.lua b/mods/game/maps/init.lua index f98ede4..a9baa89 100644 --- a/mods/game/maps/init.lua +++ b/mods/game/maps/init.lua @@ -13,6 +13,10 @@ function place_map(map) map_data.spawn_z = map_data.size_z / 2 end + if map_data.start_time == nil or map_data.start_time <= 0 then + map_data.start_time = 30 + end + return map_data end @@ -21,6 +25,7 @@ function remove_barrier(x, y, z) for node_z = 1, z - 2 do core.set_node({x = node_x, y = y - 1, z = node_z}, {name = "air"}) -- account for the fact that lua counts starting at 1... i think.... whatever, it works \_('_')_/ end - end + end + assert(loadstring(map_data.scripts.on_barrier_remove or ""))() return "" end diff --git a/mods/game/maps/maps/forest-2/map.lua b/mods/game/maps/maps/forest-2/map.lua index 8f3435e..d7fa691 100644 --- a/mods/game/maps/maps/forest-2/map.lua +++ b/mods/game/maps/maps/forest-2/map.lua @@ -8,7 +8,15 @@ local map_data = { spawn_x = nil, spawn_y = nil, - spawn_z = nil + spawn_z = nil, + + start_time = 45, + + scripts = { + on_start = "", + on_barrier_remove = "", + on_end = "" + } } return map_data diff --git a/mods/game/maps/maps/forest-3/map.lua b/mods/game/maps/maps/forest-3/map.lua new file mode 100644 index 0000000..358aa38 --- /dev/null +++ b/mods/game/maps/maps/forest-3/map.lua @@ -0,0 +1,22 @@ +local map_data = { + name = "forest-3", + size_x = 537, + size_y = 142, + size_z = 244, + + barrier_level = 138, -- <- Y level of the barrier + + spawn_x = nil, + spawn_y = nil, + spawn_z = nil, + + start_time = 60, + + scripts = { + on_start = "", + on_barrier_remove = "", + on_end = "" + } +} + +return map_data diff --git a/mods/game/maps/maps/forest-3/map.mts b/mods/game/maps/maps/forest-3/map.mts new file mode 100644 index 0000000..35dc33f Binary files /dev/null and b/mods/game/maps/maps/forest-3/map.mts differ diff --git a/mods/game/maps/maps/forest/map.lua b/mods/game/maps/maps/forest/map.lua index 5533aae..72e7a27 100644 --- a/mods/game/maps/maps/forest/map.lua +++ b/mods/game/maps/maps/forest/map.lua @@ -8,7 +8,15 @@ local map_data = { spawn_x = nil, spawn_y = nil, - spawn_z = nil + spawn_z = nil, + + start_time = 30, + + scripts = { + on_start = "", + on_barrier_remove = "", + on_end = "" + } } return map_data diff --git a/mods/game/maps/maps/pine/map.lua b/mods/game/maps/maps/pine/map.lua index c422923..108fbb1 100644 --- a/mods/game/maps/maps/pine/map.lua +++ b/mods/game/maps/maps/pine/map.lua @@ -8,7 +8,15 @@ local map_data = { spawn_x = nil, spawn_y = nil, - spawn_z = nil + spawn_z = nil, + + start_time = 30, + + scripts = { + on_start = "", + on_barrier_remove = "", + on_end = "" + } } return map_data diff --git a/mods/game/maps/maps/savanna/map.lua b/mods/game/maps/maps/savanna/map.lua index 0b82dcc..1bb8814 100644 --- a/mods/game/maps/maps/savanna/map.lua +++ b/mods/game/maps/maps/savanna/map.lua @@ -8,7 +8,15 @@ local map_data = { spawn_x = nil, spawn_y = nil, - spawn_z = nil + spawn_z = nil, + + start_time = 45, + + scripts = { + on_start = "", + on_barrier_remove = "", + on_end = "" + } } return map_data