mirror of
https://github.com/a-bad-dev/simple-shooter-game.git
synced 2026-06-08 20:12:11 +00:00
quick and hacky way to automatically start matches
This commit is contained in:
parent
23a4c7d6bb
commit
bb6bc192e9
3 changed files with 54 additions and 33 deletions
|
|
@ -118,49 +118,51 @@ 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("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")
|
||||
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(3, function() -- add a few seconds to allow the map to be placed fully
|
||||
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
|
||||
local player_name = player:get_player_name()
|
||||
inv = player:get_inventory()
|
||||
|
||||
inv:set_list("main", {})
|
||||
|
||||
set_player_mode(player, "pre_match")
|
||||
give_player_items(player)
|
||||
|
||||
player:set_properties({
|
||||
pointable = true, -- allow players to be killable after the match starts
|
||||
})
|
||||
alive_players[player_name] = "alive"
|
||||
player:set_pos({x = map_data.spawn_x, y = map_data.spawn_y, z = map_data.spawn_z})
|
||||
|
||||
set_player_mode(player, "normal")
|
||||
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 = {}
|
||||
|
||||
for _, player in pairs(core.get_connected_players()) do
|
||||
local player_name = player:get_player_name()
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
-- Main mod for SSG
|
||||
|
||||
-- Variables
|
||||
automatic_start = {true, false}
|
||||
alive_players = {}
|
||||
map_data = {}
|
||||
spawn_pos = vector.new(-100, -9.6, -100)
|
||||
|
|
@ -32,6 +33,24 @@ core.register_on_mods_loaded(function()
|
|||
end
|
||||
end)
|
||||
|
||||
core.register_globalstep(function() -- automatically start a match every 30s
|
||||
if (not automatic_start[1]) or automatic_start[2] then
|
||||
return
|
||||
end
|
||||
|
||||
local players = 0
|
||||
for _, _ in ipairs(core.get_connected_players()) do
|
||||
players = players + 1
|
||||
end
|
||||
if players > 1 and match_state == "not_started" then
|
||||
core.chat_send_all(core.colorize("lime", "-!- Automatically starting new match in 30 seconds"))
|
||||
automatic_start[2] = true
|
||||
core.after(30, function()
|
||||
start_match("forest")
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
core.place_schematic({x=-105, y=-10, z=-108}, core.get_modpath("main") .. "/schems/spawn.mts", 0, nil, true)
|
||||
player:set_pos(spawn_pos)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ local map_data = {
|
|||
scripts = { -- "temporary" hack to ensure there's nothing on top of the map
|
||||
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_barrier_remove = "",
|
||||
on_end = ""
|
||||
on_end = "automatic_start[2] = false"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue