diff --git a/mods/game/chatcommands/init.lua b/mods/game/chatcommands/init.lua index 52d8afb..3dfd1d0 100644 --- a/mods/game/chatcommands/init.lua +++ b/mods/game/chatcommands/init.lua @@ -13,7 +13,12 @@ core.register_chatcommand("start", { return false, "-!- Match is already in progress!" end - start_match(param) + local sucess = start_match(param) + + if map_data == "nope :(" then + return false, "-!- Map not found!" + end + return true, "-!- Match started!" end }) diff --git a/mods/game/functions/init.lua b/mods/game/functions/init.lua index da201d6..f6c8db1 100644 --- a/mods/game/functions/init.lua +++ b/mods/game/functions/init.lua @@ -118,49 +118,71 @@ function start_match(map) -- Start the match set_match_state("pre_match") map_data = place_map(map or "forest") -- default to forest if no map is specified - - assert(loadstring(map_data.scripts.on_start or ""))() - - core.chat_send_all(core.colorize("#b011f9", string.format("Match about to start in %d seconds!\nOpen inventory to change class!", map_data.start_time))) + if map_data == "nope :(" then + return map_data + end + + local map_loading_images = {} for _, player in pairs(core.get_connected_players()) do set_player_mode(player, "pre_match") + + map_loading_images[player:get_player_name()] = player:hud_add({ + type = "image", + position = {x=0.5, y=0.5}, + image_scale = 100, + text = "map_loading.png", + scale = {x=-100, y=-100}, + }) + give_player_items(player) player:set_pos({x = map_data.spawn_x, y = map_data.spawn_y, z = map_data.spawn_z}) player:set_hp(20) 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(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(map_data.start_time, function() - set_match_state("in_progress") - core.chat_send_all(core.colorize("green", "Match started!")) - remove_barrier(map_data.size_x, map_data.barrier_level, map_data.size_z) - - alive_players = {} - + core.after(5, function() for _, player in pairs(core.get_connected_players()) do - local player_name = player:get_player_name() - local inv = player:get_inventory() - - inv:set_list("main", {}) - - give_player_items(player) - - player:set_properties({ - pointable = true, -- allow players to be killable after the match starts - }) - alive_players[player_name] = "alive" - - set_player_mode(player, "normal") + player:set_pos({x = map_data.spawn_x, y = map_data.spawn_y, z = map_data.spawn_z}) + player:hud_remove(map_loading_images[player:get_player_name()]) end + + + assert(loadstring(map_data.scripts.on_start or ""))() + + core.chat_send_all(core.colorize("#b011f9", string.format("Match about to start in %d seconds!\nOpen inventory to change class!", map_data.start_time))) + + 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(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(map_data.start_time, function() + set_match_state("in_progress") + core.chat_send_all(core.colorize("green", "Match started!")) + + remove_barrier(map_data.size_x, map_data.barrier_level, map_data.size_z) + + alive_players = {} + + for _, player in pairs(core.get_connected_players()) do + local player_name = player:get_player_name() + local inv = player:get_inventory() + + inv:set_list("main", {}) + + give_player_items(player) + + player:set_properties({ + pointable = true, -- allow players to be killable after the match starts + }) + alive_players[player_name] = "alive" + + set_player_mode(player, "normal") + end + end) end) end diff --git a/mods/game/functions/textures/map_loading.png b/mods/game/functions/textures/map_loading.png new file mode 100644 index 0000000..f3695b8 Binary files /dev/null and b/mods/game/functions/textures/map_loading.png differ diff --git a/mods/game/maps/init.lua b/mods/game/maps/init.lua index 3770041..1b31321 100644 --- a/mods/game/maps/init.lua +++ b/mods/game/maps/init.lua @@ -1,11 +1,13 @@ -- Maps mod for SSG function place_map(map) - local map_path = core.get_modpath("maps") .. "/maps/" - local map_data = dofile(map_path .. map .. "/map.lua") - local barrier_nodes = {} + local map_path = core.get_modpath("maps") .. "/maps/" .. map .. "/" - - core.place_schematic({x=0, y=0, z=0}, map_path .. map .. "/map.mts", 0, nil, true) + if not core.path_exists(map_path) then + return "nope :(" + end + + local map_data = dofile(map_path .. "map.lua") + core.place_schematic({x=0, y=0, z=0}, map_path .. "map.mts", 0, nil, true) if map_data.spawn_x == nil or map_data.spawn_y == nil or map_data.spawn_z == nil then -- set a default spawnpoint if not set map_data.spawn_x = map_data.size_x / 2