Teams implemented

This commit is contained in:
Zughy 2020-06-05 12:31:44 +02:00
commit e92febfedb
13 changed files with 647 additions and 97 deletions

View File

@ -13,7 +13,8 @@ minetest.register_tool("arena_lib:editor_spawners", {
on_use = function(itemstack, user)
user:get_meta():set_int("arena_lib_editor.spawner_ID", 1)
user:get_meta():set_int("arena_lib_editor.team_ID", 1)
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Spawners | sel. ID: @1 (right click slot #2 to change)", 1))
minetest.after(0, function()

View File

@ -1,11 +1,11 @@
local S = minetest.get_translator("arena_lib")
local spawners_tools_team = {
"arena_lib:spawner_add",
"arena_lib:spawner_team_add",
"arena_lib:spawner_team_remove",
"arena_lib:spawner_team_switch",
"",
"cambia team",
"cancella per team",
"arena_lib:spawner_deleteall",
"",
"arena_lib:spawner_team_deleteall",
"arena_lib:editor_return",
"arena_lib:editor_quit",
}
@ -54,7 +54,7 @@ minetest.register_tool("arena_lib:spawner_remove", {
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local spawner_ID = user:get_meta():get_int("arena_lib_editor.spawner_ID")
arena_lib.set_spawner(user:get_player_name(), mod, arena_name, "delete", spawner_ID)
arena_lib.set_spawner(user:get_player_name(), mod, arena_name, nil, "delete", spawner_ID)
end,
@ -65,7 +65,7 @@ minetest.register_tool("arena_lib:spawner_remove", {
local spawner_ID = placer:get_meta():get_int("arena_lib_editor.spawner_ID")
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
if spawner_ID >= #arena.spawn_points then
if spawner_ID >= table.maxn(arena.spawn_points) then
spawner_ID = 1
else
spawner_ID = spawner_ID +1
@ -79,6 +79,99 @@ minetest.register_tool("arena_lib:spawner_remove", {
minetest.register_tool("arena_lib:spawner_team_add", {
description = S("Add team spawner"),
inventory_image = "arenalib_tool_spawner_team_add.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local team_ID = user:get_meta():get_int("arena_lib_editor.team_ID")
arena_lib.set_spawner(user:get_player_name(), mod, arena_name, team_ID)
end
})
minetest.register_tool("arena_lib:spawner_team_remove", {
description = S("Remove team spawner"),
inventory_image = "arenalib_tool_spawner_team_remove.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local spawner_ID = user:get_meta():get_int("arena_lib_editor.spawner_ID")
local team_ID = user:get_meta():get_int("arena_lib_editor.team_ID")
arena_lib.set_spawner(user:get_player_name(), mod, arena_name, nil, "delete", spawner_ID)
end,
on_place = function(itemstack, placer, pointed_thing)
local mod = placer:get_meta():get_string("arena_lib_editor.mod")
local arena_name = placer:get_meta():get_string("arena_lib_editor.arena")
local spawner_ID = placer:get_meta():get_int("arena_lib_editor.spawner_ID")
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
if spawner_ID >= table.maxn(arena.spawn_points) then
spawner_ID = 1
else
spawner_ID = spawner_ID +1
end
placer:get_meta():set_int("arena_lib_editor.spawner_ID", spawner_ID)
arena_lib.HUD_send_msg("hotbar", placer:get_player_name(), S("Spawners | sel. ID: @1 (right click slot #2 to change)", spawner_ID))
end
})
minetest.register_tool("arena_lib:spawner_team_switch", {
description = S("Switch team"),
inventory_image = "arenalib_tool_spawner_team_switch.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local team_ID = user:get_meta():get_int("arena_lib_editor.team_ID")
local mod_ref = arena_lib.mods[mod]
if team_ID >= table.maxn(mod_ref.teams) then
team_ID = 1
else
team_ID = team_ID +1
end
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
minetest.chat_send_player(user:get_player_name(), S("Selected team: @1", mod_ref.teams[team_ID]))
user:get_meta():set_int("arena_lib_editor.team_ID", team_ID)
user:get_meta():set_int("arena_lib_editor.spawner_ID", 1)
end
})
minetest.register_tool("arena_lib:spawner_deleteall", {
description = S("Delete all spawners"),
@ -93,8 +186,29 @@ minetest.register_tool("arena_lib:spawner_deleteall", {
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local p_name = user:get_player_name()
arena_lib.set_spawner(p_name, mod, arena_name, "deleteall")
minetest.chat_send_player(user:get_player_name(), S("All the spawn points has been removed"))
arena_lib.set_spawner(p_name, mod, arena_name, nil, "deleteall")
end
})
minetest.register_tool("arena_lib:spawner_team_deleteall", {
description = S("Delete all spawners of the team"),
inventory_image = "arenalib_tool_spawner_team_deleteall.png",
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
on_place = function() end,
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
local mod = user:get_meta():get_string("arena_lib_editor.mod")
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
local team_ID = user:get_meta():get_int("arena_lib_editor.team_ID")
local p_name = user:get_player_name()
arena_lib.set_spawner(p_name, mod, arena_name, team_ID, "deleteall")
end
})

410
api.lua
View File

@ -14,6 +14,7 @@ local function init_storage() end
local function update_storage() end
local function copy_table() end
local function next_available_ID() end
local function assign_team_spawner() end
local function timer_start() end
local players_in_game = {} --KEY: player name, INDEX: {(string) minigame, (int) arenaID}
@ -23,8 +24,10 @@ local arena_default = {
name = "",
sign = {},
players = {}, --KEY: player name, INDEX: kills, deaths, player_properties
teams = nil,
players_amount = 0,
spawn_points = {},
players_amount_per_team = nil,
spawn_points = {}, --KEY: ids, INDEX: {position, team}
max_players = 4,
min_players = 2,
in_queue = false,
@ -78,6 +81,7 @@ function arena_lib.register_minigame(mod, def)
mod_ref.properties = {}
mod_ref.temp_properties = {}
mod_ref.player_properties = {}
mod_ref.team_properties = {}
if def.prefix then
mod_ref.prefix = def.prefix
@ -146,6 +150,10 @@ function arena_lib.register_minigame(mod, def)
mod_ref.player_properties = def.player_properties
end
if def.team_properties then
mod_ref.team_properties = def.team_properties
end
init_storage(mod, mod_ref)
end
@ -209,12 +217,31 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player
arena.max_players = max_players
end
-- aggiungo le proprietà custom
-- eventuali team
if next(mod_ref.teams) then
arena.teams = {}
arena.players_amount_per_team = {}
for k, t_name in pairs(mod_ref.teams) do
arena.teams[k] = {name = t_name}
arena.players_amount_per_team[k] = 0
-- e loro eventuali proprietà
for j, w in pairs(mod_ref.team_properties) do
arena.teams[k][j] = w
end
end
else
arena.teams = {-1}
end
-- aggiungo eventuali proprietà custom
for property, value in pairs(mod_ref.properties) do
arena[property] = value
end
-- e quelle temp custom
-- temp custom
for temp_property, value in pairs(mod_ref.temp_properties) do
arena[temp_property] = value
end
@ -263,12 +290,30 @@ end
-- Gli spawn points si impostano prendendo la coordinata del giocatore che lancia il comando.
-- Non ci possono essere più spawn points del numero massimo di giocatori.
-- 'param' può essere: "overwrite", "delete", "deleteall"
function arena_lib.set_spawner(sender, mod, arena_name, param, ID)
function arena_lib.set_spawner(sender, mod, arena_name, teamID_or_name, param, ID)
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
local mod_ref = arena_lib.mods[mod]
local team
local team_ID
if teamID_or_name then
if type(teamID_or_name) == "number" then
team_ID = teamID_or_name
team = mod_ref.teams[teamID_or_name]
elseif type(teamID_or_name) == "string" then
team = teamID_or_name
end
-- controllo team
if not arena_lib.is_team_declared(mod_ref, team) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] This team doesn't exist!")))
return end
end
local pos = vector.floor(minetest.get_player_by_name(sender):get_pos()) -- tolgo i decimali per immagazzinare un int
local pos_Y_up = {x = pos.x, y = pos.y+1, z = pos.z} -- alzo Y di uno sennò tippa nel blocco
local mod_ref = arena_lib.mods[mod]
@ -278,27 +323,49 @@ function arena_lib.set_spawner(sender, mod, arena_name, param, ID)
-- se overwrite, sovrascrivo
if param == "overwrite" then
-- se lo spawner da sovrascrivere non esiste, annullo
if arena.spawn_points[ID] == nil then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] No spawner with that ID to overwrite!")))
return end
-- è inutile specificare un team. Avviso per non confondere
if team then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] No team must be specified for this function!")))
return end
arena.spawn_points[ID] = pos_Y_up
-- se lo spawner da sovrascrivere non esiste, annullo
if arena.spawn_points[ID].pos == nil then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] No spawner with that ID to overwrite!")))
return end
arena.spawn_points[ID].pos = pos_Y_up
minetest.chat_send_player(sender, mod_ref.prefix .. S("Spawn point #@1 successfully overwritten", ID))
-- se delete, cancello
elseif param == "delete" then
-- è inutile specificare un team. Avviso per non confondere
if team then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] No team must be specified for this function!")))
return end
if arena.spawn_points[ID] == nil then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] No spawner with that ID to delete!")))
return end
return end
table.remove(arena.spawn_points, ID)
--TODO: switch migliore dato che ci stanno dentro anche i team
arena.spawn_points[ID] = nil
minetest.chat_send_player(sender, mod_ref.prefix .. S("Spawn point #@1 successfully deleted", ID))
-- se deleteall, li cancello tutti
elseif param == "deleteall" then
arena.spawn_points = {}
if team then
for id, spawner in pairs(arena.spawn_points) do
if spawner.team == team then
arena.spawn_points[id] = nil
end
end
minetest.chat_send_player(sender, S("All the spawn points belonging to team @1 have been removed", team))
else
arena.spawn_points = {}
minetest.chat_send_player(sender, S("All the spawn points have been removed"))
end
else
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Unknown parameter!")))
end
@ -307,23 +374,63 @@ function arena_lib.set_spawner(sender, mod, arena_name, param, ID)
-- sennò sto creando un nuovo spawner
local spawn_points_count = arena_lib.get_arena_spawners_count(arena)
-- se c'è già uno spawner in quel punto, annullo
for id, spawn in pairs(arena.spawn_points) do
if minetest.serialize(pos_Y_up) == minetest.serialize(spawn.pos) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There's already a spawn in this point!")))
return end
end
local spawn_points_count = arena_lib.get_arena_spawners_count(arena, team) -- (se team è nil, ritorna in automatico i punti spawn totali)
-- se provo a impostare uno spawn point di troppo, annullo
if spawn_points_count == arena.max_players then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Spawn points can't exceed the maximum number of players!")))
return end
-- se c'è già uno spawner in quel punto, annullo
for id, spawn in pairs(arena.spawn_points) do
if minetest.serialize(pos_Y_up) == minetest.serialize(spawn) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There's already a spawn in this point!")))
return end
local next_available_spawnID = 1
if team then
-- ottengo l'ID del team se non mi è stato passato come parametro
if type(team_ID) ~= "number" then
for i = 1, #arena.teams do
if arena.teams[i].name == team then
team_ID = i
end
end
end
-- prendo il primo spawner di quel team
next_available_spawnID = 1 + (arena.max_players * (team_ID -1))
-- se già esiste...
if arena.spawn_points[next_available_spawnID] then
-- ...itero tra gli spawner seguenti finché non ne trovo uno vuoto
while next(arena.spawn_points, next_available_spawnID) do
-- ma se il next mi trova uno spawner con distacco > 1, vuol dire che sono al capolinea
-- perché quello trovato appartiene o a un altro team o è un buco nello stesso team (ottenuto dal cancellare). Rompo l'iterare
if next(arena.spawn_points, i) ~= i+1 then
break
end
next_available_spawnID = next_available_spawnID +1
end
-- trovato quello vuoto, porto next_available_spawnID alla sua posizione (+1)
next_available_spawnID = next_available_spawnID +1
end
else
-- ottengo l'ID del prossimo spawner disponibile
for k, v in ipairs(arena.spawn_points) do
next_available_spawnID = k +1
end
end
-- sovrascrivo/creo lo spawnpoint
arena.spawn_points[spawn_points_count +1] = pos_Y_up
minetest.chat_send_player(sender, mod_ref.prefix .. S("Spawn point #@1 successfully set", spawn_points_count +1))
-- imposto lo spawner
arena.spawn_points[next_available_spawnID] = {pos = pos_Y_up, team = team}
minetest.chat_send_player(sender, mod_ref.prefix .. S("Spawn point #@1 successfully set", next_available_spawnID))
update_storage(false, mod, id, arena)
end
@ -421,8 +528,10 @@ function arena_lib.enable_arena(sender, mod, arena_name)
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
local arena_max_players = arena.max_players * #arena.teams
-- check requisiti: spawner
if arena_lib.get_arena_spawners_count(arena) < arena.max_players then
if arena_lib.get_arena_spawners_count(arena) < arena_max_players then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Insufficient spawners, the arena can't be enabled!")))
arena.enabled = false
return end
@ -468,18 +577,26 @@ function arena_lib.disable_arena(sender, mod, arena_name)
return end
-- se c'è gente rimasta è in coda: annullo la coda e li avviso della disabilitazione
for pl_name, stats in pairs(arena.players) do
if next(arena.players) then
for pl_name, stats in pairs(arena.players) do
arena_lib.HUD_hide("all", arena)
players_in_queue[pl_name] = nil
arena.players[pl_name] = nil
arena.in_queue = false
minetest.chat_send_player(pl_name, minetest.colorize("#e6482e", S("[!] The arena you were queueing for has been disabled... :(")))
arena_lib.HUD_hide("all", arena)
players_in_queue[pl_name] = nil
arena.players[pl_name] = nil
arena.in_queue = false
minetest.chat_send_player(pl_name, minetest.colorize("#e6482e", S("[!] The arena you were queueing for has been disabled... :(")))
end
-- svuoto l'arena
arena.players_amount = 0
if #arena.teams > 1 then
for k, v in pairs(arena.players_amount_per_team) do
arena.players_amount_per_team[k] = 0
end
end
end
arena.players_amount = 0
-- disabilito
arena.enabled = false
arena_lib.update_sign(arena.sign, arena)
@ -498,6 +615,13 @@ end
-- per tutti i giocatori quando finisce la coda
function arena_lib.load_arena(mod, arena_ID)
-- my child, let's talk about some black magic: in order to teleport players in their team spawners, first of all I need to
-- sort them by team. Once it's done, I need to skip every spawner of that team if the maximum number of players is not reached:
-- otherwise, people will find theirselves in the wrong team (and you don't want that to happen). So I use this int to prevent it,
-- which increases of 1 or more every time I look for a spawner, comparing the 'team' spawner value to the player's. This happens
-- in assign_team_spawner, which also returns the new value for team_count
local team_count = 1
local count = 1
local mod_ref = arena_lib.mods[mod]
local arena = mod_ref.arenas[arena_ID]
@ -506,13 +630,28 @@ function arena_lib.load_arena(mod, arena_ID)
arena_lib.update_sign(arena.sign, arena)
local shuffled_spawners = copy_table(arena.spawn_points)
local sorted_team_players = {}
-- randomizzo gli spawner
for i = #shuffled_spawners, 2, -1 do
local j = math.random(i)
shuffled_spawners[i], shuffled_spawners[j] = shuffled_spawners[j], shuffled_spawners[i]
-- randomizzo gli spawner se non è a team
if #arena.teams == 1 then
for i = #shuffled_spawners, 2, -1 do
local j = math.random(i)
shuffled_spawners[i], shuffled_spawners[j] = shuffled_spawners[j], shuffled_spawners[i]
end
-- sennò ordino i giocatori per team
else
local j = 1
for i = 1, #arena.teams do
for pl_name, pl_stats in pairs(arena.players) do
if pl_stats.teamID == i then
sorted_team_players[j] = {name = pl_name, team = arena.teams[pl_stats.teamID].name}
j = j +1
end
end
end
end
-- per ogni giocatore...
for pl_name, _ in pairs(arena.players) do
@ -534,7 +673,11 @@ function arena_lib.load_arena(mod, arena_ID)
})
-- teletrasporto i giocatori
player:set_pos(shuffled_spawners[count])
if #arena.teams == 1 then
player:set_pos(shuffled_spawners[count].pos)
else
team_count = assign_team_spawner(arena.spawn_points, team_count, sorted_team_players[count].name, sorted_team_players[count].team)
end
-- svuoto eventualmente l'inventario
if not mod_ref.keep_inventory then
@ -548,6 +691,7 @@ function arena_lib.load_arena(mod, arena_ID)
count = count +1
end
-- eventuale codice aggiuntivo
if mod_ref.on_load then
mod_ref.on_load(arena)
@ -615,7 +759,7 @@ function arena_lib.join_arena(mod, p_name, arena_ID)
player:get_inventory():set_list("main",{})
end
player:set_pos(arena_lib.get_random_spawner(arena))
player:set_pos(arena_lib.get_random_spawner(arena, p_name))
players_in_game[p_name] = {minigame = mod, arenaID = arena_ID}
-- eventuale codice aggiuntivo
@ -625,13 +769,23 @@ function arena_lib.join_arena(mod, p_name, arena_ID)
end
--a partita finita
-- a partita finita.
-- winner_name può essere stringa (no team) o tabella di nomi (team)
function arena_lib.load_celebration(mod, arena, winner_name)
local mod_ref = arena_lib.mods[mod]
local winning_message = ""
arena.in_celebration = true
arena_lib.update_sign(arena.sign, arena)
if type(winner_name) == "string" then
winning_message = S("@1 wins the game", winner_name)
elseif type(winner_name) == "table" then
local winner_team_ID = arena.players[winner_name[1]].teamID
winning_message = S("Team @1 wins the game", arena.teams[winner_team_ID].name)
end
for pl_name, stats in pairs(arena.players) do
@ -643,7 +797,7 @@ function arena_lib.load_celebration(mod, arena, winner_name)
end
minetest.get_player_by_name(pl_name):set_nametag_attributes({color = {a = 255, r = 255, g = 255, b = 255}})
minetest.chat_send_player(pl_name, mod_ref.prefix .. S("@1 wins the game", winner_name))
minetest.chat_send_player(pl_name, mod_ref.prefix .. winning_message)
end
-- eventuale codice aggiuntivo
@ -704,6 +858,21 @@ function arena_lib.end_arena(mod_ref, mod, arena)
arena[temp_property] = {}
end
end
-- e quelle eventuali di team
if #arena.teams > 1 then
for team_property, v in pairs(arena.team_properties) do
if type(v) == "string" then
arena[team_property] = ""
elseif type(v) == "number" then
arena[team_property] = 0
elseif type(v) == "boolean" then
arena[team_property] = false
elseif type(v) == "table" then
arena[team_property] = {}
end
end
end
local id = arena_lib.get_arena_by_name(mod, arena.name)
@ -767,8 +936,9 @@ function arena_lib.is_player_in_queue(p_name, mod)
if not players_in_queue[p_name] then
return false
else
-- se il campo mod è specificato, controllo che sia lo stesso
if mod ~= nil then
if mod then
if players_in_queue[p_name].minigame == mod then return true
else return false
end
@ -781,6 +951,20 @@ end
function arena_lib.is_team_declared(mod_ref, team_name)
if not mod_ref.teams then return false end
for _, t_name in pairs(mod_ref.teams) do
if team_name == t_name then
return true
end
end
return false
end
function arena_lib.remove_player_from_arena(p_name, reason)
-- reason 1 = has been eliminated
-- reason 2 = has been kicked
@ -804,11 +988,16 @@ function arena_lib.remove_player_from_arena(p_name, reason)
if arena == nil then return end
local p_team_ID = arena.players[p_name].teamID
-- lo rimuovo
arena.players[p_name] = nil
players_in_game[p_name] = nil
players_in_queue[p_name] = nil
arena.players_amount = arena.players_amount - 1
if #arena.teams > 1 then
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
end
arena_lib.update_sign(arena.sign, arena)
@ -857,16 +1046,40 @@ function arena_lib.remove_player_from_arena(p_name, reason)
-- se l'arena era in coda e ora ci son troppi pochi giocatori, annullo la coda
if arena.in_queue then
local timer = minetest.get_node_timer(arena.sign)
local arena_min_players = arena.min_players * #arena.teams
local arena_max_players = arena.max_players * #arena.teams
if arena.players_amount < arena.min_players then
if arena.players_amount < arena_min_players then
timer:stop()
arena.in_queue = false
arena_lib.HUD_send_msg_all("hotbar", arena, arena.name .. " | " .. arena.players_amount .. "/" .. arena.max_players .. " | " ..
S("Waiting for more players...") .. " (" .. arena.min_players - arena.players_amount .. ")")
arena_lib.HUD_send_msg_all("hotbar", arena, arena.name .. " | " .. arena.players_amount .. "/" .. arena_max_players .. " | " ..
S("Waiting for more players...") .. " (" .. arena_min_players - arena.players_amount .. ")")
arena_lib.send_message_players_in_arena(arena, mod_ref.prefix .. S("The queue has been cancelled due to not enough players"))
end
-- se invece ha i team e sono rimasti solo i giocatori di un team, il loro team vince
elseif #arena.teams > 1 and arena.players_amount < arena.min_players * #arena.teams then
local team_to_compare
for i = 1, #arena.players_amount_per_team do
if arena.players_amount_per_team[i] ~= 0 then
team_to_compare = i
break
end
end
for _, pl_stats in pairs(arena.players) do
if pl_stats.teamID ~= team_to_compare then
return
end
end
arena_lib.send_message_players_in_arena(arena, mod_ref.prefix .. S("There are no other teams left, you win!"))
arena_lib.load_celebration(mod, arena, arena_lib.get_players_in_team(arena, team_to_compare))
-- se invece erano rimasti solo 2 giocatori in partita, l'altro vince
elseif arena.players_amount == 1 then
@ -880,7 +1093,6 @@ function arena_lib.remove_player_from_arena(p_name, reason)
arena_lib.load_celebration(mod, arena, pl_name)
end
end
end
@ -892,6 +1104,20 @@ end
function arena_lib.assign_team(arena, p_name)
local assigned_team_ID = 1
for i = 1, #arena.teams do
if arena.players_amount_per_team[i] < arena.players_amount_per_team[assigned_team_ID] then
assigned_team_ID = i
end
end
return assigned_team_ID
end
function arena_lib.immunity(player)
local immunity_item = ItemStack("arena_lib:immunity")
@ -940,6 +1166,24 @@ end
-- ritorna tabella di nomi giocatori, o di giocatori se to_players == true
function arena_lib.get_players_in_team(arena, team_ID, to_players)
local players = {}
for pl_name, pl_stats in pairs(arena.players) do
if pl_stats.teamID == team_ID then
if to_players then
table.insert(players, minetest.get_player_by_name(pl_name))
else
table.insert(players, pl_name)
end
end
end
return players
end
function arena_lib.get_mod_by_player(p_name)
if arena_lib.is_player_in_arena(p_name) then
return players_in_game[p_name].minigame
@ -984,14 +1228,31 @@ end
function arena_lib.get_arena_spawners_count(arena)
return table.maxn(arena.spawn_points)
function arena_lib.get_arena_spawners_count(arena, team)
local count = 0
for _, spawner in pairs(arena.spawn_points) do
if team then
if spawner.team == team then
count = count +1
end
else
count = count +1
end
end
return count
end
function arena_lib.get_random_spawner(arena)
return arena.spawn_points[math.random(1,table.maxn(arena.spawn_points))]
function arena_lib.get_random_spawner(arena, p_name)
if #arena.teams > 1 then
local team_ID = arena.players[p_name].teamID
local min = 1 + (arena.max_players * (team_ID - 1))
local max = arena.max_players * team_ID
return arena.spawn_points[math.random(min, max)].pos
else
return arena.spawn_points[math.random(1,table.maxn(arena.spawn_points))].pos
end
end
@ -1030,17 +1291,50 @@ function init_storage(mod, mod_ref)
--v------------------ LEGACY UPDATE, to remove in 4.0 -------------------v
local to_convert = false
-- add the players_amount parameter for 2.6.0 and lesser versions
-- add the 'players_amount' parameter for 2.6.0 and lesser versions
if not arena.players_amount then
to_convert = true
arena.players_amount = 0
minetest.log("action", "[ARENA_LIB] Added '.players_amount' property from 2.7.0")
end
-- spawners conversion from 2.7.0 to 3.0+ version
if next(arena.spawn_points) then
if arena.spawn_points[next(arena.spawn_points)].x ~= nil then
to_convert = true
minetest.log("action", "[ARENA_LIB] Converting old spawn points for arena " .. arena.name)
for id, coords in pairs(arena.spawn_points) do
arena.spawn_points[id] = {pos = coords}
minetest.log("action", "[ARENA_LIB] Spawn point #" .. id .. "(" .. minetest.pos_to_string(arena.spawn_points[id].pos) .. ") converted")
end
end
end
--^------------------ LEGACY UPDATE, to remove in 4.0 -------------------^
-- controlli timer
if mod_ref.timer == -1 and arena.timer then -- se avevo abilitato i timer e ora li ho rimossi, li tolgo dalle arene
-- gestione team
if #arena.teams > 1 and not next(mod_ref.teams) then -- se avevo abilitato i team e ora li ho rimossi
arena.players_amount_per_team = nil
arena.teams = {-1}
elseif next(mod_ref.teams) then -- sennò li genero
arena.players_amount_per_team = {}
arena.teams = {}
for k, t_name in pairs(mod_ref.teams) do
arena.players_amount_per_team[k] = 0
arena.teams[k] = {name = t_name}
-- e loro eventuali proprietà
for j, w in pairs(mod_ref.team_properties) do
arena.teams[k][j] = w
end
end
end
-- gestione timer
if mod_ref.timer == -1 and arena.timer then -- se avevo abilitato i timer e ora li ho rimossi, li tolgo dalle arene
arena.timer = nil
elseif mod_ref.timer ~= -1 and not arena.timer then -- se li ho abilitati ora e le arene non ce li hanno, glieli aggiungo
elseif mod_ref.timer ~= -1 and not arena.timer then -- se li ho abilitati ora e le arene non ce li hanno, glieli aggiungo
arena.timer = mod_ref.timer
end
@ -1111,6 +1405,20 @@ end
function assign_team_spawner(spawn_points, ID, p_name, p_team)
minetest.log("action", p_team)
for i = ID, #spawn_points do
if p_team == spawn_points[i].team then
minetest.get_player_by_name(p_name):set_pos(spawn_points[i].pos)
return i+1
end
end
end
function timer_start(mod_ref, arena)
if arena.on_celebration then return end

View File

@ -25,6 +25,22 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
return end
local mod_ref = arena_lib.mods[mod]
local arena_min_players = arena.min_players * #arena.teams
local arena_max_players = arena.max_players * #arena.teams
local teams = ""
local min_players_per_team = ""
local max_players_per_team = ""
-- concateno eventuali team
if next(mod_ref.teams) then
min_players_per_team = minetest.colorize("#eea160", S("Players required per team: ")) .. minetest.colorize("#cfc6b8", arena.min_players) .. "\n"
max_players_per_team = minetest.colorize("#eea160", S("Players supported per team: ")) .. minetest.colorize("#cfc6b8", arena.max_players) .. "\n"
for _, t_name in pairs(mod_ref.teams) do
teams = teams .. " '" .. t_name .. "'"
end
else
teams = "---"
end
-- concateno nomi giocatori
local names = ""
@ -55,11 +71,21 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
end
-- calcolo coordinate spawn point
local spawners_count = 0
local spawners_pos = ""
for spawn_id, spawn_pos in pairs(arena.spawn_points) do
spawners_count = spawners_count + 1
spawners_pos = spawners_pos .. " " .. minetest.pos_to_string(spawn_pos) .. " "
if #arena.teams > 1 then
for i = 1, #arena.teams do
spawners_pos = spawners_pos .. arena.teams[i].name .. ": "
for j = 1 + (arena.max_players * (i-1)), arena.max_players * i do
spawners_pos = spawners_pos .. " " .. minetest.pos_to_string(arena.spawn_points[j].pos) .. " "
end
spawners_pos = spawners_pos .. "; "
end
else
for spawn_id, spawn_params in pairs(arena.spawn_points) do
spawners_pos = spawners_pos .. " " .. minetest.pos_to_string(spawn_params.pos) .. " "
end
end
-- calcolo eventuale timer
@ -89,21 +115,45 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
temp_properties = temp_properties .. temp_property .. "; "
end
end
local team_properties = ""
if not next(mod_ref.team_properties) then
team_properties = "---"
else
if arena.in_game == true then
for i = 1, #arena.teams do
team_properties = team_properties .. arena.teams[i].name .. ": "
for team_property, _ in pairs(mod_ref.team_properties) do
team_properties = team_properties .. " " .. team_property .. " = " .. arena.teams[i][team_property] .. ";"
end
team_properties = team_properties .. "|"
end
else
for team_property, _ in pairs(mod_ref.team_properties) do
team_properties = team_properties .. team_property .. "; "
end
end
end
minetest.chat_send_player(sender,
minetest.colorize("#cfc6b8", "====================================") .. "\n" ..
minetest.colorize("#eea160", S("Name: ")) .. minetest.colorize("#cfc6b8", arena_name ) .. "\n" ..
minetest.colorize("#eea160", "ID: ") .. minetest.colorize("#cfc6b8", arena_ID) .. "\n" ..
minetest.colorize("#eea160", S("Players required: ")) .. minetest.colorize("#cfc6b8", arena.min_players) .. "\n" ..
minetest.colorize("#eea160", S("Players supported: ")) .. minetest.colorize("#cfc6b8", arena.max_players) .. "\n" ..
minetest.colorize("#eea160", S("Teams: ")) .. minetest.colorize("#cfc6b8", teams) .. "\n" ..
min_players_per_team ..
max_players_per_team ..
minetest.colorize("#eea160", S("Players required: ")) .. minetest.colorize("#cfc6b8", arena_min_players) .. "\n" ..
minetest.colorize("#eea160", S("Players supported: ")) .. minetest.colorize("#cfc6b8", arena_max_players) .. "\n" ..
minetest.colorize("#eea160", S("Players inside: ")) .. minetest.colorize("#cfc6b8", arena.players_amount .. " ( ".. names .. " )") .. "\n" ..
minetest.colorize("#eea160", S("Enabled: ")) .. minetest.colorize("#cfc6b8", tostring(arena.enabled)) .. "\n" ..
minetest.colorize("#eea160", S("Status: ")) .. minetest.colorize("#cfc6b8", status) .. "\n" ..
minetest.colorize("#eea160", S("Sign: ")) .. minetest.colorize("#cfc6b8", sign_pos) .. "\n" ..
minetest.colorize("#eea160", S("Spawn points: ")) .. minetest.colorize("#cfc6b8", spawners_count .. " ( " .. spawners_pos .. " )") .. "\n" ..
minetest.colorize("#eea160", S("Spawn points: ")) .. minetest.colorize("#cfc6b8", #arena.spawn_points .. " ( " .. spawners_pos .. " )") .. "\n" ..
timer ..
minetest.colorize("#eea160", S("Properties: ")) .. minetest.colorize("#cfc6b8", properties) .. "\n" ..
minetest.colorize("#eea160", S("Temp properties: ")) .. minetest.colorize("#cfc6b8", temp_properties)
minetest.colorize("#eea160", S("Temp properties: ")) .. minetest.colorize("#cfc6b8", temp_properties) .. "\n" ..
minetest.colorize("#eea160", S("Team properties: ")) .. minetest.colorize("#cfc6b8", team_properties)
)
end

View File

@ -7,13 +7,17 @@
[!] An arena with that name exists already!=[!] Esiste già un'arena con quel nome!
Arena @1 succesfully created=Arena @1 creata con successo
Arena @1 successfully removed=Arena @1 rimossa con successo
[!] This team doesn't exist!=[!] Questo team non esiste!
[!] No spawner with that ID to overwrite!=[!] Nessuno spawner con quell'ID da sovrascrivere!
[!] No team must be specified for this function!=[!] Non va specificato nessun team per questa funzione!
Spawn point #@1 successfully overwritten=Punto di spawn #@1 sovrascritto con successo
[!] No spawner with that ID to delete!=[!] Nessuno spawner con quell'ID da cancellare!
All the spawn points belonging to team @1 have been removed=Tutti i punti di spawn appartenenti al team @1 sono stati rimossi
All the spawn points have been removed=Tutti i punti di spawn sono stati rimossi
Spawn point #@1 successfully deleted=Punto di spawn #@1 cancellato con successo
[!] Unknown parameter!=[!] Parametro non riconosciuto!
[!] Spawn points can't exceed the maximum number of players!=[!] I punti di spawn non possono superare i giocatori massimi!
[!] There's already a spawn in this point!=[!] C'è già uno spawn in questo punto!
[!] Spawn points can't exceed the maximum number of players!=[!] I punti di spawn non possono superare i giocatori massimi!
Spawn point #@1 successfully set=Punto di spawn #@1 impostato con successo
[!] That's not a sign!=[!] Questo non è un cartello!
Sign of arena @1 successfully removed=Cartello dell'arena @1 rimosso con successo
@ -34,12 +38,15 @@ Arena @1 successfully disabled=Arena @1 disabilitata con successo
@1 has quit the match=@1 ha abbandonato la partita
Waiting for more players...=In attesa di più giocatori...
The queue has been cancelled due to not enough players=La coda è stata annullata per troppi pochi giocatori
There are no other teams left, you win!=Non ci sono altre squadre rimaste, hai vinto!
You're the last player standing: you win!=Sei l'ultimo giocatore rimasto in partita: hai vinto!
You win the game due to not enough players=Hai vinto la partita per troppi pochi giocatori
# debug_utilities.lua
name: =nome:
Total arenas: =Arene totali:
Players required per team: =Giocatori minimi per squadra:
Players supported per team: =Giocatori massimi per squadra:
in queue=in coda
loading=in caricamento
in game=in partita
@ -48,15 +55,17 @@ waiting=in attesa
Timer: =Timer:
current: =corrente:
Name: =Nome:
Enabled: =Abilitata:
Teams: =Squadre:
Players required: =Giocatori minimi:
Players supported: =Giocatori massimi:
Players inside: =Giocatori dentro:
Enabled: =Abilitata:
Status: =Stato:
Sign: =Cartello:
Spawn points: =Punti di spawn:
Properties: =Proprietà:
Temp properties: =Proprietà temporanee:
Team properties: =Proprietà squadra:
[!] No ongoing game! =[!] Nessuna partita in corso!
Player: =Giocatore:
, kills: =, uccisioni:
@ -65,8 +74,8 @@ Player: =Giocatore:
# items.lua
You're immune!=Sei immune!
# signs.lua
[!] You must leave the editor first!=[!] Devi prima uscire dall'editor!
[!] The arena is not enabled!=[!] L'arena non è attiva!
[!] The arena is already full!=[!] L'arena è già piena!
[!] The arena is loading, try again in a few seconds!=[!] L'arena è in caricamento, riprova tra qualche secondo!
@ -74,6 +83,7 @@ You're immune!=Sei immune!
Waiting for more players...=In attesa di più giocatori...
The queue has been cancelled due to not enough players=La coda è stata annullata per troppi pochi giocatori
@1 seconds for the match to start=@1 secondi all'inizio
You've joined team @1=Ti sei unito al team @1
The game begins in @1 seconds!=La partita inizierà tra @1 secondi!
Get ready!=Preparati!
# signs_lib gives troubles atm
@ -100,12 +110,15 @@ Info=Info
Go back=Torna indietro
Leave the editor=Esci dall'editor
# tools_spawner.lua
Add spawner=Aggiungi spawner
Remove spawner=Rimuovi spawner
Add team spawner=Aggiungi spawner squadra
Remove team spawner=Rimuovi spawner squadra
Switch team=Cambia squadra
Selected team: @1=Squadra selezionata: @1
Delete all spawners=Cancella tutti gli spawner
All the spawn points has been removed=Tutti i punti di spawn sono stati rimossi
Delete all spawners of a team=Cancella tutti gli spawner della squadra
# tools_sign.lua
Add sign=Aggiungi cartello

View File

@ -7,13 +7,17 @@
[!] An arena with that name exists already!=
Arena @1 succesfully created=
Arena @1 successfully removed=
[!] This team doesn't exist!=
[!] No spawner with that ID to overwrite!=
[!] No team must be specified for this function!=
Spawn point #@1 successfully overwritten=
[!] No spawner with that ID to delete!=
Spawn point #@1 successfully deleted=
All the spawn points belonging to team @1 have been removed=
All the spawn points have been removed=
[!] Unknown parameter!=
[!] Spawn points can't exceed the maximum number of players!=
[!] There's already a spawn in this point!=
[!] Spawn points can't exceed the maximum number of players!=
Spawn point #@1 successfully set=
[!] That's not a sign!=
Sign of arena @1 successfully removed=
@ -29,17 +33,21 @@ Arena @1 successfully enabled=
[!] The arena you were queueing for has been disabled... :(=
Arena @1 successfully disabled=
@1 wins the game=
Team @1 wins the game=
@1 has been eliminated=
@1 has been kicked=
@1 has quit the match=
Waiting for more players...=
The queue has been cancelled due to not enough players=
There are no other teams left, you win!=
You're the last player standing: you win!=
You win the game due to not enough players=
# debug_utilities.lua
name: =
Total arenas: =
Players required per team: =
Players supported per team: =
in queue=
loading=
in game=
@ -48,6 +56,7 @@ waiting=
Timer: =
current: =
Name: =
Teams: =
Players required: =
Players supported: =
Players inside: =
@ -57,6 +66,7 @@ Sign: =
Spawn points: =
Properties: =
Temp properties: =
Team properties: =
[!] No ongoing game! =
Player: =
, kills: =
@ -66,6 +76,7 @@ Player: =
You're immune!=
# signs.lua
[!] You must leave the editor first!=
[!] The arena is not enabled!=
[!] The arena is already full!=
[!] The arena is loading, try again in a few seconds!=
@ -73,6 +84,7 @@ You're immune!=
Waiting for more players...=
The queue has been cancelled due to not enough players=
@1 seconds for the match to start=
You've joined team @1=
The game begins in @1 seconds!=
Get ready!=
# signs_lib gives troubles atm
@ -103,8 +115,12 @@ Leave the editor=
# tools_spawner.lua
Add spawner=
Remove spawner=
Add team spawner=
Remove team spawner=
Switch team=
Selected team: @1=
Delete all spawners=
All the spawn points has been removed=
Delete all spawners of the team=
# tools_sign.lua
Add sign=

View File

@ -9,7 +9,8 @@ minetest.register_on_joinplayer(function(player)
p_meta:set_string("arena_lib_editor.mod", "")
p_meta:set_string("arena_lib_editor.arena", "")
p_meta:set_string("arena_lib_editor.spawner_ID", "")
p_meta:set_int("arena_lib_editor.spawner_ID", 0)
p_meta:set_int("arena_lib_editor.team_ID", 0)
if minetest.get_modpath("hub_manager") then return end -- se c'è hub_manager, ci pensa quest'ultimo allo svuotamento dell'inventario
@ -29,11 +30,27 @@ end)
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
local target_name = player:get_player_name()
local p_name = hitter:get_player_name()
local arena = arena_lib.get_arena_by_player(p_name)
if arena and arena.players[p_name].team and arena.players[p_name].team == arena.players[target_name].team then
return true
end
end)
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if player:get_inventory():contains_item("main", "arena_lib:immunity") then
return 0
end
return hp_change
end, true)
@ -65,7 +82,7 @@ minetest.register_on_respawnplayer(function(player)
local arena = arena_lib.get_arena_by_player(p_name)
player:set_pos(arena_lib.get_random_spawner(arena))
player:set_pos(arena_lib.get_random_spawner(arena, p_name))
arena_lib.immunity(player)
return true

View File

@ -34,7 +34,7 @@ minetest.override_item("default:sign_wall", {
return end
-- se l'arena è piena
if sign_arena.players_amount == sign_arena.max_players and arena_lib.get_queueID_by_player(p_name) ~= arenaID then
if sign_arena.players_amount == sign_arena.max_players * #sign_arena.teams 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
@ -56,28 +56,35 @@ minetest.override_item("default:sign_wall", {
-- se la coda è la stessa rimuovo il giocatore...
if queued_mod == mod and queued_ID == arenaID then
local p_team_ID = sign_arena.players[p_name].teamID
arena_lib.send_message_players_in_arena(sign_arena, minetest.colorize("#d69298", sign_arena.name .. " < " .. p_name))
sign_arena.players[p_name] = nil
sign_arena.players_amount = sign_arena.players_amount - 1
if #sign_arena.teams > 1 then
sign_arena.players_amount_per_team[p_team_ID] = sign_arena.players_amount_per_team[p_team_ID] -1
end
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
local arena_min_players = sign_arena.min_players * #sign_arena.teams
-- ...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
if players_in_arena < 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...")) ..
" (" .. sign_arena.min_players - players_in_arena .. ")")
" (" .. 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
elseif players_in_arena < arena_min_players then
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_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)))
@ -89,29 +96,34 @@ minetest.override_item("default:sign_wall", {
local old_mod_ref = arena_lib.mods[queued_mod]
local old_arena = old_mod_ref.arenas[queued_ID]
local old_p_team_ID = old_arena.players[p_name].teamID
-- 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
if #old_arena.teams > 1 then
old_arena.players_amount_per_team[old_p_team_ID] = old_arena.players_amount_per_team[old_p_team_ID] -1
end
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
local arena_min_players = old_arena.min_players * #old_arena.teams
-- ...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
if players_in_arena < 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...")) ..
" (" .. old_arena.min_players - players_in_arena .. ")")
" (" .. 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
elseif players_in_arena < 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...")) ..
" (" .. old_arena.min_players - players_in_arena .. ")")
" (" .. 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)))
@ -120,9 +132,22 @@ minetest.override_item("default:sign_wall", {
end
end
local p_team_ID
local p_team
-- determino eventuale team giocatore
if #sign_arena.teams > 1 then
p_team_ID = arena_lib.assign_team(sign_arena, p_name)
p_team = sign_arena.teams[p_team_ID].name
minetest.chat_send_player(p_name, mod_ref.prefix .. S("You've joined team @1", minetest.colorize("#eea160", p_team)))
end
-- aggiungo il giocatore ed eventuali proprietà
sign_arena.players[p_name] = {kills = 0, deaths = 0}
sign_arena.players[p_name] = {kills = 0, deaths = 0, teamID = p_team_ID}
sign_arena.players_amount = sign_arena.players_amount +1
if #sign_arena.teams > 1 then
sign_arena.players_amount_per_team[p_team_ID] = sign_arena.players_amount_per_team[p_team_ID] +1
end
for k, v in pairs(mod_ref.player_properties) do
sign_arena.players[p_name][k] = v
@ -143,26 +168,28 @@ minetest.override_item("default:sign_wall", {
local timer = minetest.get_node_timer(pos)
local players_in_arena = sign_arena.players_amount
local arena_min_players = sign_arena.min_players * #sign_arena.teams
local arena_max_players = sign_arena.max_players * #sign_arena.teams
-- se ci sono abbastanza giocatori e la coda non è partita...
-- se la coda non è partita...
if not sign_arena.in_queue and not sign_arena.in_game then
-- ...parte il timer d'attesa
if players_in_arena == sign_arena.min_players then
-- ...e ci sono abbastanza giocatori, parte il timer d'attesa
if players_in_arena == arena_min_players then
sign_arena.in_queue = true
timer:start(mod_ref.queue_waiting_time)
HUD_countdown(sign_arena, timer)
-- sennò aggiorno semplicemente la HUD
elseif players_in_arena < sign_arena.min_players then
elseif players_in_arena < arena_min_players then
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_min_players - players_in_arena .. ")")
end
end
-- 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
if players_in_arena == arena_max_players and sign_arena.in_queue then
if timer:get_timeout() - timer:get_elapsed() > 5 then
timer:stop()
timer:start(5)
@ -195,8 +222,10 @@ minetest.override_item("default:sign_wall", {
function arena_lib.update_sign(pos, arena)
-- non uso il getter perché dovrei richiamare 2 funzioni (ID e count)
local p_count = 0
local t_count = #arena.teams
-- non uso il getter perché dovrei richiamare 2 funzioni (ID e count)
for pl, stats in pairs(arena.players) do
p_count = p_count +1
end
@ -204,7 +233,7 @@ function arena_lib.update_sign(pos, arena)
signs_lib.update_sign(pos, {text = [[
]] .. "\n" .. [[
]] .. arena.name .. "\n" .. [[
]] .. p_count .. "/".. arena.max_players .. "\n" .. [[
]] .. p_count .. "/".. arena.max_players * t_count .. "\n" .. [[
]] .. in_game_txt(arena) .. "\n" .. [[
]]})
@ -222,8 +251,9 @@ function HUD_countdown(arena, timer)
local seconds = math.floor(timer:get_timeout() - timer:get_elapsed() + 0.5)
-- dai 5 secondi in giù il messaggio è stampato su broadcast
-- dai 5 secondi in giù il messaggio è stampato su broadcast e genero i team
if seconds <= 5 then
--arena_lib.generate_teams(mod_ref, arena)
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
@ -238,7 +268,8 @@ end
-- es. Foresta | 3/4 | Il match inizierà a breve
function arena_display_format(arena, msg)
return arena.name .. " | " .. arena.players_amount .. "/" .. arena.max_players .. " | " .. msg
local arena_max_players = arena.max_players * #arena.teams
return arena.name .. " | " .. arena.players_amount .. "/" .. arena_max_players .. " | " .. msg
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 235 B

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B