Add on_respawn callback (closes #157)

master
Zughy 2022-06-07 12:18:38 +02:00
parent 415793d06d
commit 9e87893362
3 changed files with 18 additions and 5 deletions

View File

@ -125,6 +125,7 @@ To customise your mod even more, there are a few empty callbacks you can use. Th
* `arena_lib.on_end(mod, function(arena, players, winners, spectators, is_forced))`: same as above. Players and spectators are given here because `end_arena` has already deleted them - hence these are a copy. `is_forced` returns `true` when the match has been forcibly terminated (via `force_arena_ending`)
* `arena_lib.on_join(mod, function(p_name, arena, as_spectator))`: called when a player joins an ongoing match. If `as_spectator` is true, they'll be added as such
* `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.
* `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

View File

@ -72,6 +72,12 @@ end
function arena_lib.on_respawn(mod, func)
arena_lib.mods[mod].on_respawn = func
end
function arena_lib.on_change_spectated_target(mod, func)
arena_lib.mods[mod].on_change_spectated_target = func
end

View File

@ -167,12 +167,18 @@ minetest.register_on_respawnplayer(function(player)
if not arena_lib.is_player_in_arena(p_name) then return end
local arena = arena_lib.get_arena_by_player(p_name)
if not arena_lib.is_player_spectating(p_name) then
player:set_pos(arena_lib.get_random_spawner(arena, arena.players[p_name].teamID))
else
if arena_lib.is_player_spectating(p_name) then
arena_lib.find_and_spectate_player(p_name)
else
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(p_name)]
local arena = arena_lib.get_arena_by_player(p_name)
player:set_pos(arena_lib.get_random_spawner(arena, arena.players[p_name].teamID))
if mod_ref.on_respawn then
mod_ref.on_respawn(arena, p_name)
end
end
return true