Add a lot of new stuff

This commit is contained in:
IonicCheese 2026-02-19 11:12:27 -08:00
commit 948040e47b
13 changed files with 163 additions and 141 deletions

View file

@ -28,7 +28,7 @@ core.register_chatcommand("stop", {
privs = {match_manager = true}, privs = {match_manager = true},
description = "Terminate the match", description = "Terminate the match",
func = function() func = function()
if match_state ~= "pre_match" and match_state ~= "post_match" and match_state ~= "not_started" then if match_state ~= "post_match" and match_state ~= "not_started" then
core.chat_send_all(core.colorize("red", "Match terminated.")) core.chat_send_all(core.colorize("red", "Match terminated."))
end_match() end_match()
@ -38,3 +38,17 @@ core.register_chatcommand("stop", {
return false, "Match cannot be terminated at the moment." return false, "Match cannot be terminated at the moment."
end end
}) })
core.register_chatcommand("list_maps", {
params = "",
privs = {match_manager = true},
description = "List all maps",
func = function()
local maps = core.get_dir_list(core.get_modpath("maps") .. "/maps", true)
local map_list = "Available maps:\n"
for _, map in pairs(maps) do
map_list = map_list .. map .. "\n"
end
return true, map_list .. "\nUse /start <map> to start a match."
end
})

View file

