From 978c7ef6419ca17828d888a69df2b53af6419ca1 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Mon, 7 Dec 2020 11:30:35 -0800 Subject: [PATCH] Add CTF Respawn Delay (#712) * Add respawn delay * Fix weird edit of .luacheckrc --- mods/ctf/ctf_events/mod.conf | 2 +- mods/ctf/ctf_respawn_delay/README.md | 3 + mods/ctf/ctf_respawn_delay/init.lua | 85 ++++++++++++++++++++++++ mods/ctf/ctf_respawn_delay/mod.conf | 2 + mods/pvp/gauges/textures/health_nan.png | Bin 0 -> 118 bytes 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 mods/ctf/ctf_respawn_delay/README.md create mode 100644 mods/ctf/ctf_respawn_delay/init.lua create mode 100644 mods/ctf/ctf_respawn_delay/mod.conf create mode 100644 mods/pvp/gauges/textures/health_nan.png diff --git a/mods/ctf/ctf_events/mod.conf b/mods/ctf/ctf_events/mod.conf index 5ba95d1..69b2b1e 100644 --- a/mods/ctf/ctf_events/mod.conf +++ b/mods/ctf/ctf_events/mod.conf @@ -1,2 +1,2 @@ name = ctf_events -depends = ctf, ctf_match, hudkit +depends = ctf, ctf_match, ctf_map_core, hudkit diff --git a/mods/ctf/ctf_respawn_delay/README.md b/mods/ctf/ctf_respawn_delay/README.md new file mode 100644 index 0000000..48240af --- /dev/null +++ b/mods/ctf/ctf_respawn_delay/README.md @@ -0,0 +1,3 @@ +# CTF Respawn Delay + +Thanks to LMD for the hp_max=0 and registered_on_respawnplayers ideas diff --git a/mods/ctf/ctf_respawn_delay/init.lua b/mods/ctf/ctf_respawn_delay/init.lua new file mode 100644 index 0000000..1df6991 --- /dev/null +++ b/mods/ctf/ctf_respawn_delay/init.lua @@ -0,0 +1,85 @@ +ctf_respawn_delay = { + players = {}, +} +local respawnfunc +local RESPAWN_DELAY = 5 +local RESPAWN_INTERVAL = 1.1 +local RESPAWN_MESSAGE = "Respawning in " + +minetest.register_on_dieplayer(function(player, reason) + local pname = player:get_player_name() + if ctf_match.is_in_build_time() or (reason.type == "punch" and reason.object and + reason.object:is_player() and reason.object:get_player_name() == pname) then + return + end + + ctf_respawn_delay.players[pname] = { + old_max = player:get_properties().hp_max, + timeleft = "waiting", + hudid = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5, y=0.5}, + name = "respawn_delay", + scale = {x=100, y=100}, + text = RESPAWN_MESSAGE..RESPAWN_DELAY, + number = 0xD600AF, + alignment = {x = 0, y = -1}, + offset = {x = 0, y = 0}, + size = {x = 2}, + }) + } + player:set_properties({hp_max = 0}) +end) + +minetest.register_on_mods_loaded(function() + ctf_respawn_delay.registered_on_respawnplayers = minetest.registered_on_respawnplayers + minetest.registered_on_respawnplayers = {} + + table.insert(minetest.registered_on_respawnplayers, 1, function(player) + local pname = player:get_player_name() + + if ctf_respawn_delay.players[pname] and ctf_respawn_delay.players[pname].timeleft == "waiting" then + local pos = player:get_pos() + pos.y = 500 + + player:set_pos(pos) -- Player will be stuck there because CTF 'air' is walkable + ctf_respawn_delay.players[pname].timeleft = RESPAWN_DELAY + minetest.after(RESPAWN_INTERVAL, respawnfunc, pname) + + return true + end + + for k, func in ipairs(ctf_respawn_delay.registered_on_respawnplayers) do + func(player) + end + + return true + end) +end) + +function respawnfunc(pname) + local player = minetest.get_player_by_name(pname) + + if not player then + ctf_respawn_delay.players[pname] = nil + return + end + + ctf_respawn_delay.players[pname].timeleft = ctf_respawn_delay.players[pname].timeleft - 1 + local timeleft = ctf_respawn_delay.players[pname].timeleft + + if timeleft > 0 then + player:hud_change(ctf_respawn_delay.players[pname].hudid, "text", RESPAWN_MESSAGE..timeleft) + + minetest.after(RESPAWN_INTERVAL, respawnfunc, pname) + else + player:hud_remove(ctf_respawn_delay.players[pname].hudid) + player:set_properties({hp_max = ctf_respawn_delay.players[pname].old_max}) + player:set_hp(ctf_respawn_delay.players[pname].old_max) + ctf_respawn_delay.players[pname] = nil + + for k, func in ipairs(ctf_respawn_delay.registered_on_respawnplayers) do + func(player) + end + end +end diff --git a/mods/ctf/ctf_respawn_delay/mod.conf b/mods/ctf/ctf_respawn_delay/mod.conf new file mode 100644 index 0000000..b3998c6 --- /dev/null +++ b/mods/ctf/ctf_respawn_delay/mod.conf @@ -0,0 +1,2 @@ +name = ctf_respawn_delay +depends = ctf_match diff --git a/mods/pvp/gauges/textures/health_nan.png b/mods/pvp/gauges/textures/health_nan.png new file mode 100644 index 0000000000000000000000000000000000000000..869d9df854690b5ce272b942044044bb03d22ca3 GIT binary patch literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^3xJq|gBeJA#<9!+QjEnx?oJHr&dIz4a@YcVLR^9L zVTMD_PmH{PEICgX#}JF&