Compare commits

..

No commits in common. "3ae96044a63f3dc709b4d5bcd462542bb0eaa5c3" and "a39c32d1d00b41d120745708535ab0e23e00ae48" have entirely different histories.

2 changed files with 20 additions and 32 deletions

View File

@ -24,6 +24,7 @@ STAMINA_STARVE_LVL = 3 -- level of staturation that causes starving
STAMINA_VISUAL_MAX = 20 -- hud bar extends only to 20 STAMINA_VISUAL_MAX = 20 -- hud bar extends only to 20
local is_50 = minetest.has_feature("object_use_texture_alpha")
local function clamp(val, minval, maxval) local function clamp(val, minval, maxval)
return math.max(math.min(val, maxval), minval) return math.max(math.min(val, maxval), minval)
@ -36,50 +37,37 @@ SPRINT_JUMP = clamp(tonumber(minetest.settings:get("stamina_sprint_jump")) or 0
-- how fast to drain satation while sprinting (0-1) -- how fast to drain satation while sprinting (0-1)
SPRINT_DRAIN = clamp(tonumber(minetest.settings:get("stamina_sprint_drain")) or 0.35, 0.0, 1.0) SPRINT_DRAIN = clamp(tonumber(minetest.settings:get("stamina_sprint_drain")) or 0.35, 0.0, 1.0)
-- minetest 5.x check
local is_50 = minetest.has_feature("object_use_texture_alpha")
-- are we a real player ?
local function is_player(player)
local function ck_player(player)
-- pipeworks fake player check its not necesary with real player check: -- pipeworks fake player check its not necesary with real player check:
if player then if minetest.is_player(player) then return true end end if player then if minetest.is_player(player) then return true end end
return false
end end
local function get_int_attribute(player) local function get_int_attribute(player)
if not is_player(player) then if not ck_player(player) then return nil end
return nil
end
local level local level
if is_50 then if is_50 then
local meta = player:get_meta() local meta = player:get_meta()
level = meta and meta:get_string("stamina:level") level = meta and meta:get_string("stamina:level")
else else
level = player and player:get_attribute("stamina:level") level = player and player:get_attribute("stamina:level")
end end
if level then if level then return tonumber(level) end -- true its converted to number, even false
return tonumber(level)
end
return nil return nil
end end
local stamina_enabled = minetest.settings:get_bool("enable_stamina") ~= false local stamina_enabled = minetest.settings:get_bool("enable_stamina") ~= false
local damage_enabled = minetest.settings:get_bool("enable_damage") local damage_enabled = minetest.settings:get_bool("enable_damage")
local function stamina_update_level(player, level) local function stamina_update_level(player, level)
if not is_player(player) then if not ck_player(player) then return nil end
return nil
end
local old = get_int_attribute(player) local old = get_int_attribute(player)
@ -93,9 +81,7 @@ local function stamina_update_level(player, level)
end end
if is_50 then if is_50 then
local meta = player and player:get_meta() ; if not meta then return end local meta = player and player:get_meta() ; if not meta then return end
meta:set_string("stamina:level", level) meta:set_string("stamina:level", level)
else else
player:set_attribute("stamina:level", level) player:set_attribute("stamina:level", level)
@ -132,7 +118,9 @@ end
local function exhaust_player(player, v) local function exhaust_player(player, v)
if not is_player(player) then if not player
or not ck_player(player) -- player.is_player can return nill in rare cases, and real check of player here
or not player.set_attribute then
return return
end end
@ -234,7 +222,7 @@ end
local function head_particle(player, texture) local function head_particle(player, texture)
if not player then return end if not ck_player(player) then return end
local prop = player:get_properties() local prop = player:get_properties()
local pos = player:get_pos() ; pos.y = pos.y + (prop.eye_height or 1.23) -- mouth level local pos = player:get_pos() ; pos.y = pos.y + (prop.eye_height or 1.23) -- mouth level
@ -262,7 +250,7 @@ local function drunk_tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
if not is_player(player) then return end -- need cos some rare cases during game running object is not player if not ck_player(player) then return end -- need cos some rare cases during game running object is not player
local name = player:get_player_name() local name = player:get_player_name()
@ -311,7 +299,7 @@ local function health_tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
if not is_player(player) then return end -- need cos some rare cases during game running object is not player if not ck_player(player) then return end -- need cos some rare cases during game running object is not player
local name = player:get_player_name() local name = player:get_player_name()
@ -347,7 +335,7 @@ local function action_tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
if not is_player(player) then return end -- need cos some rare cases during game running object is not player if not ck_player(player) then return end -- need cos some rare cases during game running object is not player
local controls = player:get_player_control() local controls = player:get_player_control()
@ -368,7 +356,7 @@ local function action_tick()
--- START sprint --- START sprint
if enable_sprint then if enable_sprint then
local name = player:get_player_name() local name = player and player:get_player_name()
-- check if player can sprint (stamina must be over 6 points) -- check if player can sprint (stamina must be over 6 points)
if name if name
@ -433,7 +421,7 @@ local function poison_tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
if not is_player(player) then return end -- need cos some rare cases during game running object is not player if not ck_player(player) then return end -- need cos some rare cases during game running object is not player
local name = player:get_player_name() local name = player:get_player_name()
@ -473,7 +461,7 @@ local function stamina_tick()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
if not is_player(player) then return end -- need cos some rare cases during game running object is not player if not ck_player(player) then return end -- need cos some rare cases during game running object is not player
local h = get_int_attribute(player) local h = get_int_attribute(player)
@ -528,7 +516,7 @@ if damage_enabled and minetest.settings:get_bool("enable_stamina") ~= false then
-- override core.do_item_eat() so we can redirect hp_change to stamina -- override core.do_item_eat() so we can redirect hp_change to stamina
core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
if not is_player(user) then return end -- abort if called by fake player (eg. pipeworks-wielder) if not ck_player(user) then return end -- abort if called by fake player (eg. pipeworks-wielder)
local old_itemstack = itemstack local old_itemstack = itemstack
@ -653,12 +641,13 @@ if damage_enabled and minetest.settings:get_bool("enable_stamina") ~= false then
local level = STAMINA_VISUAL_MAX -- TODO local level = STAMINA_VISUAL_MAX -- TODO
-- the code here was redundant cos get_int_attribute already call the level
-- but with backguard compat, tenplus1 just inherint the code but with removed backguard compatibility
-- also here we do not check if name its valid, object its already valid
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)
end end
if is_50 then if is_50 then
local meta = player:get_meta() local meta = player:get_meta()
if meta then meta:set_string("stamina:level", level) end if meta then meta:set_string("stamina:level", level) end
else else

View File

@ -24,7 +24,6 @@ local effect_me = function(pos, player, def)
minetest.chat_send_player(name, green .. "You seem a little tipsy!") minetest.chat_send_player(name, green .. "You seem a little tipsy!")
end end
end
-- restore stamina function -- restore stamina function
local full_stamina = function(pos, player, def) local full_stamina = function(pos, player, def)