This commit is contained in:
Giov4 2023-02-05 21:06:20 +01:00
commit d36819b5cc
17 changed files with 266 additions and 102 deletions

22
DOCS.md
View File

@ -13,7 +13,7 @@
* [1.5.1 Arena properties](#151-arena-properties)
* [1.5.1.1 Updating non temporary properties via code](#1511-updating-non-temporary-properties-via-code)
* [1.5.1.2 Updating properties for old arenas](#1512-updating-properties-for-old-arenas)
* [1.5.2 Player properties](#152-player-properties)
* [1.5.2 Player and spectator properties](#152-player-and-spectator-properties)
* [1.5.3 Team properties](#153-team-properties)
* [1.6 HUD](#16-hud)
* [1.7 Utils](#17-utils)
@ -54,7 +54,8 @@ The second field, on the contrary, is a table of optional parameters: they defin
* `name`: (string) the name of your minigame. If not specified, it takes the name used to register the minigame
* `prefix`: (string) what's going to appear in most of the lines printed by your mod. Default is `[<mg name>] `, where `<mg name>` is the name of your minigame
* `icon`: (string) optional icon to represent your minigame. Currently unused by default (`nil`), it comes in handy for external mods
* `teams`: (table) contains team names. If not declared, your minigame won't have teams and the table will be equal to `{-1}`. You can add as many teams as you like, as the number of spawners (and players) will be multiplied by the number of teams (so `max_players = 4` * 3 teams = `max_players = 12`)
* `teams`: (table) contains team names. If not declared, your minigame won't have teams and the table will be equal to `{-1}`. You can add as many teams as you like, as the number of spawners (and players) will be multiplied by the number of teams (so `max_players = 4` * 3 teams = 12 players in total)
* `variable_teams_amount`: (boolean) whether to support a variable amount of teams per arena. It requires `teams`. Default is `false`
* `teams_color_overlay`: (table) [color strings](https://drafts.csswg.org/css-color/#named-colors). It applies a color overlay onto the players' skin according to their team, to better distinguish them. It requires `teams`. Default is `nil`
* `is_team_chat_default`: (bool) whether players messages in a game should be sent to their teammates only. It requires `teams`, default is false
* `chat_all_prefix`: (string) prefix for every message sent in arena, team chat aside. Default is `[arena] ` (geolocalised)
@ -87,6 +88,7 @@ The second field, on the contrary, is a table of optional parameters: they defin
* `properties`: see [1.5 Additional properties](#15-additional-properties)
* `temp_properties`: ^
* `player_properties`: ^
* `spectator_properties`: ^
* `team_properties`: ^ (it won't work if `teams` hasn't been declared)
### 1.1 Per server configuration
@ -124,8 +126,6 @@ A few more are available for players having the `arenalib_admin` privilege:
* `list <minigame>`: lists all the arenas of `<minigame>`
* `remove (<minigame>) <arena>`: deletes an arena
* `settings <minigame>`: changes `<minigame>` settings
* `/forceend mod arena_name`: forcibly ends an ongoing game
* `/flusharena mod arena_name`: restores a broken arena (when not in progress)
### 1.4 Callbacks
Callbacks are divided in two types: minigame callbacks and global callbacks. The former allow you to customise your mod even more, whilst the latter are great for external mods that want to customise the experience outside of a specific minigame (e.g. a server giving players some currency when winning, a HUD telling players what game is in progress).
@ -143,7 +143,7 @@ Callbacks are divided in two types: minigame callbacks and global callbacks. The
* `arena_lib.on_join(mod, function(p_name, arena, as_spectator, was_spectator))`: called when a user joins an ongoing match. `as_spectator` returns true if they join as a spectator. `was_spectator` returns true if the user was spectating the arena when joining as an actual player
* `arena_lib.on_death(mod, function(arena, p_name, reason))`: called when a player dies
* `arena_lib.on_respawn(mod, function(arena, p_name))`: called when a player respawns
* `arena_lib.on_change_spectated_target(mod, function(arena, sp_name, t_type, t_name, prev_type, prev_spectated))`: called when a spectator (`sp_name`) changes who or what they're spectating, including when they get assigned someone to spectate at entering the arena.
* `arena_lib.on_change_spectated_target(mod, function(arena, sp_name, t_type, t_name, prev_type, prev_spectated, is_forced))`: called when a spectator (`sp_name`) changes who or what they're spectating, including when they get assigned someone to spectate at entering the arena. `is_forced` returns true when the change is a result of `spectate_target(...)`
* `t_type` represents the type of the target (either `"player"`, `"entity"` or `"area"`)
* `t_name` its name. If it's an entity or an area, it'll be the name used to register it through the `arena_lib.add_spectate...` functions
* if they were following someone/something else earlier, `prev_type` and `prev_spectated` follow the same logic of the aforementioned parameters
@ -225,8 +225,8 @@ Instead, the right way to permanently update a property for an arena is calling
##### 1.5.1.2 Updating properties for old arenas
This is done automatically by arena_lib every time you change the properties declaration in `register_minigame`, so don't worry. Just, keep in mind that when a property is removed, it'll be removed from every arena; so if you're not sure about what you're doing, do a backup first.
#### 1.5.2 Player properties
These are a particular type of temporary properties, as they're attached to every player in the arena. Let's say you now want to keep track of how many kills a player does in a streak without dying. You just need to create a killstreak parameter, declaring it like so
#### 1.5.2 Player and spectator properties
These are a particular type of temporary properties, as they're attached to every player/spectator in the arena. Let's say you now want to keep track of how many kills a player does in a streak without dying. You just need to create a killstreak parameter, declaring it like so
```lua
arena_lib.register_minigame("mymod", {
--stuff
@ -280,6 +280,7 @@ There are also some other functions which might turn useful. They are:
* `arena_lib.add_spectate_area(mod, arena, pos_name, pos)`: same as `add_spectate_entity`, but it adds an area instead. `pos` is a table containing the coordinates of the area to spectate
* `arena_lib.remove_spectate_entity(mod, arena, e_name)`: removes an entity from the spectatable entities of an ongoing match
* `arena_lib.remove_spectate_area(mod, arena, pos_name)`: removes an area from the spectatable areas of an ongoing match
* `arena_lib.spectate_target(mod, arena, sp_name, type, t_name)`: forces `sp_name` to spectate a specific target, if exists. `type` is a string that can either be `"player"`, `"entity"` or `"area"`
* `arena_lib.is_player_spectating(sp_name)`: returns whether a player is spectating a match, as a boolean
* `arena_lib.is_player_spectated(p_name)`: returns whether a player is being spectated
* `arena_lib.is_entity_spectated(mod, arena_name, e_name)`: returns whether an entity is being spectated
@ -300,7 +301,8 @@ There are also some other functions which might turn useful. They are:
* `arena_lib.get_players_in_minigame(mod, <to_player>)`: returns a table containing as value either the names of all the players inside the specified minigame (`mod`) or, if `to_player` is `true`, the players themselves
* `arena_lib.get_players_in_team(arena, team_ID, <to_player>)`: returns a table containing as value either the names of the players inside the specified team or, if `to_player` is `true`, the players themselves
* `arena_lib.get_active_teams(arena)`: returns an ordered table having as values the ID of teams that are not empty
* `arena_lib.get_player_spectators(p_name)`: returns a list containing all the people currently spectating `p_name`. Format `{sp_name = true}`
* `arena_lib.get_target_spectators(mod, arena_name, type, t_name)`: returns a list containing all the spectators currently following `t_name`. Format `{sp_name = true}`. For players, consider using the next function instead
* `arena_lib.get_player_spectators(p_name)`: Like `get_target_spectators(...)` but cleaner and just for players. It's cleaner since there can't be two players with the same name, contrary to areas and entities
* `arena_lib.get_player_spectated(sp_name)`: returns the player `sp_name` is currently spectating, if any
* `arena_lib.get_spectate_entities(mod, arena_name)`: returns a table containing all the spectatable entities of `arena_name`, if any. Format `{e_name = entity}`, where `e_name` is the name used to register the entity in `add_spectate_entity(...)` and `entity` the `luaentity` table
* `arena_lib.get_spectate_areas(mod, arena_name)`: same as in `get_spectate_entities(...)` but for areas. Entities returned in the table are the dummy ObjectRef entities put at the area coordinates
@ -434,7 +436,9 @@ If you don't want to rely on the hotbar, or you want both the editor and the com
`arena_lib.set_thumbnail(sender, mod, arena_name, thumbnail)`: changes the thumbnail of the arena. `thumbnail` is the name of the file, including its extension. It must be inside the `arena_lib/Thumbnails` world folder.
##### 2.2.2.2 Players management
`arena_lib.change_players_amount(sender, mod, arena_name, min_players, max_players)` changes the amount of players in a specific arena. It also works by specifying only one field (such as `([...] myarena, 3)` or `([...] myarena, nil, 6)`). It returns true if it succeeded.
`arena_lib.change_players_amount(sender, mod, arena_name, min_players, max_players)` changes the amount of players in a specific arena. It also works by specifying only one field (such as `([...] myarena, 3)` or `([...] myarena, nil, 6)`). It returns true if it succeeds.
`arena_lib.change_teams_amount(sender, mod, arena_name, amount)` changes the amount of teams in a specific arena. It'll use the first N teams declared, where N is `amount`. It returns `true` if it succeeds.
##### 2.2.2.3 Enabling/Disabling teams
`arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable)` enables/disables teams per single arena. `enable` is an int, where `0` disables teams and `1` enables them.

View File

@ -7,8 +7,6 @@ arena_lib = {}
dofile(srcpath .. "/_load.lua")
dofile(modpath .. "/libs/chatcmdbuilder.lua")
dofile(minetest.get_worldpath() .. "/arena_lib/SETTINGS.lua")
dofile(srcpath .. "/admin_tools/entrances.lua")
dofile(srcpath .. "/admin_tools/minigame_settings.lua")
dofile(srcpath .. "/api/core.lua")

View File

@ -1,4 +1,4 @@
# version 5.4.0
# version 5.5.0-dev
# author(s): Zughy
# reviewer(s):
# textdomain: arena_lib
@ -21,11 +21,20 @@ message=messaggio
Writes a message in the arena global chat while in a game=Scrive un messaggio nella chat globale dell'arena mentre si è in una partita
Writes 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!
# TODO: for when /arenas help is implemented
Kicks a player from an ongoing game=Caccia un giocatore da una partita in corso
Tweaks the minigame settings for the current server=Modifica le impostazioni del minigioco per il server corrente
DEBUG ONLY: reset the properties of a bugged arena=SOLO DEBUG: ripristina le proprietà di un'arena rotta
Creates an arena for the specified minigame=Crea un'arena per il minigioco specificato
Disables an arena=Disabilita un'arena
Enters the arena editor=Entra nell'editor dell'arena
Enables an arena=Abilita un'arena
Changes the entrance types of the specified minigame=Cambia i tipi d'entrata del minigioco specificato
DEBUG ONLY - resets the properties of a bugged arena=SOLO DEBUG - ripristina le proprietà di un'arena rotta
Forcibly ends an ongoing game=Forza la conclusione di una partita in corso
Lists all the installed minigames, alphabetically sorted=Elenca tutti i minigiochi installati, in ordine alfabetico
See @1=Vedi @1
Prints all the arena's info=Stampa a schermo tutte le informazioni dell'arena
Kicks a player from an ongoing game=Caccia un giocatore da una partita in corso
Lists all the arenas of the specified minigame=Elenca tutte le arene del minigioco specificato
Deletes an arena=Cancella un'arena
Tweaks the minigame settings for the current server=Modifica le impostazioni del minigioco per il server corrente
# admin_tools/entrances.lua
[!] You can't perform this action while in game!=[!] Non puoi eseguire quest'azione mentre sei in partita!
@ -54,6 +63,7 @@ Arena @1 successfully renamed in @2=Arena @1 rinominata con successo in @2
[!] File not found!=[!] File non trovato!
Players amount successfully changed ( min @1 | max @2 )=Numero dei giocatori modificato con successo ( min @1 | max @2 )
[!] Nothing to do here!=[!] È già tutto a posto qui!
Teams amount successfully changed (@1)=Numero delle squadre modificato con successo (@1)
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!
@ -140,7 +150,7 @@ Arena_lib editor | Now editing: @1=Arena_lib editor | Stai modificando: @1
# editor/editor_icons.lua
Players=Giocatori
Players | num to set: @1 (left/right click slot #3 to change)=Giocatori | num: @1 (click sx/dx su slot #3 per cambiare)
Players | num to set: @1 (left/right click slot #4 to change)=Giocatori | num: @1 (click sx/dx su slot #4 per cambiare)
Values are PER TEAM!=I valori sono PER SQUADRA!
Spawners=Spawner
Spawners | sel. ID: @1 (right click slot #2 to change)=Spawner | ID sel.: @1 (tasto dx su slot #2 per cambiare)
@ -169,6 +179,9 @@ Global light=Luce globale
Shadows=Ombre
# editor/tools_players.lua
Players required=Giocatori minimi
Players supported=Giocatori massimi
Teams amount=Numero squadre
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)
@ -321,4 +334,4 @@ Team properties: =Proprietà squadra:
[!] The arena is already full!=[!] L'arena è già piena!
#utils/utils.lua
You've joined team @1=Ti sei unito alla squadra @1
You've joined team @1=Ti sei unito alla squadra @1

View File

@ -1,4 +1,4 @@
# version 5.4.0
# version 5.5.0-dev
# author(s):
# reviewer(s):
# textdomain: arena_lib
@ -21,11 +21,20 @@ message=
Writes a message in the arena global chat while in a game=
Writes a message in the arena team chat while in a game (if teams are enabled)=
[!] Teams are not enabled!=
#TODO: for when /arenas help is implemented
Kicks a player from an ongoing game=
Tweaks the minigame settings for the current server=
DEBUG ONLY: reset the properties of a bugged arena=
Creates an arena for the specified minigame=
Disables an arena=
Enters the arena editor=
Enables an arena=
Changes the entrance types of the specified minigame=
DEBUG ONLY - resets the properties of a bugged arena=
Forcibly ends an ongoing game=
Lists all the installed minigames, alphabetically sorted=
See @1=
Prints all the arena's info=
Kicks a player from an ongoing game=
Lists all the arenas of the specified minigame=
Deletes an arena=
Tweaks the minigame settings for the current server=
# admin_tools/entrances.lua
[!] You can't perform this action while in game!=
@ -54,6 +63,7 @@ Arena @1 successfully renamed in @2=
[!] File not found!=
Players amount successfully changed ( min @1 | max @2 )=
[!] Nothing to do here!=
Teams amount successfully changed (@1)=
Teams successfully enabled for the arena @1=
Teams successfully disabled for the arena @1=
[!] This team doesn't exist!=
@ -139,7 +149,7 @@ Arena_lib editor | Now editing: @1=
# editor/editor_icons.lua
Players=
Players | num to set: @1 (left/right click slot #3 to change)=
Players | num to set: @1 (left/right click slot #4 to change)=
Values are PER TEAM!=
Spawners=
Spawners | sel. ID: @1 (right click slot #2 to change)=
@ -168,6 +178,9 @@ Global light=
Shadows=
# editor/tools_players.lua
Players required=
Players supported=
Teams amount=
Change the current number=
Teams: on (click to toggle off)=
Teams: off (click to toggle on)=
@ -320,4 +333,4 @@ Team properties: =
[!] The arena is already full!=
#utils/utils.lua
You've joined team @1=
You've joined team @1=

View File

@ -1,3 +1,6 @@
----------------------------------------------
-----------------WORLD FOLDER-----------------
----------------------------------------------
local function load_world_folder()
local wrld_dir = minetest.get_worldpath() .. "/arena_lib"
local content = minetest.get_dir_list(wrld_dir)
@ -43,3 +46,17 @@ local function load_world_folder()
end
load_world_folder()
----------------------------------------------
-------------------SETTINGS-------------------
----------------------------------------------
dofile(minetest.get_worldpath() .. "/arena_lib/SETTINGS.lua")
-- deprecated, to remove in 7.0
if arena_lib.STORE_INVENTORY_MODE then
minetest.log("warning", "[ARENA_LIB] Setting 'STORE_INVENTORY_MODE' is of no use now, please delete it from SETTINGS.lua (inside the arena_lib world folder)")
end

View File

@ -97,6 +97,7 @@ function arena_lib.register_minigame(mod, def)
mod_ref.prefix = "[" .. mod_ref.name .. "] "
mod_ref.icon = def.icon
mod_ref.teams = {-1}
mod_ref.variable_teams_amount = false
mod_ref.teams_color_overlay = nil
mod_ref.is_team_chat_default = false
mod_ref.chat_all_prefix = "[" .. S("arena") .. "] "
@ -122,6 +123,7 @@ function arena_lib.register_minigame(mod, def)
mod_ref.properties = {}
mod_ref.temp_properties = {}
mod_ref.player_properties = {}
mod_ref.spectator_properties = {}
mod_ref.team_properties = {}
if def.prefix then
@ -131,12 +133,16 @@ function arena_lib.register_minigame(mod, def)
if def.teams and type(def.teams) == "table" then
mod_ref.teams = def.teams
if def.variable_teams_amount == true then
mod_ref.variable_teams_amount = true
end
if def.teams_color_overlay then
mod_ref.teams_color_overlay = def.teams_color_overlay
end
if def.is_team_chat_default == true then
mod_ref.is_team_chat_default = def.is_team_chat_default
mod_ref.is_team_chat_default = true
end
if def.chat_team_prefix then
@ -236,6 +242,10 @@ function arena_lib.register_minigame(mod, def)
mod_ref.player_properties = def.player_properties
end
if def.spectator_properties then
mod_ref.spectator_properties = def.spectator_properties
end
if def.team_properties then
mod_ref.team_properties = def.team_properties
end
@ -579,7 +589,7 @@ function arena_lib.change_players_amount(sender, mod, arena_name, min_players, m
arena.max_players = old_max_players
return end
-- se i giocatori massimi sono cambiati, svuoto i vecchi spawner per evitare problemi
-- se i giocatori massimi sono cambiati, 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
@ -590,7 +600,6 @@ function arena_lib.change_players_amount(sender, mod, arena_name, min_players, m
end
update_storage(false, mod, id, arena)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Players amount successfully changed ( min @1 | max @2 )", arena.min_players, arena.max_players))
-- ritorno true per procedere al cambio di stack nell'editor
@ -599,6 +608,52 @@ end
function arena_lib.change_teams_amount(sender, mod, arena_name, amount, in_editor)
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
if not in_editor then
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
end
-- se le squadre non sono abilitate, annullo
if not arena.teams_enabled then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Teams are not enabled!")))
return end
-- se il numero inserito è lo stesso delle squadre attuali, annullo
if #arena.teams == amount then
minetest.chat_send_player(sender, minetest.colorize("#cfc6b8", S("[!] Nothing to do here!")))
return end
local mod_ref = arena_lib.mods[mod]
-- se il numero è minore di 2, o maggiore delle squadre dichiarate nella mod, annullo
if amount < 2 or amount > #mod_ref.teams then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
return end
-- svuoto i vecchi punti rinascita per evitare problemi
arena_lib.set_spawner(sender, mod, arena_name, nil, "deleteall", nil, in_editor)
arena.teams = {}
for i = 1, amount do
arena.teams[i] = {name = mod_ref.teams[i]}
end
-- aggiorno l'entrata, se esiste
if arena.entrance then
arena_lib.entrances[arena.entrance_type].update(mod, arena)
end
update_storage(false, mod, id, arena)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Teams amount successfully changed (@1)", amount))
-- ritorno true per procedere al cambio di stack nell'editor
return true
end
function arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable, in_editor) -- enable can be 0 or 1
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
@ -606,14 +661,14 @@ function arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable, in_ed
if not ARENA_LIB_EDIT_PRECHECKS_PASSED(sender, arena) then return end
end
-- se non ci sono team nella mod, annullo
-- se non ci sono squadre nella mod, annullo
if not next(arena_lib.mods[mod].teams) 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
-- se le squadre 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!")))
minetest.chat_send_player(sender, minetest.colorize("#cfc6b8", S("[!] Nothing to do here!")))
return end
-- se abilito
@ -643,7 +698,7 @@ function arena_lib.toggle_teams_per_arena(sender, mod, arena_name, enable, in_ed
return
end
-- svuoto i vecchi spawner per evitare problemi
-- svuoto i vecchi punti rinascita per evitare problemi
arena_lib.set_spawner(sender, mod, arena_name, nil, "deleteall", nil, in_editor)
-- aggiorno l'entrata, se esiste
@ -1231,11 +1286,11 @@ function init_storage(mod, mod_ref)
-- gestione squadre
if arena.teams_enabled and not (#mod_ref.teams > 1) then -- se avevo abilitato le squadre e ora le ho rimosse
arena.players_amount_per_team = nil
arena.teams = {-1}
arena.teams_enabled = false
arena.players_amount_per_team = nil
arena.spectators_amount_per_team = nil
elseif #mod_ref.teams > 1 and arena.teams_enabled then -- sennò le genero per tutte le arene con teams_enabled
elseif #mod_ref.teams > 1 and not arena.teams_enabled then -- sennò le genero per tutte le arene con teams_enabled
arena.players_amount_per_team = {}
arena.spectators_amount_per_team = {}
arena.teams = {}
@ -1245,12 +1300,11 @@ function init_storage(mod, mod_ref)
arena.spectators_amount_per_team[k] = 0
arena.teams[k] = {name = t_name}
end
end
local arena_max_players = arena.max_players * #arena.teams
-- resetto punti rinascita se ho cambiato il numero di squadre
-- reimposto punti rinascita se ho cambiato il numero di squadre
if arena_max_players ~= #arena.spawn_points then
to_update = true
arena.enabled = false

View File

@ -74,7 +74,6 @@ function arena_lib.load_arena(mod, arena_ID)
-- per ogni giocatore...
for pl_name, _ in pairs(arena.players) do
operations_before_entering_arena(mod_ref, mod, arena, arena_ID, pl_name)
-- teletrasporto i giocatori
@ -481,9 +480,9 @@ function arena_lib.remove_player_from_arena(p_name, reason, executioner)
operations_before_leaving_arena(mod_ref, arena, p_name, reason)
arena.players_and_spectators[p_name] = nil
arena.past_present_players_inside[p_name] = nil
players_in_game[p_name] = nil
handle_leaving_callbacks(mod_ref, arena, p_name, reason, executioner, true)
players_in_game[p_name] = nil
-- sennò...
else

View File

@ -252,9 +252,10 @@ function arena_lib.get_players_amount_left_to_start_queue(arena)
if arena.teams_enabled then
players_required = 0
for _, amount in pairs(arena.players_amount_per_team) do
if arena.min_players - amount > 0 then
players_required = players_required + (arena.min_players - amount)
for i = 1, #arena.teams do
local p_per_team = arena.players_amount_per_team[i]
if arena.min_players - p_per_team > 0 then
players_required = players_required + (arena.min_players - p_per_team)
end
end
else

View File

@ -9,7 +9,6 @@ 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
@ -52,7 +51,6 @@ end
function arena_lib.get_active_teams(arena)
if #arena.teams == 1 then
minetest.log("warning", "Attempt to call get_active_teams in arena " .. arena.name .. " when teams are not enabled. Aborting...")
return end

View File

@ -158,29 +158,28 @@ ChatCmdBuilder.new("arenas", function(cmd)
end)
-- aiuto
--[[ TODO: per elencare comandi con descrizione geolocalizzata e con sintassi colorata tipo World Edit. In /help è orribile, rimuovere da lì. !Alcune traduzioni stanno già nei file di localizzazione!
cmd:sub("help", function(sender)
minetest.chat_send_player(sender, "TUTTI I VARI COMANDI")
minetest.chat_send_player(sender,
minetest.colorize("#00ffff", "/arenas create") .. " <" .. S("minigame") .. "> <" .. S("arena") .. "> (<pmin> <pmax>): " .. S("Creates an arena for the specified minigame") .. "\n"
.. minetest.colorize("#00ffff", "/arenas disable") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Disables an arena") .. "\n"
.. minetest.colorize("#00ffff", "/arenas edit") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Enters the arena editor") .. "\n"
.. minetest.colorize("#00ffff", "/arenas enable") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Enables an arena") .. "\n"
.. minetest.colorize("#00ffff", "/arenas entrances") .. " <" .. S("minigame") .. ">: " .. S("Changes the entrance types of the specified minigame") .. "\n"
.. minetest.colorize("#00ffff", "/arenas flush") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("DEBUG ONLY - resets the properties of a bugged arena") .. "\n"
.. minetest.colorize("#00ffff", "/arenas forceend") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Forcibly ends an ongoing game") .. "\n"
.. minetest.colorize("#00ffff", "/arenas gamelist") .. ": " .. S("Lists all the installed minigames, alphabetically sorted") .. "\n"
.. minetest.colorize("#00ffff", "/arenas glist") .. ": " .. S("See @1", "gamelist") .. "\n"
.. minetest.colorize("#00ffff", "/arenas info") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Prints all the arena's info") .. "\n"
.. minetest.colorize("#00ffff", "/arenas kick") .. " <" .. S("player") .. ">: " .. S("Kicks a player from an ongoing game") .. "\n"
.. minetest.colorize("#00ffff", "/arenas list") .. " <" .. S("minigame") .. ">: " .. S("Lists all the arenas of the specified minigame") .. "\n"
.. minetest.colorize("#00ffff", "/arenas remove") .. " (<" .. S("minigame") .. ">) <" .. S("arena") .. ">: " .. S("Deletes an arena") .. "\n"
.. minetest.colorize("#00ffff", "/arenas settings") .. " <" .. S("minigame") .. ">: " .. S("Tweaks the minigame settings for the current server")
)
end)
]]
end, {
params = "[ create | disable | edit | enable | entrances | flush | forceend | gamelist | glist | info | kick | list | remove | settings ]",
description = S("Manage arena_lib arenas; it requires arenalib_admin") .. "\n"
.. "/arenas create <" .. S("minigame") .. "> <" .. S("arena") .. "> (<pmin> <pmax>)\n"
.. "/arenas disable (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas edit (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas enable (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas entrances <" .. S("minigame") .. ">\n"
.. "/arenas flush (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas forceend (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas gamelist \n"
.. "/arenas glist \n"
.. "/arenas info (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas kick <" .. S("player") .. ">\n"
.. "/arenas list <" .. S("minigame") .. ">\n"
.. "/arenas remove (<" .. S("minigame") .. ">) <" .. S("arena") .. ">\n"
.. "/arenas settings <" .. S("minigame") .. ">",
params = "help",
description = S("Manage arena_lib arenas; it requires arenalib_admin"),
privs = { arenalib_admin = true }
})

View File

@ -7,13 +7,12 @@ local S = minetest.get_translator("arena_lib")
parties.register_on_pre_party_invite(function(sender, p_name)
-- se il party leader è in coda
-- se il capogruppo è in coda
if arena_lib.is_player_in_queue(sender) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] You can't perform this action while in queue!")))
return false end
-- se il party leader è in gioco
-- se il capogruppo è in gioco
if arena_lib.is_player_in_arena(sender) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] You can't perform this action while in game!")))
return false end
@ -24,13 +23,12 @@ end)
parties.register_on_pre_party_join(function(party_leader, p_name)
-- se il party leader è in coda
-- se il capogruppo è in coda
if arena_lib.is_player_in_queue(party_leader) then
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] The party leader must not be in queue to perform this action!")))
return false end
-- se il party leader è in gioco
-- se il capogruppo è in gioco
if arena_lib.is_player_in_arena(party_leader) then
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] The party leader must not be in game to perform this action!")))
return false end

View File

@ -22,7 +22,7 @@ minetest.register_tool("arena_lib:editor_players", {
user:get_meta():set_int("arena_lib_editor.players_number", 2)
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Players | num to set: @1 (left/right click slot #3 to change)", 2))
arena_lib.HUD_send_msg("hotbar", user:get_player_name(), S("Players | num to set: @1 (left/right click slot #4 to change)", 2))
arena_lib.give_players_tools(user:get_inventory(), mod, arena)
end
})

View File

@ -1,24 +1,24 @@
local S = minetest.get_translator("arena_lib")
local function change_players_number() end
local function change_amount() end
local players_tools = {
"", -- arena_lib:players_min
"", -- arena_lib:players_max
"", -- arena_lib:teams_amount
"arena_lib:players_change",
"",
"", -- arena_lib:players_teams_on/off
"",
"",
"arena_lib:editor_return",
"arena_lib:editor_quit",
}
minetest.register_tool("arena_lib:players_min", {
minetest.register_node("arena_lib:players_min", {
description = S("Players required: "),
description = S("Players required"),
inventory_image = "arenalib_tool_players_min.png",
wield_image = "arenalib_tool_players_min.png",
groups = {not_in_creative_inventory = 1},
@ -40,9 +40,9 @@ minetest.register_tool("arena_lib:players_min", {
minetest.register_tool("arena_lib:players_max", {
minetest.register_node("arena_lib:players_max", {
description = S("Players supported: "),
description = S("Players supported"),
inventory_image = "arenalib_tool_players_max.png",
wield_image = "arenalib_tool_players_max.png",
groups = {not_in_creative_inventory = 1},
@ -50,7 +50,6 @@ minetest.register_tool("arena_lib:players_max", {
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")
@ -62,6 +61,27 @@ minetest.register_tool("arena_lib:players_max", {
end
})
minetest.register_node("arena_lib:players_teams_amount", {
description = S("Teams amount"),
inventory_image = "arenalib_tool_players_teams_amount.png",
wield_image = "arenalib_tool_players_teams_amount.png",
groups = {not_in_creative_inventory = 1},
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 teams_amount = user:get_meta():get_int("arena_lib_editor.players_number")
if not arena_lib.change_teams_amount(user:get_player_name(), mod, arena_name, teams_amount, true) then return end
-- aggiorno la quantità se il cambio è andato a buon fine
user:set_wielded_item("arena_lib:players_teams_amount " .. teams_amount)
end
})
minetest.register_tool("arena_lib:players_change", {
@ -72,15 +92,15 @@ minetest.register_tool("arena_lib:players_change", {
on_drop = function() end,
on_use = function(itemstack, user, pointed_thing)
change_players_number(user, true)
change_amount(user, true)
end,
on_secondary_use = function(itemstack, placer, pointed_thing)
change_players_number(placer, false)
change_amount(placer, false)
end,
on_place = function(itemstack, user, pointed_thing)
change_players_number(user, false)
change_amount(user, false)
end
})
@ -101,7 +121,8 @@ minetest.register_tool("arena_lib:players_teams_on", {
arena_lib.toggle_teams_per_arena(user:get_player_name(), mod, arena_name, 0, true)
user:get_inventory():set_stack("main", 5, "arena_lib:players_teams_off")
user:get_inventory():set_stack("main", 3, "")
user:get_inventory():set_stack("main", 6, "arena_lib:players_teams_off")
end
})
@ -122,7 +143,11 @@ minetest.register_tool("arena_lib:players_teams_off", {
arena_lib.toggle_teams_per_arena(user:get_player_name(), mod, arena_name, 1, true)
user:get_inventory():set_stack("main", 5, "arena_lib:players_teams_on")
if arena_lib.mods[mod].variable_teams_amount then
local id, arena = arena_lib.get_arena_by_name(mod, arena_name)
user:get_inventory():set_stack("main", 3, "arena_lib:players_teams_amount " .. #arena.teams)
end
user:get_inventory():set_stack("main", 6, "arena_lib:players_teams_on")
end
})
@ -141,9 +166,12 @@ function arena_lib.give_players_tools(inv, mod, arena)
if #mod_ref.teams == 1 then return end
if arena.teams_enabled then
inv:set_stack("main", 5, "arena_lib:players_teams_on")
inv:set_stack("main", 6, "arena_lib:players_teams_on")
if mod_ref.variable_teams_amount then
inv:set_stack("main", 3, "arena_lib:players_teams_amount " .. #arena.teams)
end
else
inv:set_stack("main", 5, "arena_lib:players_teams_off")
inv:set_stack("main", 6, "arena_lib:players_teams_off")
end
end
@ -155,17 +183,17 @@ end
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function change_players_number(player, decrease)
local players_number = player:get_meta():get_int("arena_lib_editor.players_number")
function change_amount(player, decrease)
local amount = player:get_meta():get_int("arena_lib_editor.players_number")
if not decrease then
players_number = players_number +1
amount = amount +1
else
if players_number > 1 then
players_number = players_number -1
if amount > 1 then
amount = amount -1
else return end
end
player:get_meta():set_int("arena_lib_editor.players_number", players_number)
arena_lib.HUD_send_msg("hotbar", player:get_player_name(), S("Players | num to set: @1 (left/right click slot #3 to change)", players_number))
player:get_meta():set_int("arena_lib_editor.players_number", amount)
arena_lib.HUD_send_msg("hotbar", player:get_player_name(), S("Players | num to set: @1 (left/right click slot #4 to change)", amount))
end

View File

@ -83,10 +83,19 @@ function arena_lib.enter_spectate_mode(p_name, arena)
local hand = player:get_inventory():get_list("hand")
players_in_spectate_mode[p_name] = { minigame = mod, arenaID = arena_ID, teamID = team_ID, hand = hand}
arena.spectators[p_name] = true
arena.spectators[p_name] = {}
arena.players_and_spectators[p_name] = true
arena.spectators_amount = arena.spectators_amount + 1
-- eventuali proprietà aggiuntive
for k, v in pairs(arena_lib.mods[mod].spectator_properties) do
if type(v) == "table" then
arena.spectators[p_name][k] = table.copy(v)
else
arena.spectators[p_name][k] = v
end
end
-- applico mano finta
player:get_inventory():set_size("hand", 1)
player:get_inventory():add_item("hand", "arena_lib:spectate_hand")
@ -183,7 +192,7 @@ end
----------------------------
-- find next spectatatable target
-- find next spectatable target
----------------------------
function arena_lib.find_and_spectate_player(sp_name, change_team, go_counterwise)
@ -273,7 +282,6 @@ function arena_lib.find_and_spectate_player(sp_name, change_team, go_counterwise
else
local i = 1
for pl_name, _ in pairs(arena.players) do
if i == new_ID then
set_spectator(mod, arena.name, spectator, "player", pl_name, i)
return true
@ -362,9 +370,9 @@ function arena_lib.find_and_spectate_area(mod, arena, sp_name)
end
local i = 1
for pos_name, _ in pairs(areas_storage[mod][arena_name]) do
for ar_name, _ in pairs(areas_storage[mod][arena_name]) do
if i == new_ID then
set_spectator(mod, arena_name, spectator, "area", pos_name, i)
set_spectator(mod, arena_name, spectator, "area", ar_name, i)
return true
end
@ -380,8 +388,6 @@ end
---------------------CORE---------------------
----------------------------------------------
function arena_lib.add_spectate_entity(mod, arena, e_name, entity)
if not arena.in_game then return end
@ -483,6 +489,27 @@ end
function arena_lib.spectate_target(mod, arena, sp_name, type, t_name)
if type == "player" then
if arena.players_amount == 0 or not players_spectated[t_name]then return end
elseif type == "entity" then
if arena.spectate_entities_amount == 0 or not entities_spectated[mod][arena.name][t_name] then return end
elseif type == "area" then
if arena.spectate_areas_amount == 0 or not areas_spectated[mod][arena.name][t_name] then return end
else
return
end
-- sì, potrei richiedere direttamente 'spectator', ma per coesione con il resto dell'API e con il fatto che
-- arena_lib salva lɜ spettatorɜ indicizzandolɜ per nome, tanto vale una conversione in più qui
local spectator = minetest.get_player_by_name(sp_name)
local i = spectator:get_meta():get_int("arenalib_watchID") -- non c'è bisogno di calcolare l'ID, riapplico quello che già ha
set_spectator(mod, arena.name, spectator, type, t_name, i, true)
end
----------------------------------------------
--------------------UTILS---------------------
@ -524,6 +551,18 @@ end
function arena_lib.get_target_spectators(mod, arena_name, type, t_name)
if type == "player" then
return players_spectated[p_name]
elseif type == "entity" then
return entities_spectated[mod][arena_name][t_name]
elseif type == "area" then
return areas_spectated[mod][arena_name][t_name]
end
end
function arena_lib.get_player_spectated(sp_name)
if arena_lib.is_player_spectating(sp_name) then
return players_in_spectate_mode[sp_name].spectating
@ -544,14 +583,11 @@ end
----------------------------------------------
---------------FUNZIONI LOCALI----------------
----------------------------------------------
function set_spectator(mod, arena_name, spectator, type, name, i)
function set_spectator(mod, arena_name, spectator, type, name, i, is_forced)
local sp_name = spectator:get_player_name()
local prev_spectated = players_in_spectate_mode[sp_name].spectating
local prev_type = players_in_spectate_mode[sp_name].type
@ -602,7 +638,7 @@ function set_spectator(mod, arena_name, spectator, type, name, i)
-- eventuale codice aggiuntivo
if mod_ref.on_change_spectated_target then
local arena = arena_lib.get_arena_by_player(sp_name)
mod_ref.on_change_spectated_target(arena, sp_name, type, name, prev_type, prev_spectated)
mod_ref.on_change_spectated_target(arena, sp_name, type, name, prev_type, prev_spectated, is_forced)
end
end

View File

@ -69,6 +69,11 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
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"
if mod_ref.variable_teams_amount then
teams = "(" .. #arena.teams .. ") "
end
for i = 1, #arena.teams do
teams = teams .. "'" .. arena.teams[i].name .. "' "
players_inside_per_team = players_inside_per_team .. "'" .. arena.teams[i].name .. "' : " .. arena.players_amount_per_team[i] .. " "
@ -76,6 +81,7 @@ function arena_lib.print_arena_info(sender, mod, arena_name)
spectators_inside_per_team = spectators_inside_per_team .. "'" .. arena.teams[i].name .. "' : " .. arena.spectators_amount_per_team[i] .. " "
end
end
players_inside_per_team = minetest.colorize("#eea160", S("Players inside per team: ")) .. minetest.colorize("#cfc6b8", players_inside_per_team) .. "\n"
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"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B