Compare commits
2 Commits
a39c32d1d0
...
3ae96044a6
Author | SHA1 | Date | |
---|---|---|---|
3ae96044a6 | |||
cd4833fae7 |
51
init.lua
51
init.lua
@ -24,7 +24,6 @@ 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)
|
||||||
@ -37,37 +36,50 @@ 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 ck_player(player) then return nil end
|
if not is_player(player) then
|
||||||
|
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 return tonumber(level) end -- true its converted to number, even false
|
if level then
|
||||||
|
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 ck_player(player) then return nil end
|
if not is_player(player) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
local old = get_int_attribute(player)
|
local old = get_int_attribute(player)
|
||||||
|
|
||||||
@ -81,7 +93,9 @@ 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)
|
||||||
@ -118,9 +132,7 @@ end
|
|||||||
|
|
||||||
local function exhaust_player(player, v)
|
local function exhaust_player(player, v)
|
||||||
|
|
||||||
if not player
|
if not is_player(player) then
|
||||||
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
|
||||||
|
|
||||||
@ -222,7 +234,7 @@ end
|
|||||||
|
|
||||||
local function head_particle(player, texture)
|
local function head_particle(player, texture)
|
||||||
|
|
||||||
if not ck_player(player) then return end
|
if not 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
|
||||||
@ -250,7 +262,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 ck_player(player) then return end -- need cos some rare cases during game running object is not player
|
if not is_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()
|
||||||
|
|
||||||
@ -299,7 +311,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 ck_player(player) then return end -- need cos some rare cases during game running object is not player
|
if not is_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()
|
||||||
|
|
||||||
@ -335,7 +347,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 ck_player(player) then return end -- need cos some rare cases during game running object is not player
|
if not is_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()
|
||||||
|
|
||||||
@ -356,7 +368,7 @@ local function action_tick()
|
|||||||
--- START sprint
|
--- START sprint
|
||||||
if enable_sprint then
|
if enable_sprint then
|
||||||
|
|
||||||
local name = player and player:get_player_name()
|
local name = 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
|
||||||
@ -421,7 +433,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 ck_player(player) then return end -- need cos some rare cases during game running object is not player
|
if not is_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()
|
||||||
|
|
||||||
@ -461,7 +473,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 ck_player(player) then return end -- need cos some rare cases during game running object is not player
|
if not is_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)
|
||||||
|
|
||||||
@ -516,7 +528,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 ck_player(user) then return end -- abort if called by fake player (eg. pipeworks-wielder)
|
if not is_player(user) then return end -- abort if called by fake player (eg. pipeworks-wielder)
|
||||||
|
|
||||||
local old_itemstack = itemstack
|
local old_itemstack = itemstack
|
||||||
|
|
||||||
@ -641,13 +653,12 @@ 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
|
||||||
|
@ -24,6 +24,7 @@ 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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user