Compare commits

...

7 Commits
master ... main

Author SHA1 Message Date
3ae96044a6 upstream merge sync: fix redundant checks for players, backguard compatibility
* sync commit "added 0.4.x support and fake player check function"
2023-07-24 05:54:49 -04:00
cd4833fae7 it was not a bug at lucky_block.lua
* this revert partially commit 41bd87405d02ce699c8e558459395116f1958c97
  becouse https://notabug.org/TenPlus1/stamina/issues/14
2023-07-24 05:41:16 -04:00
a39c32d1d0 sync code with MR and comment on performance issues
* do not check fake players in callbacks due performance impack
  but made proper player checks on each loop cos each loop
  retrieve players at live so a suddent disconected player may
  happened or craker player with invalid object that property
  check at `ck_player(obj)`
* added comments about this, this commit tries to sync the MR at
  https://notabug.org/TenPlus1/stamina/pulls/16
  until (as always) tenplus1 commit their own solution
2023-07-23 21:01:21 -04:00
26ae940ec9 fix confused code and redundant checks for fake players, backguard compatibility
* level its not property set on join player due inherit code
* real check player for fake players provided in ch_player function
* do not check fake players in callbacks due performance impack
* the level of the attribute its never set property, was backguard compatibilty part
* closes and fixed https://notabug.org/TenPlus1/stamina/issues/15
* this mod now works with older engines 0.4 and also newer 5.X
2023-07-23 20:17:25 -04:00
41bd87405d sync player nil checks; add settings for stamina speed, jump and drain
* add settings for stamina speed, jump and drain
* Merge branch 'master' of https://notabug.org/TenPlus1/stamina into main-sync
* Fix https://notabug.org/TenPlus1/stamina/issues/14 extra end at line 16
* property dont update hud/hunger if damage not enabled
* added more nil player checks due constant loop codes inside functions
* sync license and replace sip sound with licensed one
2023-07-23 18:37:50 -04:00
c328513513 Improve the readme for minenux 2022-01-21 10:06:44 -04:00
7912e7c95b 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
2022-01-21 09:39:43 -04:00
5 changed files with 169 additions and 27 deletions

98
README.md Normal file
View File

@ -0,0 +1,98 @@
Minetest mod "Stamina"
=====================
It adds a stamina, or "hunger" mechanic to Minetest
![](screenshot.png)
Information:
---------------
This mod adds a stamina, or "hunger" mechanic to Minetest. Actions like
crafting, walking, digging or fighting make the player exhausted. When
enough exhaustion has been accumulated, the player gets more hungry,
and loses stamina.
If a player is low on stamina, they start taking periodical damage,
and ultimately will die if they do not eat food.
Eating food no longer heals the player. Instead, it increases the
stamina of the player. The stamina bar shows how well fed the player
is. More bread pieces means more stamina.
Walking while holding down Aux1 (usually E key) will make player sprint so
long as their stamina bar is 3 or more bread. This will make the player run
that bit faster and jump a tiny bit higher.
### Q&A time: Why won't I move the stamina bar to the right?
Answer: this conflicts with the builtin breath bar. To move the
builtin breath bar, I basically have to entirely re-implement it
in lua including timers to catch breath changes for each online
player, which is all a waste of time, just to move a few pixels
around.
### Downloads
Original mod is at github on https://github.com/minetest-mods/stamina, this
version is a fork over the Tenplus1 version (Check the tech info below), you
can download at https://codeberg.org/minenux/minetest-mod-stamina .
This version just try to be sure works over minetst 0.4 and also 5.X, with
some checks focused on olders versions like 5.0, 5.2 and 0.4.17
Technical information:
---------------------
This mod intercepts minetest.item_eat(), and applies the hp_change
as stamina change. The value can be positive (increase stamina) or
negative (periodically damage the player by 1 hp).
### Depends
* default
* 3d_armor (optional)
* player_monoids/pova (both alternative it, both optionally)
### TenPlus1 Additions:
- Added support for POVA and player_monoids
- Added Pipeworks checks for fake players
- Added 60 second drunk effect when foods have {alcohol=1} group (eat 4 or more)
- Moved exhaustion and hud_id to player table instead of player attributes
The player phishics are set on Pova or Player_monoids but
not both at the same time, only the first detected is apply.
### Callbacks
Callbacks that are registered via minetest.register_on_item_eat()
are called after this mod, so the itemstack will have changed already
when callbacks are called. You can get the original itemstack as 6th
parameter of your function then.
A global function is available for mods to change player stamina levels:
stamina.change(player, change)
License:
--------
(C) 2015 - BlockMen
(C) 2016 - Auke Kok <sofar@foo-projects.org>
Code:
- all code LGPL-2.1+
Textures:
- stamina_hud_poison.png - BlockMen (CC-BY 3.0)
- stamina_hud_fg.png - PilzAdam (WTFPL), modified by BlockMen
- stamina_hud_bg.png - PilzAdam (WTFPL), modified by BlockMen
Sounds:
- stamina_eat.*.ogg - http://www.freesound.org/people/sonictechtonic/sounds/242215/ CC-BY-3.0
stamina_burp.ogg - https://www.freesfx.co.uk/sfx/burp (small burp)
stamina_sip.ogg - https://elements.envato.com/sip-16081-C7V5YLG

View File

