From b9aacb40277d3a12317fbe272791b829e962e123 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Mon, 27 Feb 2023 15:44:51 +0100 Subject: [PATCH] Possibility for minigames to declare a global minimum amount of players (closes #206) --- locale/arena_lib.it.tr | 1 + locale/template.txt | 1 + src/api/core.lua | 42 ++++++++++++++++++++++++++++++++---- src/editor/tools_players.lua | 1 - src/editor/tools_spawner.lua | 7 ------ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/locale/arena_lib.it.tr b/locale/arena_lib.it.tr index 14cb66e..cf854c8 100755 --- a/locale/arena_lib.it.tr +++ b/locale/arena_lib.it.tr @@ -65,6 +65,7 @@ There are no winners=Non ci sono vincitorɜ [!] Parameters don't seem right!=[!] I parametri hanno qualcosa che non va! [!] Property type doesn't match, aborting!=[!] Il tipo della proprietà non corrisponde, annullo! Parameter @1 successfully overwritten=Parametro @1 sovrascritto con successo +[!] This minigame needs at least @1 players!=[!] Questo minigioco ha bisogno di almeno @1 giocatorɜ! Arena @1 successfully created=Arena @1 creata con successo Arena @1 successfully removed=Arena @1 rimossa con successo Arena @1 successfully renamed in @2=Arena @1 rinominata con successo in @2 diff --git a/locale/template.txt b/locale/template.txt index daadd9a..21a68d1 100755 --- a/locale/template.txt +++ b/locale/template.txt @@ -65,6 +65,7 @@ There are no winners= [!] Parameters don't seem right!= [!] Property type doesn't match, aborting!= Parameter @1 successfully overwritten= +[!] This minigame needs at least @1 players!= Arena @1 successfully created= Arena @1 successfully removed= Arena @1 successfully renamed in @2= diff --git a/src/api/core.lua b/src/api/core.lua index 06397fa..983300f 100755 --- a/src/api/core.lua +++ b/src/api/core.lua @@ -101,6 +101,7 @@ function arena_lib.register_minigame(mod, def) mod_ref.fov = nil mod_ref.camera_offset = nil mod_ref.hotbar = nil + mod_ref.min_players = 1 mod_ref.join_while_in_progress = false mod_ref.spectate_mode = true mod_ref.disable_inventory = false @@ -190,6 +191,10 @@ function arena_lib.register_minigame(mod, def) mod_ref.hotbar.selected_image = def.hotbar.selected_image end + if def.min_players then + mod_ref.min_players = def.min_players + end + if def.join_while_in_progress == true then mod_ref.join_while_in_progress = def.join_while_in_progress end @@ -385,6 +390,10 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player if min_players > max_players or min_players == 0 or max_players < 2 then minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!"))) return end + + if min_players > mod_ref.min_players then + minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] This minigame needs at least @1 players!", mod_ref.min_players))) + return end end local ID = next_available_ID(mod_ref) @@ -401,6 +410,10 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player arena.max_players = max_players end + if arena.min_players < mod_ref.min_players then + arena.min_players = mod_ref.min_players + end + -- eventuali squadre if #mod_ref.teams > 1 then arena.teams = {} @@ -572,7 +585,6 @@ function arena_lib.change_arena_property(sender, mod, arena_name, property, new_ return end setfenv(func, {}) - local good, result = pcall(func) -- se le operazioni della funzione causano errori @@ -617,9 +629,18 @@ function arena_lib.change_players_amount(sender, mod, arena_name, min_players, m minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!"))) arena.min_players = old_min_players arena.max_players = old_max_players - return end + return end - -- se i giocatori massimi sono cambiati, svuoto i vecchi punti rinascita per evitare problemi + local mod_ref = arena_lib.mods[mod] + + -- se ha meno giocatorɜ di quellɜ richiestɜ dal minigioco, annullo + if arena.min_players < mod_ref.min_players then + minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] This minigame needs at least @1 players!", mod_ref.min_players))) + arena.min_players = old_min_players + arena.max_players = old_max_players + return end + + -- se lɜ giocatorɜ massimɜ sono cambiatɜ, svuoto i vecchi punti rinascita per evitare problemi if max_players and old_max_players ~= max_players then arena_lib.set_spawner(sender, mod, arena_name, nil, "deleteall", nil, in_editor) end @@ -1349,7 +1370,7 @@ function init_storage(mod, mod_ref) local arena_max_players = arena.max_players * #arena.teams -- reimposto punti rinascita se ho cambiato il numero di squadre - if arena_max_players ~= #arena.spawn_points then + if arena_max_players ~= #arena.spawn_points and arena.enabled then to_update = true arena.enabled = false arena.spawn_points = {} @@ -1357,6 +1378,19 @@ function init_storage(mod, mod_ref) " has been reset due to not coinciding with the maximum amount of players (" .. arena_max_players .. ")") end + -- aggiorna lɜ giocatorɜ minimɜ in caso di conflitto + if arena.min_players < mod_ref.min_players then + arena.min_players = mod_ref.min_players + if arena.max_players < mod_ref.min_players then + arena.max_players = mod_ref.min_players + arena.spawn_points = {} + arena.enabled = false + minetest.log("action", "[ARENA_LIB] spawn points of arena " .. arena.name .. + " has been reset due to not coinciding with the maximum amount of players (" .. arena_max_players .. ")") + end + to_update = true + end + -- gestione tempo if mod_ref.time_mode == "none" and arena.initial_time then -- se avevo abilitato il tempo e ora l'ho rimosso, lo tolgo dalle arene arena.initial_time = nil diff --git a/src/editor/tools_players.lua b/src/editor/tools_players.lua index 438a8cc..8ffd5a8 100755 --- a/src/editor/tools_players.lua +++ b/src/editor/tools_players.lua @@ -26,7 +26,6 @@ minetest.register_node("arena_lib:players_min", { 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 players_amount = user:get_meta():get_int("arena_lib_editor.players_number") diff --git a/src/editor/tools_spawner.lua b/src/editor/tools_spawner.lua index 9a08167..b4db73d 100755 --- a/src/editor/tools_spawner.lua +++ b/src/editor/tools_spawner.lua @@ -35,7 +35,6 @@ minetest.register_tool("arena_lib:spawner_add", { 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") @@ -54,7 +53,6 @@ minetest.register_tool("arena_lib:spawner_remove", { 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") @@ -82,7 +80,6 @@ minetest.register_tool("arena_lib:spawner_team_add", { 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") @@ -103,7 +100,6 @@ minetest.register_tool("arena_lib:spawner_team_remove", { 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") @@ -130,7 +126,6 @@ minetest.register_tool("arena_lib:spawner_team_switch", { 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") @@ -163,7 +158,6 @@ minetest.register_tool("arena_lib:spawner_deleteall", { 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 p_name = user:get_player_name() @@ -184,7 +178,6 @@ minetest.register_tool("arena_lib:spawner_team_deleteall", { 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")