mirror of
https://github.com/a-bad-dev/simple-shooter-game.git
synced 2026-06-08 20:12:11 +00:00
Misc fixes
- Prevent players from falling through the barrier before the match starts - Prevent the server from crashing if you try to start a non-existant map
This commit is contained in:
parent
1b4903fe22
commit
2c09090a91
4 changed files with 61 additions and 32 deletions
|
|
@ -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
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
BIN
mods/game/functions/textures/map_loading.png
Normal file
BIN
mods/game/functions/textures/map_loading.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 360 KiB |
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue