2020-04-03 05:49:16 -07:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
2020-05-25 13:49:42 -07:00
|
|
|
|
2020-05-14 12:16:11 -07:00
|
|
|
arena_lib.HUD_add(player)
|
2020-04-03 05:49:16 -07:00
|
|
|
|
2021-01-23 09:59:02 -08:00
|
|
|
if arena_lib.STORE_INVENTORY_MODE ~= "none" then
|
|
|
|
arena_lib.restore_inventory(player:get_player_name())
|
|
|
|
end
|
|
|
|
|
2021-02-15 14:53:32 -08:00
|
|
|
local p_meta = player:get_meta()
|
2022-01-22 08:29:05 -08:00
|
|
|
local p_inv = player:get_inventory()
|
2021-02-15 14:53:32 -08:00
|
|
|
|
2020-05-29 14:22:47 -07:00
|
|
|
-- nel caso qualcuno si fosse disconnesso da dentro all'editor o fosse crashato il server con qualcuno nell'editor
|
2022-01-22 08:29:05 -08:00
|
|
|
if p_inv:contains_item("main", "arena_lib:editor_quit") then
|
2020-05-29 14:22:47 -07:00
|
|
|
|
|
|
|
p_meta:set_string("arena_lib_editor.mod", "")
|
|
|
|
p_meta:set_string("arena_lib_editor.arena", "")
|
2020-06-23 14:13:11 -07:00
|
|
|
p_meta:set_int("arena_lib_editor.players_number", 0)
|
2020-05-31 13:38:59 -07:00
|
|
|
p_meta:set_int("arena_lib_editor.spawner_ID", 0)
|
|
|
|
p_meta:set_int("arena_lib_editor.team_ID", 0)
|
2020-05-29 14:22:47 -07:00
|
|
|
|
|
|
|
if minetest.get_modpath("hub_manager") then return end -- se c'è hub_manager, ci pensa quest'ultimo allo svuotamento dell'inventario
|
|
|
|
|
2022-01-22 08:29:05 -08:00
|
|
|
p_inv:set_list("main", {})
|
|
|
|
p_inv:set_list("craft", {})
|
2021-02-15 14:53:32 -08:00
|
|
|
|
|
|
|
-- se invece era in spettatore
|
2022-01-22 08:29:05 -08:00
|
|
|
elseif p_inv:get_list("hand") and p_inv:contains_item("hand", "arena_lib:spectate_hand") then
|
|
|
|
p_inv:set_stack("hand", 1, nil)
|
|
|
|
p_inv:set_size("hand", 0)
|
2020-05-28 17:34:22 -07:00
|
|
|
end
|
|
|
|
|
2021-02-15 14:53:32 -08:00
|
|
|
p_meta:set_string("arenalib_infobox_mod", "")
|
|
|
|
p_meta:set_int("arenalib_infobox_arenaID", 0)
|
2020-04-03 05:49:16 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
2020-06-13 01:49:54 -07:00
|
|
|
|
2020-04-01 13:23:07 -07:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
|
|
|
|
local p_name = player:get_player_name()
|
2020-04-04 08:47:07 -07:00
|
|
|
|
2020-11-08 06:27:06 -08:00
|
|
|
if arena_lib.is_player_in_arena(p_name) then
|
2020-11-08 16:37:57 -08:00
|
|
|
arena_lib.remove_player_from_arena(p_name, 0)
|
2020-08-25 13:28:45 -07:00
|
|
|
elseif arena_lib.is_player_in_queue(p_name) then
|
2021-01-25 06:29:55 -08:00
|
|
|
arena_lib.remove_player_from_queue(p_name)
|
2020-11-08 06:27:06 -08:00
|
|
|
elseif arena_lib.is_player_in_edit_mode(p_name) then
|
2020-06-10 17:36:17 -07:00
|
|
|
arena_lib.quit_editor(player)
|
2020-11-23 05:10:13 -08:00
|
|
|
elseif arena_lib.is_player_in_settings(p_name) then
|
|
|
|
arena_lib.quit_minigame_settings(p_name)
|
2020-06-10 17:36:17 -07:00
|
|
|
end
|
2020-11-08 06:27:06 -08:00
|
|
|
|
|
|
|
arena_lib.HUD_remove(p_name)
|
2020-04-01 13:23:07 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-31 13:38:59 -07:00
|
|
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
2020-06-07 10:36:10 -07:00
|
|
|
|
2022-01-10 05:15:10 -08:00
|
|
|
local t_name = player:get_player_name()
|
2020-05-31 13:38:59 -07:00
|
|
|
local p_name = hitter:get_player_name()
|
2022-01-10 05:15:10 -08:00
|
|
|
local t_arena = arena_lib.get_arena_by_player(t_name)
|
|
|
|
local p_arena = arena_lib.get_arena_by_player(p_name)
|
2020-06-07 10:36:10 -07:00
|
|
|
|
2022-01-10 05:15:10 -08:00
|
|
|
-- se nessuno dei due è perlomeno in coda, lascio spazio agli altri eventuali on_punchplayer
|
|
|
|
if not p_arena and not t_arena then
|
|
|
|
return
|
2021-02-15 14:53:32 -08:00
|
|
|
end
|
|
|
|
|
2022-01-10 05:15:10 -08:00
|
|
|
-- se uno è in partita e l'altro no, annullo
|
|
|
|
if ((p_arena and p_arena.in_game) and not (t_arena and t_arena.in_game)) or
|
|
|
|
((t_arena and t_arena.in_game) and not (p_arena and p_arena.in_game)) then
|
2020-05-31 13:38:59 -07:00
|
|
|
return true
|
|
|
|
end
|
2020-06-07 10:36:10 -07:00
|
|
|
|
2022-01-10 05:15:10 -08:00
|
|
|
-- se sono nella stessa partita e nella stessa squadra, annullo
|
|
|
|
if p_arena.players[t_name] and p_arena.players[p_name].teamID and p_arena.players[p_name].teamID == p_arena.players[t_name].teamID then
|
|
|
|
return true
|
|
|
|
end
|
2020-05-31 13:38:59 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
|
|
|
|
2021-02-15 14:53:32 -08:00
|
|
|
local p_name = player:get_player_name()
|
|
|
|
local mod = arena_lib.get_mod_by_player(p_name)
|
2020-06-09 16:14:46 -07:00
|
|
|
|
|
|
|
-- se non è in partita, annullo
|
|
|
|
if not mod then return hp_change end
|
|
|
|
|
2021-02-15 14:53:32 -08:00
|
|
|
-- se è spettatore, annullo
|
|
|
|
if arena_lib.is_player_spectating(p_name) and reason.type ~= "respawn" then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2020-06-09 16:14:46 -07:00
|
|
|
-- se un tipo di danno è disabilitato, annullo
|
|
|
|
for _, disabled_damage in pairs(arena_lib.mods[mod].disabled_damage_types) do
|
|
|
|
if reason.type == disabled_damage then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-31 13:38:59 -07:00
|
|
|
return hp_change
|
|
|
|
|
|
|
|
end, true)
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-01 13:23:07 -07:00
|
|
|
minetest.register_on_dieplayer(function(player, reason)
|
|
|
|
|
|
|
|
local p_name = player:get_player_name()
|
|
|
|
if not arena_lib.is_player_in_arena(p_name) then return end
|
|
|
|
|
2020-04-16 06:51:20 -07:00
|
|
|
local mod_ref = arena_lib.mods[arena_lib.get_mod_by_player(p_name)]
|
2020-04-16 04:17:05 -07:00
|
|
|
local arena = arena_lib.get_arena_by_player(p_name)
|
2020-04-01 13:23:07 -07:00
|
|
|
local p_stats = arena.players[p_name]
|
|
|
|
p_stats.deaths = p_stats.deaths +1
|
|
|
|
|
2020-04-16 04:17:05 -07:00
|
|
|
if mod_ref.on_death then
|
2020-04-20 15:57:58 -07:00
|
|
|
mod_ref.on_death(arena, p_name, reason)
|
2020-04-16 04:17:05 -07:00
|
|
|
end
|
2020-04-08 10:01:35 -07:00
|
|
|
|
2020-04-01 13:23:07 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_respawnplayer(function(player)
|
|
|
|
|
2020-04-16 06:51:20 -07:00
|
|
|
local p_name = player:get_player_name()
|
|
|
|
|
|
|
|
if not arena_lib.is_player_in_arena(p_name) then return end
|
2020-04-16 04:17:05 -07:00
|
|
|
|
2020-04-16 06:51:20 -07:00
|
|
|
local arena = arena_lib.get_arena_by_player(p_name)
|
2020-04-01 13:23:07 -07:00
|
|
|
|
2021-02-16 07:54:18 -08:00
|
|
|
if not arena_lib.is_player_spectating(p_name) then
|
|
|
|
player:set_pos(arena_lib.get_random_spawner(arena, arena.players[p_name].teamID))
|
|
|
|
end
|
2020-04-02 03:47:55 -07:00
|
|
|
return true
|
2020-04-01 13:23:07 -07:00
|
|
|
end)
|