Fix various ctf_respawn_delay bugs (#889)
This commit is contained in:
parent
e2f2ba9fae
commit
038dd3c1e5
2 changed files with 43 additions and 29 deletions
|
@ -91,11 +91,14 @@ end
|
||||||
local function set_max_hp(player, max_hp)
|
local function set_max_hp(player, max_hp)
|
||||||
local cur_hp = player:get_hp()
|
local cur_hp = player:get_hp()
|
||||||
local old_max = player:get_properties().hp_max
|
local old_max = player:get_properties().hp_max
|
||||||
local new_hp = cur_hp + max_hp - old_max
|
|
||||||
player:set_properties({
|
|
||||||
hp_max = max_hp
|
|
||||||
})
|
|
||||||
|
|
||||||
|
if old_max == 0 then
|
||||||
|
minetest.log("error", "[ctf_classes] Reviving dead player " .. player:get_player_name())
|
||||||
|
end
|
||||||
|
|
||||||
|
player:set_properties({hp_max = max_hp})
|
||||||
|
|
||||||
|
local new_hp = cur_hp + max_hp - old_max
|
||||||
if new_hp > max_hp then
|
if new_hp > max_hp then
|
||||||
minetest.log("error", string.format("New hp %d is larger than new max %d, old max is %d", new_hp, max_hp, old_max))
|
minetest.log("error", string.format("New hp %d is larger than new max %d, old max is %d", new_hp, max_hp, old_max))
|
||||||
new_hp = max_hp
|
new_hp = max_hp
|
||||||
|
|
|
@ -37,13 +37,18 @@ minetest.register_on_mods_loaded(function()
|
||||||
table.insert(minetest.registered_on_respawnplayers, 1, function(player)
|
table.insert(minetest.registered_on_respawnplayers, 1, function(player)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
if ctf_respawn_delay.players[pname] and ctf_respawn_delay.players[pname].timeleft == "waiting" then
|
if ctf_respawn_delay.players[pname] then
|
||||||
|
-- Since the player is still dead the client can send respawn actions
|
||||||
|
-- https://github.com/minetest/minetest/blob/4152227f17315a9cf9038266d9f9bb06e21e3424/src/network/serverpackethandler.cpp#L895
|
||||||
|
-- We should ignore those
|
||||||
|
if ctf_respawn_delay.players[pname].timeleft == "waiting" then
|
||||||
ctf_respawn_delay.players[pname].timeleft = RESPAWN_DELAY
|
ctf_respawn_delay.players[pname].timeleft = RESPAWN_DELAY
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
pos.y = ctf_map.map.h/2 + 10
|
pos.y = ctf_map.map.h/2 + 10
|
||||||
|
|
||||||
player:set_pos(pos) -- Player will be stuck there because CTF 'air' is walkable
|
player:set_pos(pos) -- Player will be stuck there because CTF 'air' is walkable
|
||||||
minetest.after(RESPAWN_INTERVAL, respawnfunc, pname)
|
minetest.after(RESPAWN_INTERVAL, respawnfunc, pname)
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -56,15 +61,10 @@ minetest.register_on_mods_loaded(function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function ctf_respawn_delay.respawnplayer(name)
|
function respawnplayer(player, pname)
|
||||||
local player = minetest.get_player_by_name(name)
|
player:hud_remove(ctf_respawn_delay.players[pname].hudid)
|
||||||
|
player:set_properties({hp_max = ctf_respawn_delay.players[pname].old_max})
|
||||||
if not player then return end
|
player:set_hp(ctf_respawn_delay.players[pname].old_max)
|
||||||
|
|
||||||
player:hud_remove(ctf_respawn_delay.players[name].hudid)
|
|
||||||
player:set_properties({hp_max = ctf_respawn_delay.players[name].old_max})
|
|
||||||
player:set_hp(ctf_respawn_delay.players[name].old_max)
|
|
||||||
ctf_respawn_delay.players[name] = nil
|
|
||||||
|
|
||||||
for k, func in ipairs(ctf_respawn_delay.registered_on_respawnplayers) do
|
for k, func in ipairs(ctf_respawn_delay.registered_on_respawnplayers) do
|
||||||
func(player)
|
func(player)
|
||||||
|
@ -72,16 +72,13 @@ function ctf_respawn_delay.respawnplayer(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function respawnfunc(pname)
|
function respawnfunc(pname)
|
||||||
local player = minetest.get_player_by_name(pname)
|
if not ctf_respawn_delay.players[pname] then
|
||||||
|
|
||||||
if not player or not ctf_respawn_delay.players[pname] then
|
|
||||||
ctf_respawn_delay.players[pname] = nil
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(ctf_respawn_delay.players[pname].timeleft) == "string" then
|
local player = minetest.get_player_by_name(pname)
|
||||||
minetest.after(RESPAWN_INTERVAL, respawnfunc, pname)
|
if not player then
|
||||||
|
ctf_respawn_delay.players[pname] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,12 +90,26 @@ function respawnfunc(pname)
|
||||||
|
|
||||||
minetest.after(RESPAWN_INTERVAL, respawnfunc, pname)
|
minetest.after(RESPAWN_INTERVAL, respawnfunc, pname)
|
||||||
else
|
else
|
||||||
ctf_respawn_delay.respawnplayer(pname)
|
respawnplayer(player, pname)
|
||||||
|
ctf_respawn_delay.players[pname] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf_match.register_on_new_match(function()
|
ctf_match.register_on_new_match(function()
|
||||||
for name in pairs(ctf_respawn_delay.players) do
|
for pname in pairs(ctf_respawn_delay.players) do
|
||||||
ctf_respawn_delay.respawnplayer(name)
|
local player = minetest.get_player_by_name(pname)
|
||||||
|
if player then
|
||||||
|
respawnplayer(player, pname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf_respawn_delay.players = {}
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
if ctf_respawn_delay.players[pname] then
|
||||||
|
player:set_properties({hp_max = ctf_respawn_delay.players[pname].old_max})
|
||||||
|
ctf_respawn_delay.players[pname] = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue