Callbacks: added on_enable and on_disable to run custom checks when enabling/disabling an arena
This commit is contained in:
parent
f0bd65acc4
commit
40d44975a4
2
DOCS.md
2
DOCS.md
@ -195,6 +195,8 @@ Those aside, you need to connect a few functions with your mod in order to use t
|
||||
|
||||
### 2.3 Callbacks
|
||||
To customise your mod even more, there are a few empty callbacks you can use. They are:
|
||||
* `arena_lib.on_enable(mod, function(arena, p_name)`: use it to run more checks before enabling an arena. Must return true if all conditions are met
|
||||
* `arena_lib.on_disable(mod, function(arena, p_name)`: use it to run more checks before disabling an arena. Must return true if all conditions are met
|
||||
* `arena_lib.on_load(mod, function(arena)` (we saw these 4 earlier)
|
||||
* `arena_lib.on_start(mod, function(arena))`
|
||||
* `arena_lib.on_celebration(mod, function(arena, winner_name)`
|
||||
|
15
api.lua
15
api.lua
@ -750,13 +750,18 @@ function arena_lib.enable_arena(sender, mod, arena_name, in_editor)
|
||||
arena.enabled = false
|
||||
return end
|
||||
|
||||
local mod_ref = arena_lib.mods[mod]
|
||||
|
||||
-- eventuali controlli personalizzati
|
||||
if mod_ref.on_enable then
|
||||
if not mod_ref.on_enable(arena, sender) then return end
|
||||
end
|
||||
|
||||
-- se sono nell'editor, vengo buttato fuori
|
||||
if arena_lib.is_player_in_edit_mode(sender) then
|
||||
arena_lib.quit_editor(minetest.get_player_by_name(sender))
|
||||
end
|
||||
|
||||
local mod_ref = arena_lib.mods[mod]
|
||||
|
||||
-- abilito
|
||||
arena.enabled = true
|
||||
arena_lib.update_sign(arena)
|
||||
@ -784,6 +789,11 @@ function arena_lib.disable_arena(sender, mod, arena_name)
|
||||
minetest.chat_send_player(sender, minetest.colorize("#e6482e", S("[!] You can't disable an arena during an ongoing game!")))
|
||||
return end
|
||||
|
||||
-- eventuali controlli personalizzati
|
||||
if mod_ref.on_disable then
|
||||
if not mod_ref.on_disable(arena, sender) then return end
|
||||
end
|
||||
|
||||
-- se c'è gente rimasta è in coda: annullo la coda e li avviso della disabilitazione
|
||||
if next(arena.players) then
|
||||
for pl_name, stats in pairs(arena.players) do
|
||||
@ -1914,6 +1924,7 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
------------------DEPRECATED------------------
|
||||
----------------------------------------------
|
||||
|
@ -1,3 +1,17 @@
|
||||
-- Arena management
|
||||
|
||||
function arena_lib.on_enable(mod, func)
|
||||
arena_lib.mods[mod].on_enable = func
|
||||
end
|
||||
|
||||
|
||||
|
||||
function arena_lib.on_disable(mod, func)
|
||||
arena_lib.mods[mod].on_disable = func
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Arena phases
|
||||
|
||||
function arena_lib.on_load(mod, func)
|
||||
|
Loading…
x
Reference in New Issue
Block a user