From 9e878933624510cd00f2d0143e70cee96c815f13 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Tue, 7 Jun 2022 12:18:38 +0200 Subject: [PATCH] Add on_respawn callback (closes #157) --- DOCS.md | 1 + src/callbacks.lua | 6 ++++++ src/player_manager.lua | 16 +++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/DOCS.md b/DOCS.md index 668d55a..4dbd325 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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 diff --git a/src/callbacks.lua b/src/callbacks.lua index 85cadfe..2d968e8 100755 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -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 diff --git a/src/player_manager.lua b/src/player_manager.lua index 203cb81..d277aca 100755 --- a/src/player_manager.lua +++ b/src/player_manager.lua @@ -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