Teams: they can be enabled/disabled per arena (both via editor and CLI)
parent
043053690f
commit
81c74d59e6
|
@ -16,7 +16,7 @@ minetest.register_tool("arena_lib:editor_players", {
|
|||
local arena_name = user:get_meta():get_string("arena_lib_editor.arena")
|
||||
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
|
||||
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
minetest.chat_send_player(user:get_player_name(), minetest.colorize("#ffdddd", "[arena_lib] " .. S("Values are PER TEAM!")))
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ minetest.register_tool("arena_lib:editor_players", {
|
|||
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Players | num to set: @1 (left/right click slot #3 to change)", 2))
|
||||
|
||||
minetest.after(0, function()
|
||||
arena_lib.give_players_tools(user)
|
||||
arena_lib.give_players_tools(user, arena)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ local players_tools = {
|
|||
|
||||
minetest.register_tool("arena_lib:players_min", {
|
||||
|
||||
description = S("Players required"),
|
||||
description = S("Players required: "),
|
||||
inventory_image = "arenalib_tool_players_min.png",
|
||||
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
|
||||
on_place = function() end,
|
||||
|
@ -34,7 +34,7 @@ minetest.register_tool("arena_lib:players_min", {
|
|||
|
||||
minetest.register_tool("arena_lib:players_max", {
|
||||
|
||||
description = S("Players supported"),
|
||||
description = S("Players supported: "),
|
||||
inventory_image = "arenalib_tool_players_max.png",
|
||||
groups = {not_in_creative_inventory = 1, oddly_breakable_by_hand = "2"},
|
||||
on_place = function() end,
|
||||
|
@ -71,8 +71,60 @@ minetest.register_tool("arena_lib:players_change", {
|
|||
|
||||
|
||||
|
||||
function arena_lib.give_players_tools(player)
|
||||
minetest.register_tool("arena_lib:players_teams_on", {
|
||||
|
||||
description = S("Teams: on (click to toggle off)"),
|
||||
inventory_image = "arenalib_tool_players_teams_on.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")
|
||||
|
||||
arena_lib.toggle_teams_per_arena(user:get_player_name(), mod, arena_name, 0)
|
||||
|
||||
minetest.after(0, function()
|
||||
user:get_inventory():set_stack("main", 5, "arena_lib:players_teams_off")
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_tool("arena_lib:players_teams_off", {
|
||||
|
||||
description = S("Teams: off (click to toggle on)"),
|
||||
inventory_image = "arenalib_tool_players_teams_off.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")
|
||||
|
||||
arena_lib.toggle_teams_per_arena(user:get_player_name(), mod, arena_name, 1)
|
||||
|
||||
minetest.after(0, function()
|
||||
user:get_inventory():set_stack("main", 5, "arena_lib:players_teams_on")
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
function arena_lib.give_players_tools(player, arena)
|
||||
player:get_inventory():set_list("main", players_tools)
|
||||
|
||||
if arena.teams_enabled then
|
||||
player:get_inventory():set_stack("main", 5, "arena_lib:players_teams_on")
|
||||
else
|
||||
player:get_inventory():set_stack("main", 5, "arena_lib:players_teams_off")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
90
api.lua
90
api.lua
|
@ -25,6 +25,7 @@ local arena_default = {
|
|||
sign = {},
|
||||
players = {}, -- KEY: player name, VALUE: {kills, deaths, teamID, player_properties}
|
||||
teams = {-1},
|
||||
teams_enabled = false,
|
||||
players_amount = 0,
|
||||
players_amount_per_team = nil,
|
||||
spawn_points = {}, -- KEY: ids, VALUE: {position, team}
|
||||
|
@ -257,8 +258,9 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player
|
|||
end
|
||||
|
||||
-- eventuali team
|
||||
if next(mod_ref.teams) then
|
||||
if #mod_ref.teams > 1 then
|
||||
arena.teams = {}
|
||||
arena.teams_enabled = true
|
||||
arena.players_amount_per_team = {}
|
||||
|
||||
for k, t_name in pairs(mod_ref.teams) do
|
||||
|
@ -374,6 +376,58 @@ end
|
|||
|
||||
|
||||
|
||||
function arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable) -- enable can be 0 or 1
|
||||
|
||||
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
|
||||
|
||||
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
|
||||
|
||||
-- se non ci sono team nella mod, annullo
|
||||
if #arena_lib.mods[mod].teams == 1 then
|
||||
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Teams are not enabled!")))
|
||||
return end
|
||||
|
||||
-- se i team sono già in quello stato, annullo
|
||||
if enable == arena.teams_enabled then
|
||||
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Nothing to do here!")))
|
||||
return end
|
||||
|
||||
-- se abilito
|
||||
if enable == 1 then
|
||||
arena.teams = {}
|
||||
arena.players_amount_per_team = {}
|
||||
|
||||
for k, t_name in pairs(arena_lib.mods[mod].teams) do
|
||||
arena.teams[k] = {name = t_name}
|
||||
arena.players_amount_per_team[k] = 0
|
||||
end
|
||||
|
||||
arena.teams_enabled = true
|
||||
|
||||
minetest.chat_send_player(sender, S("Teams successfully enabled for the arena @1", arena_name))
|
||||
|
||||
-- se disabilito
|
||||
elseif enable == 0 then
|
||||
arena.teams = {-1}
|
||||
arena.players_amount_per_team = nil
|
||||
arena.teams_enabled = false
|
||||
minetest.chat_send_player(sender, S("Teams successfully disabled for the arena @1", arena_name))
|
||||
|
||||
-- sennò ho scritto male e annullo
|
||||
else
|
||||
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
|
||||
return
|
||||
end
|
||||
|
||||
-- svuoto i vecchi spawner per evitare problemi
|
||||
arena_lib.set_spawner(sender, mod, arena_name, nil, "deleteall")
|
||||
|
||||
arena_lib.update_sign(arena)
|
||||
update_storage(false, mod, id, arena)
|
||||
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"
|
||||
|
@ -694,7 +748,7 @@ function arena_lib.disable_arena(sender, mod, arena_name)
|
|||
end
|
||||
-- svuoto l'arena
|
||||
arena.players_amount = 0
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
for k, v in pairs(arena.players_amount_per_team) do
|
||||
arena.players_amount_per_team[k] = 0
|
||||
end
|
||||
|
@ -738,7 +792,7 @@ function arena_lib.load_arena(mod, arena_ID)
|
|||
local sorted_team_players = {}
|
||||
|
||||
-- randomizzo gli spawner se non è a team
|
||||
if #arena.teams == 1 then
|
||||
if not arena.teams_enabled 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]
|
||||
|
@ -787,7 +841,7 @@ function arena_lib.load_arena(mod, arena_ID)
|
|||
})
|
||||
|
||||
-- teletrasporto i giocatori
|
||||
if #arena.teams == 1 then
|
||||
if not arena.teams_enabled 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].teamID)
|
||||
|
@ -955,7 +1009,7 @@ function arena_lib.end_arena(mod_ref, mod, arena)
|
|||
players_in_game[pl_name] = nil
|
||||
arena.players_amount = 0
|
||||
arena.timer_current = nil
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
for i = 1, #arena.teams do
|
||||
arena.players_amount_per_team[i] = 0
|
||||
end
|
||||
|
@ -995,7 +1049,7 @@ function arena_lib.end_arena(mod_ref, mod, arena)
|
|||
end
|
||||
|
||||
-- e rimuovo quelle eventuali di team
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
for i = 1, #arena.teams do
|
||||
for t_property, _ in pairs(mod_ref.team_properties) do
|
||||
arena.teams[i][t_property] = nil
|
||||
|
@ -1165,7 +1219,7 @@ function arena_lib.remove_player_from_arena(p_name, reason)
|
|||
players_in_game[p_name] = nil
|
||||
players_in_queue[p_name] = nil
|
||||
arena.players_amount = arena.players_amount - 1
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
local p_team_ID = arena.players[p_name].teamID
|
||||
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
|
||||
end
|
||||
|
@ -1189,7 +1243,7 @@ function arena_lib.remove_player_from_arena(p_name, reason)
|
|||
end
|
||||
|
||||
-- se invece è in partita, ha i team e sono rimasti solo i giocatori di un team, il loro team vince
|
||||
elseif arena.in_game and #arena.teams > 1 and arena.players_amount < arena.min_players * #arena.teams then
|
||||
elseif arena.in_game and arena.teams_enabled and arena.players_amount < arena.min_players * #arena.teams then
|
||||
|
||||
local team_to_compare
|
||||
|
||||
|
@ -1401,7 +1455,7 @@ end
|
|||
|
||||
|
||||
function arena_lib.get_random_spawner(arena, team_ID)
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
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
|
||||
|
@ -1468,11 +1522,25 @@ function init_storage(mod, mod_ref)
|
|||
end
|
||||
--^------------------ LEGACY UPDATE, to remove in 4.0 -------------------^
|
||||
|
||||
--v------------------ LEGACY UPDATE, to remove in 5.0 -------------------v
|
||||
-- team per arena for 3.2.0 and lesser versions
|
||||
if arena.teams_enabled == nil then
|
||||
to_update = true
|
||||
if #arena.teams > 1 then
|
||||
arena.teams_enabled = true
|
||||
else
|
||||
arena.teams_enabled = false
|
||||
end
|
||||
minetest.log("action", "[ARENA_LIB] Added '.teams_enabled' property from 3.2.0")
|
||||
end
|
||||
--^------------------ LEGACY UPDATE, to remove in 5.0 -------------------^
|
||||
|
||||
-- gestione team
|
||||
if #arena.teams > 1 and not next(mod_ref.teams) then -- se avevo abilitato i team e ora li ho rimossi
|
||||
if arena.teams_enabled 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.teams_enabled = false
|
||||
elseif next(mod_ref.teams) and arena.teams_enabled then -- sennò li genero per tutte le arena con teams_enabled
|
||||
arena.players_amount_per_team = {}
|
||||
arena.teams = {}
|
||||
|
||||
|
|
2
chat.lua
2
chat.lua
|
@ -5,7 +5,7 @@ minetest.register_on_chat_message(function(p_name, message)
|
|||
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(p_name)]
|
||||
local arena = arena_lib.get_arena_by_player(p_name)
|
||||
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
if mod_ref.is_team_chat_default then
|
||||
arena_lib.send_message_players_in_arena(arena, minetest.colorize(mod_ref.chat_team_color, mod_ref.chat_team_prefix .. minetest.format_chat_message(p_name, message)), arena.players[p_name].teamID)
|
||||
else
|
||||
|
|
|
@ -107,7 +107,7 @@ minetest.register_chatcommand("t", {
|
|||
minetest.chat_send_player(name, minetest.colorize("#e6482e" , S("[!] Teams are not enabled!")))
|
||||
return false end
|
||||
|
||||
arena_lib.send_message_players_in_arena(arena, minetest.colorize(mod_ref.chat_team_color, mod_ref.chat_team_prefix .. minetest.format_chat_message(name, msg), teamID))
|
||||
arena_lib.send_message_players_in_arena(arena, minetest.colorize(mod_ref.chat_team_color, mod_ref.chat_team_prefix .. minetest.format_chat_message(name, msg)), teamID)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
|
|
@ -33,12 +33,12 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
|
|||
local players_inside_per_team = ""
|
||||
|
||||
-- concateno eventuali team
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled 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 i = 1, #arena.teams do
|
||||
teams = teams .. "'" .. arena.teams[i] .. "' "
|
||||
players_inside_per_team = players_inside_per_team .. "'" .. arena.teams[i] .. "' : " .. arena.players_amount_per_team[i] .. " "
|
||||
teams = teams .. "'" .. arena.teams[i].name .. "' "
|
||||
players_inside_per_team = players_inside_per_team .. "'" .. arena.teams[i].name .. "' : " .. arena.players_amount_per_team[i] .. " "
|
||||
end
|
||||
players_inside_per_team = minetest.colorize("#eea160", S("Players inside per team: ")) .. minetest.colorize("#cfc6b8", players_inside_per_team) .. "\n"
|
||||
else
|
||||
|
@ -85,7 +85,7 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
|
|||
|
||||
-- calcolo coordinate spawn point
|
||||
local spawners_pos = ""
|
||||
if #arena.teams > 1 then
|
||||
if arena.teams_enabled then
|
||||
|
||||
for i = 1, #arena.teams do
|
||||
spawners_pos = spawners_pos .. arena.teams[i].name .. ": "
|
||||
|
|
|
@ -11,6 +11,9 @@ 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
|
||||
Players amount successfully changed ( min @1 | max @2 )=Numero dei giocatori modificato con successo ( min @1 | max @2 )
|
||||
[!] Teams are not enabled!=[!] Le squadre non sono abilitate!
|
||||
Teams successfully enabled for the arena @1=Squadre abilitate con successo nell'arena @1
|
||||
Teams successfully disabled for the arena @1=Squadre disabilitate con successo nell'arena @1
|
||||
[!] 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!
|
||||
|
@ -58,7 +61,6 @@ Quit an ongoing game=Abbandona una partita in corso
|
|||
[!] You can't perform this action if you're the only one left!=[!] Non puoi eseguire quest'azione se sei l'unico giocatore rimasto!
|
||||
Write a message in the arena global chat while in a game=Scrive un messaggio nella chat globale dell'arena mentre si è in una partita
|
||||
Write a message in the arena team chat while in a game (if teams are enabled)=Scrive un messaggio nella chat di squadra dell'arena mentre si è in una partita (se le squadre sono abilitate)
|
||||
[!] Teams are not enabled!=[!] Le squadre non sono abilitate!
|
||||
|
||||
# debug_utilities.lua
|
||||
name: =nome:
|
||||
|
@ -137,6 +139,11 @@ Go back=Torna indietro
|
|||
Enable and leave=Abilita ed esci
|
||||
Leave the editor=Esci dall'editor
|
||||
|
||||
# _editor/tools_players.lua
|
||||
Change the current number=Cambia il numero attuale
|
||||
Teams: on (click to toggle off)=Squadre: attive (premi per disattivare)
|
||||
Teams: off (click to toggle on)=Squadre: non attive (premi per attivare)
|
||||
|
||||
# _editor/tools_spawner.lua
|
||||
Add spawner=Aggiungi spawner
|
||||
Remove spawner=Rimuovi spawner
|
||||
|
|
|
@ -11,6 +11,9 @@ Arena @1 successfully created=
|
|||
Arena @1 successfully removed=
|
||||
Arena @1 successfully renamed in @2=
|
||||
Players amount successfully changed ( min @1 | max @2 )=
|
||||
[!] Teams are not enabled!=
|
||||
Teams successfully enabled for the arena @1=
|
||||
Teams successfully disabled for the arena @1=
|
||||
[!] This team doesn't exist!=
|
||||
[!] No spawner with that ID to overwrite!=
|
||||
[!] No team must be specified for this function!=
|
||||
|
@ -58,7 +61,6 @@ Quit an ongoing game=
|
|||
[!] You can't perform this action if you're the only one left!=
|
||||
Write a message in the arena global chat while in a game=
|
||||
Write a message in the arena team chat while in a game (if teams are enabled)=
|
||||
[!] Teams are not enabled!=
|
||||
|
||||
# debug_utilities.lua
|
||||
name: =
|
||||
|
@ -137,6 +139,10 @@ Go back=
|
|||
Enable and leave=
|
||||
Leave the editor=
|
||||
|
||||
# _editor/tools_players.lua
|
||||
Change the current number=
|
||||
Teams: on (click to toggle off)=
|
||||
Teams: off (click to toggle on)=
|
||||
|
||||
# _editor/tools_spawner.lua
|
||||
Add spawner=
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 218 B |
Binary file not shown.
After Width: | Height: | Size: 198 B |
Loading…
Reference in New Issue