Don't enable arenas having a region set with spawners outside the region (closes #219)

This commit is contained in:
Zughy 2023-03-31 00:34:40 +02:00
parent 601af6d1c4
commit 5a6dfdb95d
5 changed files with 30 additions and 5 deletions

View File

@ -453,7 +453,7 @@ Arenas and their settings are stored inside the mod storage. What is *not* store
Better said, these kind of parameters are emptied every time the server starts. And not when it ends, because handling situations like crashes is simply not possible. Better said, these kind of parameters are emptied every time the server starts. And not when it ends, because handling situations like crashes is simply not possible.
### 2.2 Setting up an arena ### 2.2 Setting up an arena
In order for an arena to be playable, four conditions must be satisfied: the arena has to exist, at least one spawner has to be set (it's per team if teams are enabled), an arena entrance must be put (to allow players to enter the minigame), and any potential custom check in the `arena_lib.on_enable` callback must go through. In order for an arena to be playable, four conditions must be satisfied: the arena has to exist, at least one spawner has to be set (it's per team if teams are enabled), an arena entrance must be put (to allow players to enter the minigame), and any potential custom check in the `arena_lib.on_enable` callback must go through. Additionally, arenas having a [region](#25-arena-region) set must also have all the declared spawners inside the region.
If you love yourself, there is a built-in editor that allows you to easily make these things and many many more. Or, if you don't love yourself, you can connect every setup function to your custom CLI. Either way, run `/arenas create <minigame> <arena>` to create your first arena. If you love yourself, there is a built-in editor that allows you to easily make these things and many many more. Or, if you don't love yourself, you can connect every setup function to your custom CLI. Either way, run `/arenas create <minigame> <arena>` to create your first arena.
@ -534,7 +534,9 @@ By default, spectate mode allows to follow players, but it also allows modders t
<br> <br>
### 2.5 Arena region ### 2.5 Arena region
An arena region is an optional cuboid wrapping the arena (there can be only one per arena), that can be used for several purposes. An example is to save and then restore the arena map once the match is over, or eliminate any player that goes outside of it. As for now, a region serves no purpose by default, so it's up to the single minigame to implement the logic behind it. However, with arena_lib 7.0, the map reset is going to be a built-in feature. An arena region is an optional cuboid wrapping the arena (there can be only one per arena), that can be used for several purposes. An example is to save and then restore the arena map once the match is over, or eliminate any player that goes outside it. As for now, a region serves no purpose by default, so it's up to the single minigame to implement the logic behind it. However, with arena_lib 7.0, the map reset is going to be a built-in feature.
When a region is declared, be sure that every existing spawn point is placed inside the region, or it won't be possible to enable the arena.
An util function that comes with it is `arena_lib.is_player_in_region(..)` An util function that comes with it is `arena_lib.is_player_in_region(..)`
## 3. About the author(s) ## 3. About the author(s)

View File

@ -109,6 +109,7 @@ Background music of arena @1 successfully overwritten=Musica di sottofondo dell'
Arena @1's timer is now @2 seconds=Il timer dell'arena @1 è ora @2 secondi Arena @1's timer is now @2 seconds=Il timer dell'arena @1 è ora @2 secondi
[!] Insufficient spawners, the arena can't be enabled!=[!] Punti di rinascita insufficienti, l'arena non può essere abilitata! [!] Insufficient spawners, the arena can't be enabled!=[!] Punti di rinascita insufficienti, l'arena non può essere abilitata!
[!] Entrance not set, the arena can't be enabled!=[!] Entrata non dichiarata, l'arena non può essere abilitata! [!] Entrance not set, the arena can't be enabled!=[!] Entrata non dichiarata, l'arena non può essere abilitata!
[!] If the arena region is declared, all the existing spawn points must be placed inside it!=[!] Se si dichiara la regione dell'arena, tutti i punti di rinascita presenti devono essere posizionati al suo interno!
Arena @1 successfully enabled=Arena @1 abilitata con successo Arena @1 successfully enabled=Arena @1 abilitata con successo
[!] The arena is already disabled=[!] L'arena è già disabilitata [!] The arena is already disabled=[!] L'arena è già disabilitata
[!] You can't disable an arena during an ongoing game!=[!] Non puoi disabilitare un'arena mentre una partita è in corso! [!] You can't disable an arena during an ongoing game!=[!] Non puoi disabilitare un'arena mentre una partita è in corso!

View File

@ -109,6 +109,7 @@ Background music of arena @1 successfully overwritten=
Arena @1's timer is now @2 seconds= Arena @1's timer is now @2 seconds=
[!] Insufficient spawners, the arena can't be enabled!= [!] Insufficient spawners, the arena can't be enabled!=
[!] Entrance not set, the arena can't be enabled!= [!] Entrance not set, the arena can't be enabled!=
[!] If the arena region is declared, all the existing spawn points must be placed inside it!=
Arena @1 successfully enabled= Arena @1 successfully enabled=
[!] The arena is already disabled!= [!] The arena is already disabled!=
[!] You can't disable an arena during an ongoing game!= [!] You can't disable an arena during an ongoing game!=

View File

@ -955,7 +955,6 @@ function arena_lib.set_entrance(sender, mod, arena_name, action, ...)
local entrance = arena_lib.entrances[arena.entrance_type] local entrance = arena_lib.entrances[arena.entrance_type]
if action == "add" then if action == "add" then
if arena.entrance then if arena.entrance then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There is already an entrance for this arena!"))) minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There is already an entrance for this arena!")))
return end return end
@ -968,7 +967,6 @@ function arena_lib.set_entrance(sender, mod, arena_name, action, ...)
minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Entrance of arena @1 successfully set", arena_name)) minetest.chat_send_player(sender, arena_lib.mods[mod].prefix .. S("Entrance of arena @1 successfully set", arena_name))
elseif action == "remove" then elseif action == "remove" then
if not arena.entrance then if not arena.entrance then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There is no entrance to remove assigned to @1!", arena_name))) minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] There is no entrance to remove assigned to @1!", arena_name)))
return end return end
@ -1026,6 +1024,7 @@ function arena_lib.set_region(sender, mod, arena_name, pos1, pos2, in_editor)
arena.pos2 = nil arena.pos2 = nil
else else
-- controllo che i parametri siano corretti
if not pos1 or not pos2 or not vector.check(pos1) or not vector.check(pos2) then if not pos1 or not pos2 or not vector.check(pos1) or not vector.check(pos2) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!"))) minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] Parameters don't seem right!")))
return end return end
@ -1189,6 +1188,28 @@ function arena_lib.enable_arena(sender, mod, arena_name, in_editor)
arena.enabled = false arena.enabled = false
return end return end
-- se c'è una regione ma qualche punto rinascita sta al di fuori
if arena.pos1 then
local v1, v2 = vector.sort(arena.pos1, arena.pos2)
local region = VoxelArea:new({MinEdge=v1, MaxEdge=v2})
if not arena.teams_enabled then
for _, spawner in pairs(arena.spawn_points) do
if not region:containsp(spawner) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] If the arena region is declared, all the existing spawn points must be placed inside it!")))
return end
end
else
for _, team_table in pairs(arena.spawn_points) do
for _, spawner in pairs(team_table) do
if not region:containsp(spawner) then
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] If the arena region is declared, all the existing spawn points must be placed inside it!")))
return end
end
end
end
end
local mod_ref = arena_lib.mods[mod] local mod_ref = arena_lib.mods[mod]
-- eventuali controlli personalizzati -- eventuali controlli personalizzati

View File

@ -1,2 +1,2 @@
-- se devo aspettare Minetest -- se devo aspettare Minetest
arena_lib.temp = {} arena_lib.temp = {}