BREAKING CHANGE: pass mod name instead of mod table in global callbacks
This commit is contained in:
parent
a688b66c62
commit
495dd3223a
32
DOCS.md
32
DOCS.md
@ -51,9 +51,9 @@ First of all download the mod and put it in your mods folder.
|
||||
|
||||
Now you need to register your minigame, possibly inside the `init.lua` of your mod, via:
|
||||
```lua
|
||||
arena_lib.register_minigame("yourmod", {parameter1, parameter2 etc})
|
||||
arena_lib.register_minigame("mod_name", {parameter1, parameter2 etc})
|
||||
```
|
||||
`"yourmod"` is how arena_lib will store your mod inside its storage, and it's also what it needs in order to understand you're referring to that specific minigame (that's why almost every `arena_lib` function contains `"mod"` as a parameter). You'll need it when calling for commands and callbacks. **Use the same name you used in mod.conf or some features won't be available**.
|
||||
`"mod_name"` is how arena_lib will store your mod inside its storage, and it's also what it needs in order to understand you're referring to that specific minigame (that's why almost every `arena_lib` function contains `"mod"` as a parameter). You'll need it when calling for commands and callbacks. **Use the same name you used in mod.conf or some features won't be available**.
|
||||
The second field, on the contrary, is a table of optional parameters: they define the very features of your minigame. They are:
|
||||
* `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
|
||||
@ -121,6 +121,8 @@ The second field, on the contrary, is a table of optional parameters: they defin
|
||||
* `player_properties`: ^
|
||||
* `spectator_properties`: ^
|
||||
* `team_properties`: ^ (it won't work if `teams` hasn't been declared)
|
||||
|
||||
To retrieve a minigame table, just do `arena_lib.mods[mod_name]`
|
||||
|
||||
### 1.1 Per server configuration
|
||||
There are also a couple of settings that can only be set in game via `/arenas settings <minigame>`. This because different servers might need different parameters. They are:
|
||||
@ -208,23 +210,23 @@ end)
|
||||
#### 1.4.2 Global callbacks
|
||||
Global callbacks act in the same way of minigame callbacks with the same name. Keep in mind that not every minigame callback has a global counterpart.
|
||||
`mod_ref` is the minigame table (so the one at the beginning of [Minigame configuration](#1-minigame-configuration)) and it can retrieved by doing `arena_lib.mods[<mod>]`
|
||||
* `arena_lib.register_on_enable(function(mod_ref, arena, p_name))`
|
||||
* `arena_lib.register_on_disable(function(mod_ref, arena, p_name))`
|
||||
* `arena_lib.register_on_prejoin_queue(function(mod_ref, arena, p_name))`
|
||||
* `arena_lib.register_on_join_queue(function(mod_ref, arena, p_name, has_queue_status_changed))`: `has_queue_status_changed` is a boolean, returning true when the arena goes from in queue -> not in queue, and viceversa
|
||||
* `arena_lib.register_on_leave_queue(function(mod_ref, arena, p_name, has_queue_status_changed))`: check the previous callback for `has_queue_status_changed`
|
||||
* `arena_lib.register_on_load(function(mod_ref, arena))`
|
||||
* `arena_lib.register_on_start(function(mod_ref, arena))`
|
||||
* `arena_lib.register_on_join(function(mod_ref, arena, p_name, as_spectator, was_spectator))`
|
||||
* `arena_lib.register_on_celebration(function(mod_ref, arena, winners))`
|
||||
* `arena_lib.register_on_end(function(mod_ref, arena, players, winners, spectators, is_forced))`
|
||||
* `arena_lib.register_on_eliminate(function(mod_ref, arena, p_name))`
|
||||
* `arena_lib.register_on_quit(function(mod_ref, arena, p_name, is_spectator, reason))`
|
||||
* `arena_lib.register_on_enable(function(mod, arena, p_name))`
|
||||
* `arena_lib.register_on_disable(function(mod, arena, p_name))`
|
||||
* `arena_lib.register_on_prejoin_queue(function(mod, arena, p_name))`
|
||||
* `arena_lib.register_on_join_queue(function(mod, arena, p_name, has_queue_status_changed))`: `has_queue_status_changed` is a boolean, returning true when the arena goes from in queue -> not in queue, and viceversa
|
||||
* `arena_lib.register_on_leave_queue(function(mod, arena, p_name, has_queue_status_changed))`: check the previous callback for `has_queue_status_changed`
|
||||
* `arena_lib.register_on_load(function(mod, arena))`
|
||||
* `arena_lib.register_on_start(function(mod, arena))`
|
||||
* `arena_lib.register_on_join(function(mod, arena, p_name, as_spectator, was_spectator))`
|
||||
* `arena_lib.register_on_celebration(function(mod, arena, winners))`
|
||||
* `arena_lib.register_on_end(function(mod, arena, players, winners, spectators, is_forced))`
|
||||
* `arena_lib.register_on_eliminate(function(mod, arena, p_name))`
|
||||
* `arena_lib.register_on_quit(function(mod, arena, p_name, is_spectator, reason))`
|
||||
|
||||
Let's say we want to stop people to enter minigames when there is an event on our server. We can simply do:
|
||||
|
||||
```lua
|
||||
arena_lib.register_on_prejoin_queue(function(mod_ref, arena, p_name)
|
||||
arena_lib.register_on_prejoin_queue(function(mod, arena, p_name)
|
||||
|
||||
if myservermod.is_event_active() then
|
||||
minetest.chat_send_player(p_name, "There is a special event in progress, minigames will be back once it ends!")
|
||||
|
@ -1308,7 +1308,7 @@ function arena_lib.enable_arena(sender, mod, arena_name, in_editor)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_enable) do
|
||||
if not callback(mod_ref, arena, sender) then return end
|
||||
if not callback(mod, arena, sender) then return end
|
||||
end
|
||||
|
||||
|
||||
@ -1360,7 +1360,7 @@ function arena_lib.disable_arena(sender, mod, arena_name)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_disable) do
|
||||
if not callback(mod_ref, arena, sender) then return end
|
||||
if not callback(mod, arena, sender) then return end
|
||||
end
|
||||
|
||||
-- se c'è gente rimasta è in coda: annullo la coda e li avviso della disabilitazione
|
||||
|
@ -90,7 +90,7 @@ function arena_lib.load_arena(mod, arena_ID)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_load) do
|
||||
callback(mod_ref, arena)
|
||||
callback(mod, arena)
|
||||
end
|
||||
|
||||
-- avvio la partita dopo tot secondi, se non è già stata avviata manualmente
|
||||
@ -135,7 +135,7 @@ function arena_lib.start_arena(mod, arena)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_start) do
|
||||
callback(mod_ref, arena)
|
||||
callback(mod, arena)
|
||||
end
|
||||
end
|
||||
|
||||
@ -176,7 +176,7 @@ function arena_lib.join_arena(mod, p_name, arena_ID, as_spectator)
|
||||
return end
|
||||
|
||||
-- controlli aggiuntivi e, se in coda, se può togliersi da questa
|
||||
if not prejoin_checks_passed(mod_ref, arena, p_name, as_spectator) then return end
|
||||
if not prejoin_checks_passed(mod, mod_ref, arena, p_name, as_spectator) then return end
|
||||
|
||||
players = {[1] = p_name}
|
||||
operations_before_entering_arena(mod_ref, mod, arena, arena_ID, p_name, true)
|
||||
@ -198,7 +198,7 @@ function arena_lib.join_arena(mod, p_name, arena_ID, as_spectator)
|
||||
return end
|
||||
|
||||
-- controlli aggiuntivi e, se in coda, se può togliersi da questa
|
||||
if not prejoin_checks_passed(mod_ref, arena, p_name, as_spectator) then return end
|
||||
if not prejoin_checks_passed(mod, mod_ref, arena, p_name, as_spectator) then return end
|
||||
|
||||
players = arena_lib.get_and_add_joining_players(mod_ref, arena, p_name)
|
||||
|
||||
@ -248,7 +248,7 @@ function arena_lib.join_arena(mod, p_name, arena_ID, as_spectator)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_join) do
|
||||
callback(mod_ref, arena, pl_name, as_spectator, was_spectator[i])
|
||||
callback(mod, arena, pl_name, as_spectator, was_spectator[i])
|
||||
end
|
||||
end
|
||||
|
||||
@ -326,7 +326,7 @@ function arena_lib.load_celebration(mod, arena, winners)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_celebration) do
|
||||
callback(mod_ref, arena, winners)
|
||||
callback(mod, arena, winners)
|
||||
end
|
||||
|
||||
-- l'arena finisce dopo tot secondi, a meno che non sia stata terminata forzatamente nel mentre
|
||||
@ -396,7 +396,7 @@ function arena_lib.end_arena(mod_ref, mod, arena, winners, is_forced)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_end) do
|
||||
callback(mod_ref, arena, players, winners, spectators, is_forced)
|
||||
callback(mod, arena, players, winners, spectators, is_forced)
|
||||
end
|
||||
|
||||
-- rimuovo eventuali proprietà temporanee
|
||||
@ -1040,14 +1040,14 @@ end
|
||||
|
||||
|
||||
|
||||
function prejoin_checks_passed(mod_ref, arena, p_name, as_spectator)
|
||||
function prejoin_checks_passed(mod, mod_ref, arena, p_name, as_spectator)
|
||||
-- controlli aggiuntivi
|
||||
if mod_ref.on_prejoin then
|
||||
if not mod_ref.on_prejoin(arena, p_name, as_spectator) then return end
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_prejoin) do
|
||||
if not callback(mod_ref, arena, p_name, as_spectator) then return end
|
||||
if not callback(mod, arena, p_name, as_spectator) then return end
|
||||
end
|
||||
|
||||
-- se si era in coda
|
||||
@ -1155,7 +1155,7 @@ function eliminate_player(mod, arena, p_name, executioner)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_eliminate) do
|
||||
callback(mod_ref, arena, p_name)
|
||||
callback(mod, arena, p_name)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1202,7 +1202,7 @@ function handle_leaving_callbacks(mod, arena, p_name, reason, executioner, is_sp
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_quit) do
|
||||
callback(mod_ref, arena, p_name, is_spectator, reason)
|
||||
callback(mod, arena, p_name, is_spectator, reason)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ function arena_lib.join_queue(mod, arena, p_name)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_prejoin_queue) do
|
||||
if not callback(mod_ref, arena, p_name) then return end
|
||||
if not callback(mod, arena, p_name) then return end
|
||||
end
|
||||
|
||||
local players_to_add = arena_lib.get_and_add_joining_players(mod_ref, arena, p_name)
|
||||
@ -141,7 +141,7 @@ function arena_lib.join_queue(mod, arena, p_name)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_join_queue) do
|
||||
callback(mod_ref, arena, p_name, has_queue_status_changed)
|
||||
callback(mod, arena, p_name, has_queue_status_changed)
|
||||
end
|
||||
|
||||
arena_lib.entrances[arena.entrance_type].update(mod, arena)
|
||||
@ -228,7 +228,7 @@ function arena_lib.remove_player_from_queue(p_name)
|
||||
end
|
||||
|
||||
for _, callback in ipairs(arena_lib.registered_on_leave_queue) do
|
||||
callback(mod_ref, arena, p_name, has_queue_status_changed)
|
||||
callback(mod, arena, p_name, has_queue_status_changed)
|
||||
end
|
||||
|
||||
arena_lib.entrances[arena.entrance_type].update(mod, arena)
|
||||
|
Loading…
x
Reference in New Issue
Block a user