2020-04-02 03:45:50 -07:00
---
--- Link these functions to your mod through some commands, ie. /yourmod info arena_name
---
2020-04-17 06:27:36 -07:00
local S = minetest.get_translator ( " arena_lib " )
2020-04-02 03:45:50 -07:00
2022-04-11 05:42:33 -07:00
local function property_val_to_string ( ) end
2022-04-11 05:39:36 -07:00
local function table_to_string ( ) end
2020-09-03 10:07:27 -07:00
2020-04-02 03:45:50 -07:00
2020-04-15 04:14:30 -07:00
function arena_lib . print_arenas ( sender , mod )
2020-04-02 03:45:50 -07:00
local n = 0
2020-04-15 04:14:30 -07:00
for id , arena in pairs ( arena_lib.mods [ mod ] . arenas ) do
2020-04-02 03:45:50 -07:00
n = n + 1
2020-04-17 06:27:36 -07:00
minetest.chat_send_player ( sender , " ID: " .. id .. " , " .. S ( " name: " ) .. arena.name )
2020-04-02 03:45:50 -07:00
end
2020-04-17 12:04:37 -07:00
minetest.chat_send_player ( sender , S ( " Total arenas: " ) .. n )
2020-04-02 03:45:50 -07:00
end
2020-04-15 06:17:12 -07:00
function arena_lib . print_arena_info ( sender , mod , arena_name )
local arena_ID , arena = arena_lib.get_arena_by_name ( mod , arena_name )
2020-11-24 11:48:29 -08:00
if not arena then
2020-04-18 15:57:08 -07:00
minetest.chat_send_player ( sender , minetest.colorize ( " #e6482e " , S ( " [!] This arena doesn't exist! " ) ) )
2020-11-24 11:48:29 -08:00
return end
2020-04-18 15:57:08 -07:00
2022-04-03 07:07:27 -07:00
-- calcolo eventuale musica sottofondo
local arena_bgm = " --- "
if arena.bgm then
arena_bgm = arena.bgm . track .. " .ogg "
end
2020-04-18 15:57:08 -07:00
local mod_ref = arena_lib.mods [ mod ]
2020-05-31 13:38:59 -07:00
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 = " "
2020-06-06 12:59:46 -07:00
local players_inside_per_team = " "
2021-02-15 14:53:32 -08:00
local spectators_inside_per_team = " "
2020-05-31 13:38:59 -07:00
2022-04-03 07:07:27 -07:00
-- calcolo eventuali squadre
2020-06-26 16:04:42 -07:00
if arena.teams_enabled then
2020-05-31 13:38:59 -07:00
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 "
2020-06-26 09:43:13 -07:00
for i = 1 , # arena.teams do
2020-06-26 16:04:42 -07:00
teams = teams .. " ' " .. arena.teams [ i ] . name .. " ' "
players_inside_per_team = players_inside_per_team .. " ' " .. arena.teams [ i ] . name .. " ' : " .. arena.players_amount_per_team [ i ] .. " "
2021-02-15 14:53:32 -08:00
if mod_ref.spectate_mode then
spectators_inside_per_team = spectators_inside_per_team .. " ' " .. arena.teams [ i ] . name .. " ' : " .. arena.spectators_amount_per_team [ i ] .. " "
end
2020-05-31 13:38:59 -07:00
end
2020-06-06 12:59:46 -07:00
players_inside_per_team = minetest.colorize ( " #eea160 " , S ( " Players inside per team: " ) ) .. minetest.colorize ( " #cfc6b8 " , players_inside_per_team ) .. " \n "
2021-02-15 14:53:32 -08:00
if mod_ref.spectate_mode then
spectators_inside_per_team = minetest.colorize ( " #eea160 " , S ( " Spectators inside per team: " ) ) .. minetest.colorize ( " #cfc6b8 " , spectators_inside_per_team ) .. " \n "
end
2020-05-31 13:38:59 -07:00
else
teams = " --- "
end
2020-04-02 03:45:50 -07:00
2022-04-03 07:07:27 -07:00
-- calcolo eventuali danni disabilitati
2020-06-09 16:14:46 -07:00
local disabled_damage_types = " "
if next ( mod_ref.disabled_damage_types ) then
for _ , dmg_type in pairs ( mod_ref.disabled_damage_types ) do
disabled_damage_types = disabled_damage_types .. " " .. dmg_type
end
else
disabled_damage_types = " --- "
end
2022-04-03 07:07:27 -07:00
-- calcolo nomi giocatori
2021-02-15 14:53:32 -08:00
local p_names = " "
2020-05-25 07:27:19 -07:00
for pl , stats in pairs ( arena.players ) do
2021-02-15 14:53:32 -08:00
p_names = p_names .. " " .. pl
end
2022-04-03 07:07:27 -07:00
-- calcolo nomi spettatori
2021-02-15 14:53:32 -08:00
local sp_names = " "
for sp_name , stats in pairs ( arena.spectators ) do
sp_names = sp_names .. " " .. sp_name
end
2022-04-03 07:07:27 -07:00
-- calcolo giocatori e spettatori (per verificare che campo sia giusto)
2021-02-15 14:53:32 -08:00
local psp_names = " "
local psp_amount = 0
for psp_name , _ in pairs ( arena.players_and_spectators ) do
psp_names = psp_names .. " " .. psp_name
psp_amount = psp_amount + 1
end
2022-04-03 07:07:27 -07:00
-- calcolo giocatori presenti e passati
2021-02-15 14:53:32 -08:00
local ppp_names = " "
local ppp_names_amount = 0
for ppp_name , _ in pairs ( arena.past_present_players ) do
ppp_names = ppp_names .. " " .. ppp_name
ppp_names_amount = ppp_names_amount + 1
end
2022-04-03 07:07:27 -07:00
-- calcolo giocatori presenti e passati
2021-02-15 14:53:32 -08:00
local ppp_names_inside = " "
local ppp_names_inside_amount = 0
for ppp_name_inside , _ in pairs ( arena.past_present_players_inside ) do
ppp_names_inside = ppp_names_inside .. " " .. ppp_name_inside
ppp_names_inside_amount = ppp_names_inside_amount + 1
2020-05-25 07:27:19 -07:00
end
2022-05-27 16:06:19 -07:00
-- calcolo eventuali entità/aree seguibili
local spectatable_entities = " "
local spectatable_areas = " "
if mod_ref.spectate_mode then
local entities = " "
local areas = " "
if arena.in_game then
for en_name , _ in pairs ( arena_lib.get_spectate_entities ( mod , arena_name ) ) do
entities = entities .. en_name .. " , "
end
for ar_name , _ in pairs ( arena_lib.get_spectate_areas ( mod , arena_name ) ) do
areas = areas .. ar_name .. " , "
end
entities = entities : sub ( 1 , - 3 )
areas = areas : sub ( 1 , - 3 )
else
entities = " --- "
areas = " --- "
end
spectatable_entities = minetest.colorize ( " #eea160 " , S ( " Current spectatable entities: " ) ) .. minetest.colorize ( " #cfc6b8 " , entities ) .. " \n "
spectatable_areas = minetest.colorize ( " #eea160 " , S ( " Current spectatable areas: " ) ) .. minetest.colorize ( " #cfc6b8 " , areas ) .. " \n \n "
end
2020-05-25 07:27:19 -07:00
-- calcolo stato arena
local status
if arena.in_queue then
status = S ( " in queue " )
elseif arena.in_loading then
status = S ( " loading " )
elseif arena.in_game then
status = S ( " in game " )
elseif arena.in_celebration then
status = S ( " celebrating " )
else
status = S ( " waiting " )
end
2020-04-19 07:39:46 -07:00
-- calcolo cartello
local sign_pos
2020-09-25 15:55:10 -07:00
if next ( arena.sign ) then
2020-05-29 04:47:33 -07:00
sign_pos = minetest.pos_to_string ( arena.sign )
2020-04-19 07:39:46 -07:00
else
2020-05-29 04:47:33 -07:00
sign_pos = " --- "
2020-04-19 07:39:46 -07:00
end
2022-04-03 07:07:27 -07:00
-- calcolo coordinate punto di spawn
2020-04-02 03:45:50 -07:00
local spawners_pos = " "
2020-06-26 16:04:42 -07:00
if arena.teams_enabled then
2020-06-06 09:03:59 -07:00
2020-05-31 13:38:59 -07:00
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
2020-06-06 09:03:59 -07:00
if arena.spawn_points [ j ] then
spawners_pos = spawners_pos .. " " .. minetest.pos_to_string ( arena.spawn_points [ j ] . pos ) .. " "
end
2020-05-31 13:38:59 -07:00
end
2020-06-06 09:03:59 -07:00
spawners_pos = spawners_pos .. " ; "
2020-05-31 13:38:59 -07:00
end
2020-06-06 09:03:59 -07:00
2020-05-31 13:38:59 -07:00
else
for spawn_id , spawn_params in pairs ( arena.spawn_points ) do
spawners_pos = spawners_pos .. " " .. minetest.pos_to_string ( spawn_params.pos ) .. " "
end
2020-04-02 03:45:50 -07:00
end
2020-10-11 07:49:23 -07:00
-- calcolo eventuale tempo
local time = " "
2021-01-25 07:44:23 -08:00
if mod_ref.time_mode ~= " none " then
2020-10-11 07:49:23 -07:00
local current_time = not arena.current_time and " --- " or arena.current_time
time = minetest.colorize ( " #eea160 " , S ( " Initial time: " ) ) .. minetest.colorize ( " #cfc6b8 " , arena.initial_time .. " ( " .. S ( " current: " ) .. current_time .. " ) " ) .. " \n "
2020-05-24 14:38:21 -07:00
end
2022-04-11 05:39:36 -07:00
-- calcolo eventuale volta celeste personalizzata
local celvault = " "
if arena.celestial_vault then
for elem , params in pairs ( arena.celestial_vault ) do
if next ( params ) then
celvault = celvault .. string.upper ( elem ) .. " : " .. table_to_string ( params ) .. " \n "
end
end
else
celvault = " --- "
end
2022-04-01 03:26:26 -07:00
-- calcolo eventuale illuminazione personalizzata
local lighting = " "
if arena.lighting then
2022-04-11 05:39:36 -07:00
lighting = table_to_string ( arena.lighting )
2022-04-03 07:07:27 -07:00
else
lighting = " --- "
2022-04-01 03:26:26 -07:00
end
2020-04-18 15:57:08 -07:00
--calcolo proprietà
2020-05-25 07:27:19 -07:00
local properties = " "
2022-04-03 07:07:27 -07:00
if next ( mod_ref.properties ) then
for property , _ in pairs ( mod_ref.properties ) do
2022-04-11 05:42:33 -07:00
local value = property_val_to_string ( arena [ property ] )
2022-04-03 07:07:27 -07:00
properties = properties .. property .. " = " .. value .. " ; "
end
else
properties = " --- "
2020-04-18 15:57:08 -07:00
end
--calcolo proprietà temporanee
2020-05-25 07:27:19 -07:00
local temp_properties = " "
2022-04-03 07:07:27 -07:00
if next ( mod_ref.temp_properties ) then
if arena.in_game == true then
for temp_property , _ in pairs ( mod_ref.temp_properties ) do
2022-04-11 05:42:33 -07:00
local value = property_val_to_string ( arena [ temp_property ] )
2022-04-03 07:07:27 -07:00
temp_properties = temp_properties .. temp_property .. " = " .. value .. " ; "
end
else
for temp_property , _ in pairs ( mod_ref.temp_properties ) do
temp_properties = temp_properties .. temp_property .. " ; "
end
2020-05-25 07:27:19 -07:00
end
else
2022-04-03 07:07:27 -07:00
temp_properties = " --- "
2020-04-18 15:57:08 -07:00
end
2020-06-06 09:03:59 -07:00
2020-05-31 13:38:59 -07:00
local team_properties = " "
2020-09-05 06:36:54 -07:00
if not arena.teams_enabled then
2020-05-31 13:38:59 -07:00
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
2022-04-11 05:42:33 -07:00
local value = property_val_to_string ( arena.teams [ i ] [ team_property ] )
2020-09-03 10:07:27 -07:00
team_properties = team_properties .. " " .. team_property .. " = " .. value .. " ; "
2020-05-31 13:38:59 -07:00
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
2020-06-06 09:03:59 -07:00
2020-04-18 15:57:08 -07:00
2020-05-25 07:27:19 -07:00
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 " ..
2022-01-07 14:59:12 -08:00
minetest.colorize ( " #eea160 " , S ( " Author: " ) ) .. minetest.colorize ( " #cfc6b8 " , arena.author ) .. " \n " ..
minetest.colorize ( " #eea160 " , S ( " BGM: " ) ) .. minetest.colorize ( " #cfc6b8 " , arena_bgm ) .. " \n " ..
2020-05-31 13:38:59 -07:00
minetest.colorize ( " #eea160 " , S ( " Teams: " ) ) .. minetest.colorize ( " #cfc6b8 " , teams ) .. " \n " ..
2022-05-27 16:06:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Disabled damage types: " ) ) .. minetest.colorize ( " #cfc6b8 " , disabled_damage_types ) .. " \n \n " ..
2020-05-31 13:38:59 -07:00
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 " ..
2021-02-15 14:53:32 -08:00
minetest.colorize ( " #eea160 " , S ( " Players inside: " ) ) .. minetest.colorize ( " #cfc6b8 " , arena.players_amount .. " ( " .. p_names .. " ) " ) .. " \n " ..
2020-06-06 12:59:46 -07:00
players_inside_per_team ..
2021-02-15 14:53:32 -08:00
minetest.colorize ( " #eea160 " , S ( " Spectators inside: " ) ) .. minetest.colorize ( " #cfc6b8 " , arena.spectators_amount .. " ( " .. sp_names .. " ) " ) .. " \n " ..
spectators_inside_per_team ..
minetest.colorize ( " #eea160 " , S ( " Players and spectators inside: " ) ) .. minetest.colorize ( " #cfc6b8 " , psp_amount .. " ( " .. psp_names .. " ) " ) .. " \n " ..
minetest.colorize ( " #eea160 " , S ( " Past and present players: " ) ) .. minetest.colorize ( " #cfc6b8 " , ppp_names_amount .. " ( " .. ppp_names .. " ) " ) .. " \n " ..
2022-05-27 16:06:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Past and present players inside: " ) ) .. minetest.colorize ( " #cfc6b8 " , ppp_names_inside_amount .. " ( " .. ppp_names_inside .. " ) " ) .. " \n \n " ..
spectatable_entities ..
spectatable_areas ..
2020-05-25 07:27:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Enabled: " ) ) .. minetest.colorize ( " #cfc6b8 " , tostring ( arena.enabled ) ) .. " \n " ..
minetest.colorize ( " #eea160 " , S ( " Status: " ) ) .. minetest.colorize ( " #cfc6b8 " , status ) .. " \n " ..
2020-05-29 04:47:33 -07:00
minetest.colorize ( " #eea160 " , S ( " Sign: " ) ) .. minetest.colorize ( " #cfc6b8 " , sign_pos ) .. " \n " ..
2022-05-27 16:06:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Spawn points: " ) ) .. minetest.colorize ( " #cfc6b8 " , # arena.spawn_points .. " ( " .. spawners_pos .. " ) " ) .. " \n \n " ..
2020-10-11 07:49:23 -07:00
time ..
2022-04-11 05:39:36 -07:00
minetest.colorize ( " #eea160 " , S ( " Custom sky: " ) ) .. minetest.colorize ( " #cfc6b8 " , celvault ) .. " \n " ..
2022-05-27 16:06:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Custom lighting: " ) ) .. minetest.colorize ( " #cfc6b8 " , lighting ) .. " \n \n " ..
2020-05-25 07:27:19 -07:00
minetest.colorize ( " #eea160 " , S ( " Properties: " ) ) .. minetest.colorize ( " #cfc6b8 " , properties ) .. " \n " ..
2020-05-31 13:38:59 -07:00
minetest.colorize ( " #eea160 " , S ( " Temp properties: " ) ) .. minetest.colorize ( " #cfc6b8 " , temp_properties ) .. " \n " ..
minetest.colorize ( " #eea160 " , S ( " Team properties: " ) ) .. minetest.colorize ( " #cfc6b8 " , team_properties )
2020-05-25 07:27:19 -07:00
)
2020-05-24 14:38:21 -07:00
2020-04-02 03:45:50 -07:00
end
2021-12-24 10:47:11 -08:00
function arena_lib . flush_arena ( mod , arena_name , sender )
local id , arena = arena_lib.get_arena_by_name ( mod , arena_name )
if not ARENA_LIB_EDIT_PRECHECKS_PASSED ( sender , arena ) then return end
2021-02-15 14:53:32 -08:00
if arena.in_queue or arena.in_game then
minetest.chat_send_player ( sender , minetest.colorize ( " #e6482e " , S ( " [!] You can't perform this action during an ongoing game! " ) ) )
return end
arena.players = { }
arena.spectators = { }
arena.players_and_spectators = { }
arena.past_present_players = { }
arena.past_present_players_inside = { }
arena.players_amount = 0
if arena.teams_enabled then
local mod_ref = arena_lib.mods [ mod ]
for i = 1 , # arena.teams do
arena.players_amount_per_team [ i ] = 0
if mod_ref.spectate_mode then
arena.spectators_amount_per_team [ i ] = 0
end
end
end
arena.current_time = nil
minetest.chat_send_player ( sender , " Sluuush! " )
end
2020-09-03 10:07:27 -07:00
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
2022-04-11 05:42:33 -07:00
function property_val_to_string ( value )
2020-09-03 10:07:27 -07:00
if type ( value ) == " table " then
return tostring ( dump ( value ) ) : gsub ( " \n " , " " )
else
return tostring ( value )
end
end
2022-04-11 05:39:36 -07:00
function table_to_string ( table )
local str = " "
for k , v in pairs ( table ) do
local val = " "
if type ( v ) == " table " then
if next ( v ) then
val = " { " .. table_to_string ( v ) .. " } "
end
else
val = tostring ( v )
end
if val ~= " " then
str = str .. k .. " = " .. val .. " ; "
end
end
return str
end