When the queue is full, its timer decreases to 5s (if it's not lower already)
This commit is contained in:
parent
7e3692896b
commit
4300dd618f
83
signs.lua
83
signs.lua
@ -22,14 +22,14 @@ minetest.override_item("default:sign_wall", {
|
||||
local p_name = puncher:get_player_name()
|
||||
|
||||
if not sign_arena then return end -- nel caso qualche cartello dovesse buggarsi, si può rompere e non fa crashare
|
||||
|
||||
|
||||
-- se non è abilitata
|
||||
if not sign_arena.enabled then
|
||||
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] The arena is not enabled!")))
|
||||
return end
|
||||
|
||||
|
||||
-- se l'arena è piena
|
||||
if sign_arena.players_amount == sign_arena.max_players then
|
||||
if sign_arena.players_amount == sign_arena.max_players and arena_lib.get_queueID_by_player(p_name) ~= arenaID then
|
||||
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] The arena is already full!")))
|
||||
return end
|
||||
|
||||
@ -48,7 +48,7 @@ minetest.override_item("default:sign_wall", {
|
||||
|
||||
local queued_mod = arena_lib.get_mod_by_player(p_name)
|
||||
local queued_ID = arena_lib.get_queueID_by_player(p_name)
|
||||
|
||||
|
||||
-- se la coda è la stessa rimuovo il giocatore...
|
||||
if queued_mod == mod and queued_ID == arenaID then
|
||||
arena_lib.send_message_players_in_arena(sign_arena, minetest.colorize("#d69298", sign_arena.name .. " < " .. p_name))
|
||||
@ -57,72 +57,72 @@ minetest.override_item("default:sign_wall", {
|
||||
arena_lib.update_sign(pos, sign_arena)
|
||||
arena_lib.remove_from_queue(p_name)
|
||||
arena_lib.HUD_hide("all", p_name)
|
||||
|
||||
|
||||
local players_in_arena = sign_arena.players_amount
|
||||
|
||||
|
||||
-- ...e annullo la coda se non ci sono più abbastanza persone
|
||||
if players_in_arena < sign_arena.min_players and sign_arena.in_queue then
|
||||
minetest.get_node_timer(pos):stop()
|
||||
arena_lib.HUD_hide("broadcast", sign_arena)
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
" (" .. sign_arena.min_players - players_in_arena .. ")")
|
||||
arena_lib.send_message_players_in_arena(sign_arena, mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
|
||||
sign_arena.in_queue = false
|
||||
|
||||
|
||||
-- (se la situazione è rimasta invariata, devo comunque aggiornare il numero giocatori nella hotbar)
|
||||
elseif players_in_arena < sign_arena.min_players then
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
" (" .. sign_arena.min_players - players_in_arena .. ")")
|
||||
else
|
||||
local seconds = math.floor(minetest.get_node_timer(pos):get_timeout() + 0.5)
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("@1 seconds for the match to start", seconds)))
|
||||
end
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
else
|
||||
|
||||
|
||||
local old_mod_ref = arena_lib.mods[queued_mod]
|
||||
local old_arena = old_mod_ref.arenas[queued_ID]
|
||||
|
||||
|
||||
-- sennò lo rimuovo dalla precedente e continuo per aggiungerlo in questa...
|
||||
old_arena.players[p_name] = nil
|
||||
old_arena.players_amount = old_arena.players_amount -1
|
||||
arena_lib.remove_from_queue(p_name)
|
||||
arena_lib.update_sign(old_arena.sign, old_arena)
|
||||
arena_lib.send_message_players_in_arena(old_arena, minetest.colorize("#d69298", sign_arena.name .. " < " .. p_name))
|
||||
|
||||
|
||||
local players_in_arena = old_arena.players_amount
|
||||
|
||||
|
||||
-- ...annullando la coda della precedente se non ci sono più abbastanza giocatori
|
||||
if players_in_arena < old_arena.min_players and old_arena.in_queue then
|
||||
minetest.get_node_timer(old_arena.sign):stop()
|
||||
arena_lib.HUD_hide("broadcast", old_arena)
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, S("Waiting for more players...")) ..
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, S("Waiting for more players...")) ..
|
||||
" (" .. old_arena.min_players - players_in_arena .. ")")
|
||||
arena_lib.send_message_players_in_arena(old_arena, old_mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
|
||||
old_arena.in_queue = false
|
||||
|
||||
|
||||
-- (se la situazione è rimasta invariata, devo comunque aggiornare il numero giocatori nella hotbar)
|
||||
elseif players_in_arena < old_arena.min_players and not old_arena.in_queue then
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, S("Waiting for more players...")) ..
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, S("Waiting for more players...")) ..
|
||||
" (" .. old_arena.min_players - players_in_arena .. ")")
|
||||
else
|
||||
local seconds = math.floor(minetest.get_node_timer(pos):get_timeout() + 0.5)
|
||||
arena_lib.HUD_send_msg_all("hotbar", old_arena, arena_display_format(old_arena, S("@1 seconds for the match to start", seconds)))
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- aggiungo il giocatore ed eventuali proprietà
|
||||
sign_arena.players[p_name] = {kills = 0, deaths = 0}
|
||||
sign_arena.players_amount = sign_arena.players_amount +1
|
||||
|
||||
|
||||
for k, v in pairs(mod_ref.player_properties) do
|
||||
sign_arena.players[p_name][k] = v
|
||||
end
|
||||
|
||||
|
||||
-- aggiorno il cartello
|
||||
arena_lib.update_sign(pos, sign_arena)
|
||||
|
||||
@ -137,31 +137,31 @@ minetest.override_item("default:sign_wall", {
|
||||
end
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
|
||||
|
||||
local players_in_arena = sign_arena.players_amount
|
||||
|
||||
-- se ci sono abbastanza giocatori e la coda non è partita...
|
||||
if not sign_arena.in_queue and not sign_arena.in_game then
|
||||
|
||||
local players_in_arena = sign_arena.players_amount
|
||||
|
||||
|
||||
-- ...parte il timer d'attesa
|
||||
if players_in_arena == sign_arena.min_players then
|
||||
sign_arena.in_queue = true
|
||||
timer:start(mod_ref.queue_waiting_time)
|
||||
HUD_countdown(sign_arena, mod_ref.queue_waiting_time)
|
||||
|
||||
HUD_countdown(sign_arena, timer)
|
||||
|
||||
-- sennò aggiorno semplicemente la HUD
|
||||
elseif players_in_arena < sign_arena.min_players then
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
arena_lib.HUD_send_msg_all("hotbar", sign_arena, arena_display_format(sign_arena, S("Waiting for more players...")) ..
|
||||
" (" .. sign_arena.min_players - players_in_arena .. ")")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- se raggiungo i giocatori massimi e la partita non è iniziata, parte subito
|
||||
|
||||
-- se raggiungo i giocatori massimi e la partita non è iniziata, accorcio eventualmente la durata
|
||||
if players_in_arena == sign_arena.max_players and sign_arena.in_queue then
|
||||
timer:stop()
|
||||
timer:start(0.01)
|
||||
if timer:get_timeout() > 5 then
|
||||
timer:stop()
|
||||
timer:start(5)
|
||||
end
|
||||
end
|
||||
|
||||
end,
|
||||
@ -232,19 +232,22 @@ end
|
||||
---------------FUNZIONI LOCALI----------------
|
||||
----------------------------------------------
|
||||
|
||||
function HUD_countdown(arena, seconds)
|
||||
if not arena.in_queue or seconds == 0 then return end
|
||||
|
||||
-- dai 3 secondi in giù il messaggio è stampato su broadcast
|
||||
function HUD_countdown(arena, timer)
|
||||
|
||||
if not arena.in_queue or not timer:is_started() then return end
|
||||
|
||||
local seconds = math.floor(timer:get_timeout() - timer:get_elapsed() + 0.5)
|
||||
|
||||
-- dai 5 secondi in giù il messaggio è stampato su broadcast
|
||||
if seconds <= 5 then
|
||||
arena_lib.HUD_send_msg_all("broadcast", arena, S("The game begins in @1 seconds!", seconds), nil, "arenalib_countdown")
|
||||
arena_lib.HUD_send_msg_all("hotbar", arena, arena_display_format(arena, S("Get ready!")))
|
||||
else
|
||||
arena_lib.HUD_send_msg_all("hotbar", arena, arena_display_format(arena, S("@1 seconds for the match to start", seconds)))
|
||||
end
|
||||
|
||||
|
||||
minetest.after(1, function()
|
||||
HUD_countdown(arena, seconds-1)
|
||||
HUD_countdown(arena, timer)
|
||||
end)
|
||||
end
|
||||
|
||||
@ -269,7 +272,7 @@ function in_game_txt(arena)
|
||||
elseif arena.in_celebration then txt = "Terminating"
|
||||
elseif arena.in_loading then txt = "Loading"
|
||||
elseif arena.in_game then txt = "In progress"
|
||||
|
||||
|
||||
else txt = "Waiting" end
|
||||
|
||||
return txt
|
||||
|
Loading…
x
Reference in New Issue
Block a user