hotfixes checks for player object on sudden disconnections
* is very know bug never resolved at https://github.com/minetest/minetest#8452 * In fact there's already some check for players around connected players but only for names * this fixed and close https://notabug.org/TenPlus1/stamina/issues/8 * this fixed and close https://codeberg.org/minenux/minetest-mod-stamina/issues/8 * already fix backguard compat for eye_height close https://codeberg.org/minenux/minetest-mod-stamina/issues/9 * already fix backguard compat for eye_height closes https://notabug.org/TenPlus1/stamina/issues/9
This commit is contained in:
parent
5fd2b2e5c9
commit
7912e7c95b
39
init.lua
39
init.lua
@ -143,6 +143,7 @@ local function set_sprinting(name, sprinting)
|
|||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
|
|
||||||
|
if player then
|
||||||
-- get player physics
|
-- get player physics
|
||||||
local def = player:get_physics_override()
|
local def = player:get_physics_override()
|
||||||
|
|
||||||
@ -203,12 +204,15 @@ local function set_sprinting(name, sprinting)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function head_particle(player, texture)
|
local function head_particle(player, texture)
|
||||||
|
|
||||||
|
if player then
|
||||||
local prop = player:get_properties()
|
local prop = player:get_properties()
|
||||||
local pos = player:get_pos() ; pos.y = pos.y + prop.eye_height -- mouth level
|
local eye_height = prop.eye_height or 1.23
|
||||||
|
local pos = player:get_pos() ; pos.y = pos.y + eye_height -- mouth level
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
|
|
||||||
|
|
||||||
@ -228,11 +232,14 @@ local function head_particle(player, texture)
|
|||||||
texture = texture
|
texture = texture
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function drunk_tick()
|
local function drunk_tick()
|
||||||
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
|
if player then
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if name
|
if name
|
||||||
@ -272,6 +279,9 @@ local function drunk_tick()
|
|||||||
player:set_look_horizontal(yaw)
|
player:set_look_horizontal(yaw)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -280,6 +290,8 @@ local function health_tick()
|
|||||||
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
|
if player then
|
||||||
|
|
||||||
local air = player:get_breath() or 0
|
local air = player:get_breath() or 0
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
local h = get_int_attribute(player)
|
local h = get_int_attribute(player)
|
||||||
@ -307,12 +319,15 @@ local function health_tick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function action_tick()
|
local function action_tick()
|
||||||
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
|
if player then
|
||||||
|
|
||||||
local controls = player and player:get_player_control()
|
local controls = player and player:get_player_control()
|
||||||
|
|
||||||
-- Determine if the player is walking or jumping
|
-- Determine if the player is walking or jumping
|
||||||
@ -391,13 +406,16 @@ local function action_tick()
|
|||||||
-- END sprint
|
-- END sprint
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function poison_tick()
|
local function poison_tick()
|
||||||
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
local name = player and player:get_player_name()
|
if player then
|
||||||
|
|
||||||
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if name
|
if name
|
||||||
and stamina.players[name]
|
and stamina.players[name]
|
||||||
@ -429,17 +447,23 @@ local function poison_tick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function stamina_tick()
|
local function stamina_tick()
|
||||||
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
|
if player then
|
||||||
|
|
||||||
local h = get_int_attribute(player)
|
local h = get_int_attribute(player)
|
||||||
|
|
||||||
if h and h > STAMINA_TICK_MIN then
|
if h and h > STAMINA_TICK_MIN then
|
||||||
stamina_update_level(player, h - 1)
|
stamina_update_level(player, h - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -614,6 +638,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
|
|||||||
|
|
||||||
local level = STAMINA_VISUAL_MAX -- TODO
|
local level = STAMINA_VISUAL_MAX -- TODO
|
||||||
|
|
||||||
|
if player then
|
||||||
if get_int_attribute(player) then
|
if get_int_attribute(player) then
|
||||||
|
|
||||||
level = math.min(get_int_attribute(player), STAMINA_VISUAL_MAX)
|
level = math.min(get_int_attribute(player), STAMINA_VISUAL_MAX)
|
||||||
@ -644,10 +669,12 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
|
|||||||
drunk = nil,
|
drunk = nil,
|
||||||
sprint = nil
|
sprint = nil
|
||||||
}
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
|
|
||||||
|
if player then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if stamina.players[name].poisoned
|
if stamina.players[name].poisoned
|
||||||
@ -661,6 +688,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
|
|||||||
stamina.players[name].sprint = nil
|
stamina.players[name].sprint = nil
|
||||||
|
|
||||||
stamina_update_level(player, STAMINA_VISUAL_MAX)
|
stamina_update_level(player, STAMINA_VISUAL_MAX)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(stamina_globaltimer)
|
minetest.register_globalstep(stamina_globaltimer)
|
||||||
@ -686,14 +714,18 @@ else
|
|||||||
|
|
||||||
-- create player table on join
|
-- create player table on join
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
if player then
|
||||||
stamina.players[player:get_player_name()] = {
|
stamina.players[player:get_player_name()] = {
|
||||||
poisoned = nil, sprint = nil, drunk = nil, exhaustion = 0}
|
poisoned = nil, sprint = nil, drunk = nil, exhaustion = 0}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- clear when player leaves
|
-- clear when player leaves
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
if player then
|
||||||
stamina.players[player:get_player_name()] = nil
|
stamina.players[player:get_player_name()] = nil
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
@ -705,6 +737,7 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
|
|||||||
local effect_me = function(pos, player, def)
|
local effect_me = function(pos, player, def)
|
||||||
|
|
||||||
local green = minetest.get_color_escape_sequence("#bada55")
|
local green = minetest.get_color_escape_sequence("#bada55")
|
||||||
|
if player then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if def.poison or def.drunk then
|
if def.poison or def.drunk then
|
||||||
@ -729,6 +762,8 @@ and minetest.settings:get_bool("enable_stamina") ~= false then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
lucky_block:add_blocks({
|
lucky_block:add_blocks({
|
||||||
{"cus", effect_me, {poison = 5} },
|
{"cus", effect_me, {poison = 5} },
|
||||||
{"cus", effect_me, {poison = 10} },
|
{"cus", effect_me, {poison = 10} },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user