@ -1,3 +1,18 @@
match_start_job = nil
loading_tips = {
"Open the inventory to change class!",
"Short-range is good for small/dense maps!",
"Mid-range is good on maps with long tunnels or open areas!",
"Long-range is good for maps with really open and large areas!",
"Ambushing can be powerful assuming your not found!",
"Players may sneak up on you from behind!",
"You *can't* be shot under water!",
"The Short-range class can one-shot from 6 to 7 nodes away!",
"Using torches may allow enemies to sneak up on you in the dark!",
"Turns out if you get a sniper and zoom with it. you can zoom no matter what after that...", -- how
"e s p i o n a g e",
}
-- Functions for SSG -- Functions for SSG
function make_player_invisible(player) -- Hide a player (pre-match and spectator) function make_player_invisible(player) -- Hide a player (pre-match and spectator)
save_player_data(player) save_player_data(player)
@ -127,30 +142,45 @@ function start_match(map) -- Start the match
for _, player in pairs(core.get_connected_players()) do for _, player in pairs(core.get_connected_players()) do
set_player_mode(player, "pre_match") set_player_mode(player, "pre_match")
map_loading_images[player:get_player_name()] = player:hud_add({ map_loading_images[player:get_player_name()] = {
loading = player:hud_add({
type = "image", type = "image",
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
image_scale = 100, image_scale = 100,
text = "map_loading.png", text = "map_loading.png",
scale = {x=-100, y=-100}, scale = {x=-100, y=-100},
z_index = 1000, z_index = 1000,
}),
info = player:hud_add({
type = "text",
position = {x=0.5, y=0.7},
text = loading_tips[math.random(1, #loading_tips)],
number = 0xFFFFFF,
z_index = 1000,
}) })
}
give_player_items(player) give_player_items(player)
player:set_pos({x = map_data.spawn_x, y = map_data.spawn_y, z = map_data.spawn_z}) player:set_pos(map_data.spawn)
player:set_hp(20) player:set_hp(20)
end end
core.after(3, function() core.after(3, function()
for _, player in pairs(core.get_connected_players()) do for _, player in pairs(core.get_connected_players()) do
player:set_pos({x = map_data.spawn_x, y = map_data.spawn_y, z = map_data.spawn_z}) player:set_pos(map_data.spawn)
player:hud_remove(map_loading_images[player:get_player_name()])
for _, id in pairs(map_loading_images[player:get_player_name()]) do
player:hud_remove(id)
end
end end
assert(loadstring(map_data.scripts.on_start or ""))() if map_data.on_start then
map_data.on_start()
end
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))) 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)))
@ -160,11 +190,12 @@ function start_match(map) -- Start the match
end) end)
end end
core.after(map_data.start_time, function() match_start_job = core.after(map_data.start_time, function()
match_start_job = nil
set_match_state("in_progress") set_match_state("in_progress")
core.chat_send_all(core.colorize("green", "Match started!")) core.chat_send_all(core.colorize("green", "Match started!"))
remove_barrier(map_data.size_x, map_data.barrier_level, map_data.size_z) remove_barrier()
alive_players = {} alive_players = {}
@ -190,6 +221,14 @@ end
function end_match() -- End the match function end_match() -- End the match
set_match_state("not_started") set_match_state("not_started")
if match_start_job ~= nil then
match_start_job:cancel()
end
if map_data.on_end then
map_data.on_end()
end
for _, player in pairs(core.get_connected_players()) do for _, player in pairs(core.get_connected_players()) do
player:set_pos(spawn_pos) player:set_pos(spawn_pos)
player:get_inventory():set_list("main", {}) player:get_inventory():set_list("main", {})
@ -251,8 +290,6 @@ function kill_player(player, reason) -- Handle killed/disconnected players prope
local winner_name = alive_player_names[1] local winner_name = alive_player_names[1]
core.chat_send_all(core.colorize("green", winner_name .. " is the winner!")) 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") set_match_state("post_match")
core.after(5, end_match) core.after(5, end_match)

View file

@ -2,9 +2,11 @@
function place_map(map) function place_map(map)
local map_path = core.get_modpath("maps") .. "/maps/" local map_path = core.get_modpath("maps") .. "/maps/"
local map_list = core.get_dir_list(map_path, true) local map_list = core.get_dir_list(map_path, true)
local map_pos = vector.new(0, 0, 0)
for i = 1, #map_list do for i = 1, #map_list do
if map_list[i] == map then if map_list[i] == map then
map_pos = vector.new(1000 * (i - 1), 0, 0)
break break
elseif i == #map_list then elseif i == #map_list then
return "nope :(" return "nope :("
@ -12,12 +14,11 @@ function place_map(map)
end end
local map_data = dofile(map_path .. map .. "/map.lua") local map_data = dofile(map_path .. map .. "/map.lua")
core.place_schematic({x=0, y=0, z=0}, map_path .. map .. "/map.mts", 0, nil, true) map_data.pos = map_pos
core.place_schematic(map_pos, map_path .. map .. "/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 if not map_data.spawn then -- set a default spawnpoint if not set
map_data.spawn_x = map_data.size_x / 2 map_data.spawn = vector.new(map_data.size.x / 2, map_data.barrier_level + 1, map_data.size.z / 2) + map_pos
map_data.spawn_y = map_data.barrier_level + 1
map_data.spawn_z = map_data.size_z / 2
end end
if map_data.start_time == nil or map_data.start_time <= 0 then if map_data.start_time == nil or map_data.start_time <= 0 then
@ -50,12 +51,15 @@ function place_map(map)
return map_data return map_data
end end
function remove_barrier(x, y, z) function remove_barrier()
for node_x = 1, x - 2 do for node_x = 1, x - 2 do
for node_z = 1, z - 2 do 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 \_('_')_/ 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 end
assert(loadstring(map_data.scripts.on_barrier_remove or ""))() if map_data.on_barrier_remove then
map_data.on_barrier_remove()
end
return "" return ""
end end

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "1v1", name = "1v1",
size_x = 41, size = vector.new(41, 31, 38),
size_y = 31,
size_z = 38,
barrier_level = 27, barrier_level = 27,
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 15, start_time = 15,
scripts = { on_start = nil,
on_start = "for x=0, 40 do\nfor y=0, 17 do\nfor z=0, 37 do\ncore.set_node({x=x,y=31+y,z=z}, {name=\"default:glass\"})\nend\nend\nend", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "forest-2", name = "forest-2",
size_x = 189, size = vector.new(189, 71, 102),
size_y = 71,
size_z = 102,
barrier_level = 67, -- <- Y level of the barrier barrier_level = 67, -- <- Y level of the barrier
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 45, start_time = 45,
scripts = { -- "temporary" hack to ensure there's nothing on top of the map on_start = nil,
on_start = "for x=0, 188 do\nfor y=0, 4 do\nfor z=0, 101 do\ncore.set_node({x=x,y=71+y,z=z}, {name=\"air\"})\nend\nend\nend", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "forest-3", name = "forest-3",
size_x = 537, size = vector.new(537, 117, 244),
size_y = 117,
size_z = 244,
barrier_level = 113, -- <- Y level of the barrier barrier_level = 113, -- <- Y level of the barrier
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 60, start_time = 60,
scripts = { on_start = nil,
on_start = "", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -1,22 +1,16 @@
local map_data = { return {
name = "forest-4", name = "forest-4",
size_x = 190, size = vector.new(190, 69, 155),
size_y = 69,
size_z = 155,
barrier_level = 65, barrier_level = 65,
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 30, start_time = 30,
scripts = { on_start = nil,
on_start = "for x=0, 189 do\nfor y=0, 10 do\nfor z=0, 154 do\ncore.set_node({x=x,y=69+y,z=z}, {name=\"air\"})\nend\nend\nend", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
},
classes = { classes = {
class_1 = { class_1 = {
@ -35,5 +29,3 @@ local map_data = {
} }
} }
} }
return map_data

View file

@ -1,22 +1,16 @@
local map_data = { return {
name = "forest", name = "forest",
size_x = 155, size = vector.new(155, 53, 147),
size_y = 53,
size_z = 147,
barrier_level = 49, -- <- Y level of the barrier barrier_level = 49, -- <- Y level of the barrier
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 30, start_time = 30,
scripts = { -- "temporary" hack to ensure there's nothing on top of the map on_start = nil,
on_start = "for x=0, 154 do\nfor y=0, 16 do\nfor z=0, 146 do\ncore.set_node({x=x,y=53+y,z=z}, {name=\"air\"})\nend\nend\nend", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
},
classes = { classes = {
class_1 = { class_1 = {
@ -35,5 +29,3 @@ local map_data = {
} }
} }
} }
return map_data

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "mini-map", name = "mini-map",
size_x = 8, size = vector.new(8, 19, 8),
size_y = 19,
size_z = 8,
barrier_level = 15, barrier_level = 15,
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 15, start_time = 15,
scripts = { on_start = nil,
on_start = "", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "pine", name = "pine",
size_x = 111, size = vector.new(111, 64, 107),
size_y = 64,
size_z = 107,
barrier_level = 60, -- <- Y level of the barrier barrier_level = 60, -- <- Y level of the barrier
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 30, start_time = 30,
scripts = { on_start = nil,
on_start = "", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -1,22 +1,14 @@
local map_data = { return {
name = "savanna", name = "savanna",
size_x = 341, size = vector.new(341, 83, 188),
size_y = 83,
size_z = 188,
barrier_level = 79, -- <- Y level of the barrier barrier_level = 79, -- <- Y level of the barrier
spawn_x = nil, spawn = nil,
spawn_y = nil,
spawn_z = nil,
start_time = 45, start_time = 45,
scripts = { on_start = nil,
on_start = "", on_end = nil,
on_barrier_remove = "", on_barrier_remove = nil,
on_end = ""
} }
}
return map_data

View file

@ -0,0 +1,31 @@
return {
name = "snow",
size = vector.new(267, 100, 335),
barrier_level = 97, -- <- Y level of the barrier
spawn = nil,
start_time = 45,
on_start = nil,
on_end = nil,
on_barrier_remove = nil,
classes = {
class_1 = {
name = "Long-range",
initial_items = {"ctf_ranged:m200_loaded", "default:sword_stone", "ctf_ranged:ammo 99", "default:torch 1"}
},
class_2 = {
name = "Mid-ranged",
initial_items = {"ctf_ranged:ak47_loaded", "ctf_ranged:glock17_loaded", "ctf_ranged:ammo 99", "default:torch 1"}
},
class_3 = {
name = "Short-range",
initial_items = {"ctf_ranged:benelli_loaded", "ctf_ranged:glock17_loaded", "ctf_ranged:ammo 99", "default:torch 1"}
}
}
}

Binary file not shown.