@ -56,3 +56,18 @@ TenPlus1 Additions:
- Added 60 second drunk effect when foods have {alcohol=1} group (eat 4 or more)
- Moved exhaustion and hud_id to player table instead of player attributes
- Added 4 lucky block effects
License:
--------
Code:
- all code LGPL-2.1+
Textures:
- stamina_hud_poison.png - BlockMen (CC-BY 3.0)
- stamina_hud_fg.png - PilzAdam (WTFPL), modified by BlockMen
- stamina_hud_bg.png - PilzAdam (WTFPL), modified by BlockMen
Sounds:
- stamina_eat.*.ogg - http://www.freesound.org/people/sonictechtonic/sounds/242215/ CC-BY-3.0
stamina_burp.ogg - https://www.freesfx.co.uk/sfx/burp (small burp)
stamina_sip.ogg - https://elements.envato.com/sip-16081-C7V5YLG

View File

@ -36,16 +36,32 @@ SPRINT_JUMP = clamp(tonumber(minetest.settings:get("stamina_sprint_jump")) or 0
-- 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)
-- minetest 5.x check
local is_50 = minetest.has_feature("object_use_texture_alpha")
-- are we a real player ?
local function is_player(player)
-- pipeworks fake player check its not necesary with real player check:
if player then if minetest.is_player(player) then return true end end
end
local function get_int_attribute(player)
-- pipeworks fake player check
if not player or not player.get_attribute then
if not is_player(player) then
return nil
end
local level
if is_50 then
local meta = player:get_meta()
local level = meta and meta:get_string("stamina:level")
level = meta and meta:get_string("stamina:level")
else
level = player and player:get_attribute("stamina:level")
end
if level then
return tonumber(level)
@ -61,8 +77,7 @@ local damage_enabled = minetest.settings:get_bool("enable_damage")
local function stamina_update_level(player, level)
-- pipeworks fake player check
if not player.get_attribute or not stamina_enabled then
if not is_player(player) then
return nil
end
@ -77,9 +92,14 @@ local function stamina_update_level(player, level)
return
end
if is_50 then
local meta = player and player:get_meta() ; if not meta then return end
meta:set_string("stamina:level", level)
else
player:set_attribute("stamina:level", level)
end
player:hud_change(
stamina.players[player:get_player_name()].hud_id,
@ -112,10 +132,7 @@ end
local function exhaust_player(player, v)
if not player
or not player.is_player
or not player:is_player()
or not player.set_attribute then
if not is_player(player) then
return
end
@ -245,6 +262,8 @@ local function drunk_tick()
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
local name = player:get_player_name()
if name
@ -292,6 +311,8 @@ local function health_tick()
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
local name = player:get_player_name()
if name then
@ -302,7 +323,7 @@ local function health_tick()
-- damage player by 1 hp if saturation is < 2
if h and h < STAMINA_STARVE_LVL
and hp > 0 then
and hp > 1 then
player:set_hp(hp - STAMINA_STARVE, {hunger = true})
end
@ -326,7 +347,9 @@ local function action_tick()
for _,player in ipairs(minetest.get_connected_players()) do
local controls = player and player:get_player_control()
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()
-- Determine if the player is walking or jumping
if controls then
@ -345,7 +368,7 @@ local function action_tick()
--- START sprint
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)
if name
@ -410,7 +433,9 @@ local function poison_tick()
for _,player in ipairs(minetest.get_connected_players()) do
local name = player and player:get_player_name()
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()
if name
and stamina.players[name]
@ -448,7 +473,9 @@ local function stamina_tick()
for _,player in ipairs(minetest.get_connected_players()) do
local h = player and get_int_attribute(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)
if h and h > STAMINA_TICK_MIN then
stamina_update_level(player, h - 1)
@ -501,9 +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
core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
if user.is_fake_player then
return -- abort if called by fake player (eg. pipeworks-wielder)
end
if not is_player(user) then return end -- abort if called by fake player (eg. pipeworks-wielder)
local old_itemstack = itemstack
@ -629,12 +654,15 @@ if damage_enabled and minetest.settings:get_bool("enable_stamina") ~= false then
local level = STAMINA_VISUAL_MAX -- TODO
if get_int_attribute(player) then
level = math.min(get_int_attribute(player), STAMINA_VISUAL_MAX)
else
local meta = player:get_meta()
end
meta:set_string("stamina:level", level)
if is_50 then
local meta = player:get_meta()
if meta then meta:set_string("stamina:level", level) end
else
player:set_attribute("stamina:level", level)
end
local name = player:get_player_name()
@ -662,6 +690,7 @@ if damage_enabled and minetest.settings:get_bool("enable_stamina") ~= false then
minetest.register_on_respawnplayer(function(player)
if not player then return end
local name = player:get_player_name() ; if not name then return end
if stamina.players[name].poisoned

View File

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

View File

@ -4,10 +4,10 @@ sprint_particles (Enable sprint particles) bool true
enable_stamina (Enable stamina/hunger) bool true
stamina_tick (Time in seconds after which 1 saturation point is taken) float 800
stamina_tick (Time in seconds after which 1 saturation point is taken) float 1600
stamina_sprint_speed (Extra sprint speed - 0.0 to 1.0) float 0.3
stamina_sprint_jump (Extra sprint jump height - 0.0 to 1.0) float 0.1
stamina_sprint_drain (Sprint stamina drain - 0.0 to 1.0) float 0.35
stamina_sprint_drain (Sprint stamina drain - 0.0 to 1.0) float 0.2