[Mod] Hunger with HUD bar [0.7.1] [hbhunger]

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

[Mod] Hunger with HUD bar [0.7.1] [hbhunger]

by Wuzzy » Fri Feb 27, 2015 06:47

This mod adds a simple hunger mechanic (plus HUD bar) to the game.
Eat food to avoid starvation, be sated to regenerate health.

Screenshot of the HUD bar:
Image

The mod introduces satiation and food poisoning and changes how healing and eating works.

Satiation and healing: Each player has a new attribute called “satiation”. This attribute is represented by a brown HUD bar. Quick overview:
  • Satiation is a whole number between 0 and 30
  • New players start with a satiation of 20
  • Health increases at a satiation of 16 or higher
  • Health decreases at a satiation of 1 or lower
  • Mining, building and movement will slowly decrease satiation
  • Players lose 1 satiation point every 800 seconds no matter what
Eating: Players have to eat food such as apples to restore satiation. Food will no longer directly restore one's health!
In other words, the hunger mechanic works exactly like in the “Better HUD” mod from BlockMen. Note that in BlockMen's mod, satiation can go up to 30, too. But satiation levels 20-30 are always displayed as 10 bread symbols. This mod, however, always shows the actual satiation.
Food poisoning: Very simple. When you eat poisoned food like a red mushroom, you lose health points for a few seconds (but your health can never go below 1 with food poisoning).



This mod is a fork of the “Better HUD” [hud] mod by BlockMen version 1.4.0, but made to work to use the HUD bars mod instead, and all features not needed for the hunger mechanic stripped off.
It has been updated to support the same foods as of version 2.x.1 of said mod.

This mod needs testing! If you experience any bugs or crashes or just error messages, please report them here.

Download: http://repo.or.cz/minetest_hbhunger.git ... 44c421.zip


Supported food:
All food items which use the standard minetest.item_eat function are automatically supported.

+ Known supported food and optional dependencies




This mod is incompatible with:
Attachments
hbhunger_screenshot.png
(8.48 KiB) Not downloaded yet
Last edited by Wuzzy on Fri Jun 01, 2018 10:04, edited 38 times in total.
 

User avatar
rubenwardy
Moderator
 
Posts: 5544
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by rubenwardy » Fri Feb 27, 2015 08:45

Why "saturation"?

Also the namespace should be "hphunger" no "hunger" in your mod (ie: the global table)
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by Wuzzy » Fri Feb 27, 2015 09:51

rubenwardy wrote:Why "saturation"?

What's wrong with that word? Anyways, I am not a native English speaker, so please forgive me if it's wrong.
Also, the word comes from the “Better HUD” mod, where the readme tells something about “saturation points”.

I need a word for “how ‘full’ you are”, as in “negation of hunger”. A full bar means the player character is “full”, an empty bar means the player character is starving.

From looking into a dictionary, I narrowed possible words down to these:

  • saturation
  • satiety
  • satiation
  • repletion

Could some native English speaker tell me which word I should use?

Also the namespace should be "hphunger" no "hunger" in your mod (ie: the global table)

Probably I just make the main table local, there is no API, so there is actually no good reason to put anything into global space.
 

User avatar
TenPlus1
Member
 
Posts: 2419
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by TenPlus1 » Fri Feb 27, 2015 10:02

Nice mod but the hunger.lua code you are using from BetterHUD mod is out of date and has had many bug fixes and improvements since the version you are using... Could you update...
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by Wuzzy » Fri Feb 27, 2015 10:21

@TenPlus1:

diff of hunger.lua, hud vs hbhunger wrote:2,3c2,3
< function hbhunger.save_hunger(player)
< hbhunger.set_hunger(player)
---
> function hud.save_hunger(player)
> hud.set_hunger(player)
5,6c5,6
< function hbhunger.load_hunger(player)
< hbhunger.get_hunger(player)
---
> function hud.load_hunger(player)
> hud.get_hunger(player)
23c23
< function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
---
> function hud.item_eat(hunger_change, replace_with_item, poisen, heal)
27c27
< local h = tonumber(hbhunger.hunger[name])
---
> local h = tonumber(hud.hunger[name])
34,35c34,35
< hbhunger.hunger[name] = h
< hbhunger.set_hunger(user)
---
> hud.hunger[name] = h
> hud.set_hunger(user)
59c59
< tab.on_use = hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
---
> tab.on_use = hud.item_eat(hunger_change, replace_with_item, poisen, heal)
63,65c63
< if minetest.get_modpath("default") ~= nil then
< overwrite("default:apple", 2)
< end
---
> overwrite("default:apple", 2)
366c364
< function hbhunger.handle_node_actions(pos, oldnode, player, ext)
---
> function hud.handle_node_actions(pos, oldnode, player, ext)
371,372c369,370
< local exhaus = hbhunger.exhaustion[name]
< local new = HUNGER_EXHAUST_PLACE
---
> local exhaus = hud.exhaustion[name]
> local new = HUD_HUNGER_EXHAUST_PLACE
375c373
< new = HUNGER_EXHAUST_DIG
---
> new = HUD_HUNGER_EXHAUST_DIG
379c377
< new = HUNGER_EXHAUST_MOVE
---
> new = HUD_HUNGER_EXHAUST_MOVE
382c380
< if exhaus > HUNGER_EXHAUST_LVL then
---
> if exhaus > HUD_HUNGER_EXHAUST_LVL then
384c382
< local h = tonumber(hbhunger.hunger[name])
---
> local h = tonumber(hud.hunger[name])
387,388c385,386
< hbhunger.hunger[name] = h
< hbhunger.set_hunger(player)
---
> hud.hunger[name] = h
> hud.set_hunger(player)
390c388
< hbhunger.exhaustion[name] = exhaus
---
> hud.exhaustion[name] = exhaus
393,394c391,392
< minetest.register_on_placenode(hbhunger.handle_node_actions)
< minetest.register_on_dignode(hbhunger.handle_node_actions)
---
> minetest.register_on_placenode(hud.handle_node_actions)
> minetest.register_on_dignode(hud.handle_node_actions)


I don't know what you're talking about.
 

User avatar
rubenwardy
Moderator
 
Posts: 5544
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by rubenwardy » Fri Feb 27, 2015 10:44

Hunger is used quite a lot in video games inversely, lower bars is more hungry. But meh.

It is an API, my food mod supports you using hunger.item_eat(). I don't want to make a pull request everytime I add a food.

You should use minetest.register_on_item_eat, anyway. It is what it is meant for.
 

User avatar
TenPlus1
Member
 
Posts: 2419
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by TenPlus1 » Fri Feb 27, 2015 11:05

The following is the latest functions which stop players over-eating when saturation or health is full and returns bowls/buckets from a food stack without replacing the whole stack:

Code: Select all
-- Keep these for backwards compatibility
function hud.save_hunger(player)
   hud.set_hunger(player)
end
function hud.load_hunger(player)
   hud.get_hunger(player)
end

-- Poison player
local function poisenp(tick, time, time_left, player)
   time_left = time_left + tick
   if time_left < time then
      minetest.after(tick, poisenp, tick, time, time_left, player)
   end
   if player:get_hp()-1 > 0 then
      player:set_hp(player:get_hp()-1)
   end
   
end

function hud.item_eat(hunger_change, replace_with_item, poisen, heal)
   return function(itemstack, user, pointed_thing)
   
      if itemstack:take_item() ~= nil and user ~= nil then
      
         local name = user:get_player_name()
         local h = tonumber(hud.hunger[name])
         local hp = user:get_hp()
         local rm = false
         local msg = nil

         -- Healing
         if hp < 20 and heal then
            hp = hp + heal
            if hp > 20 then hp = 20 end
            user:set_hp(hp)
            rm = true
            msg = ""
         elseif hp == 20 and heal then
            msg = "You already have full health"
         end

         -- Hunger
         if h < 30 and hunger_change then
            h = h + hunger_change
            if h > 30 then h = 30 end
            hud.hunger[name]=h
            hud.set_hunger(user)
            rm = true
         elseif h>= 30 and hunger_change and not msg then
            msg = "Cannot eat, not hungry"
         end
         
         if msg then minetest.chat_send_player(user:get_player_name(), msg) end
         
         -- Poison
         if poisen then
            poisenp(1.0, poisen, 0, user)
         end

--         minetest.sound_play("chomp", {pos=pos, gain = 1.0, max_hear_distance = 2,})

         -- if item eaten and replace_with_item, check if inventory full, add/drop replacement
         if rm then
            local inv = user:get_inventory()
            if inv:room_for_item("main", {name=replace_with_item}) then
               inv:add_item("main", replace_with_item)
            else
               local pos = user:getpos()
               pos.y = math.floor(pos.y + 0.5)
               core.add_item(pos, replace_with_item)
            end

            return itemstack
         end
         
      end
   end
end

local function overwrite(name, hunger_change, replace_with_item, poisen, heal)
   local tab = minetest.registered_items[name]
   if tab == nil then return end
   tab.on_use = hud.item_eat(hunger_change, replace_with_item, poisen, heal)
   minetest.registered_items[name] = tab
end
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by Wuzzy » Fri Feb 27, 2015 11:18

@rubenwardy: Whoops, indeed there is that function. I have renamed the table to hbhunger then.

Yeah, this is still a fresh fork from 1.4.0 from Better HUD (now updated to 1.4.1), so I don't know my “own” mod very well. :D

Basically I wanted to completely bissect the Better HUD mod, I guess I have achieved this goal for now. So I have not made much work on the actual gameplay mechanics or architecture. It seems this must be reworked.

As for minetest.register_on_item_eat: Good idea, but is it a good idea to transform the value which was intended for health initially into a “saturation” value? Would I get sane results; wouldn't some manual balancing/tweaking be needed at least?

@TenPlus1: Now this code is indeed different from my code. Where did you get that code? For me, the most recent version of Better HUD [hud] is 1.4.1, and according to GitHub, there have been 0 updates since then on the master branch. https://github.com/BlockMen/hud
Please give me the URL of the repository from which you got that code, so I can merge.

stop players over-eating when saturation or health is full

When I think about it, maybe I don't want to merge this. This sucks. When I have full health, there is still reason to eat to fill up the saturation bar.
 

SpaghettiToastBook
Member
 
Posts: 15
Joined: Sun Feb 22, 2015 21:11

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

by SpaghettiToastBook » Tue Mar 03, 2015 02:08

Wuzzy wrote:
rubenwardy wrote:Why "saturation"?

What's wrong with that word? Anyways, I am not a native English speaker, so please forgive me if it's wrong.
Also, the word comes from the “Better HUD” mod, where the readme tells something about “saturation points”.

I need a word for “how ‘full’ you are”, as in “negation of hunger”. A full bar means the player character is “full”, an empty bar means the player character is starving.

From looking into a dictionary, I narrowed possible words down to these:

  • saturation
  • satiety
  • satiation
  • repletion

Could some native English speaker tell me which word I should use?

I think the word you should use is definitely "satiation". The other three don't have quite the right meaning.
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Release: 0.2.0

by Wuzzy » Tue Mar 03, 2015 02:33

OK, here's release 0.2.0.

Changelog:
  • Change “saturation” to “satiation” throughout the mod
  • Rename global table to “hbhunger” to avoid possible naming collisions
  • General cleanup
 

User avatar
mahmutelmas06
Member
 
Posts: 367
Joined: Mon Mar 02, 2015 13:10
GitHub: mahmutelmas06
IRC: mahmutelmas06
In-game: masum

Re: [Mod] Hunger with HUD bar [0.2.0] [hbhunger]

by mahmutelmas06 » Wed Mar 04, 2015 19:35

How about to trigger eating sound when punched with food ?
My Mods:

Beverage
 

SpaghettiToastBook
Member
 
Posts: 15
Joined: Sun Feb 22, 2015 21:11
 

User avatar
rubenwardy
Moderator
 
Posts: 5544
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Hunger with HUD bar [0.2.0] [hbhunger]

by rubenwardy » Sun Mar 08, 2015 08:27

Food sweet should automatically support it if you have the latest version of food.

Edit: actually, I did a typo so it doesn't. I'll fix that.
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Release 0.3.0

by Wuzzy » Sun Mar 08, 2015 09:12

mahmutelmas06 wrote:How about to trigger eating sound when punched with food ?

Done in version 0.3.0, which I have just released.

It's a simple sound but I think it gets the job done.
 

User avatar
mahmutelmas06
Member
 
Posts: 367
Joined: Mon Mar 02, 2015 13:10
GitHub: mahmutelmas06
IRC: mahmutelmas06
In-game: masum
 

User avatar
mahmutelmas06
Member
 
Posts: 367
Joined: Mon Mar 02, 2015 13:10
GitHub: mahmutelmas06
IRC: mahmutelmas06
In-game: masum

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

by mahmutelmas06 » Mon Mar 09, 2015 11:58

I have edited some to get sound only if you are hungry.

Delete
Code: Select all
         minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})




Replace

Code: Select all
         --sound:eat
            if h < 30 and hunger_change then
         minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})
         itemstack:add_item(replace_with_item)
         end   
My Mods:

Beverage
 

H4Mm3r
Member
 
Posts: 10
Joined: Fri Apr 03, 2015 08:43
In-game: H4Mm3r

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

by H4Mm3r » Mon Apr 06, 2015 16:56

Hello,

Really love this mod, thanks !

Just have a little problem, nothing is happening when eating ethereal food, is it a known issue ?

2015-04-06 18:54:23: ACTION[ServerThread]: H4Mm3r uses farming:rhubarb, pointing at [node under=-163,2,-336 above=-163,3,-336]
=> Satiation UP
2015-04-06 18:55:00: ACTION[ServerThread]: H4Mm3r uses ethereal:orange, pointing at [nothing]
=> Nothing

H4Mm3r
 

User avatar
TenPlus1
Member
 
Posts: 2419
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

by TenPlus1 » Mon Apr 06, 2015 17:56

It seems that their is a missing line in hunger.lua for ethereal orange:

overwrite("ethereal:orange", 4)
 

H4Mm3r
Member
 
Posts: 10
Joined: Fri Apr 03, 2015 08:43
In-game: H4Mm3r

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

by H4Mm3r » Mon Apr 06, 2015 18:05

TenPlus1 wrote:It seems that their is a missing line in hunger.lua for ethereal orange:

overwrite("ethereal:orange", 4)


Oh yes ! Added this line (but with "2" hunger change, like other mod's oranges). Will apply it if some other fruits are missing.

Thanks a lot !!!

H4Mm3r
 

User avatar
Minetestforfun
Member
 
Posts: 936
Joined: Tue Aug 05, 2014 14:09
Location: On earth
GitHub: Darcidride
IRC: Darcidride + MinetestForFun
In-game: Darcidride + MinetestForFun
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Bugfix updates

by Wuzzy » Sun Jun 28, 2015 12:35

I have applied both bug fixes now, see in version 0.3.1.

Edit: There was another crash bug, should be fixed in version 0.3.2. Thanks to Ombridride.
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

GitHub?

by Sane » Fri Jul 31, 2015 21:32

Could you please put this mod up on GitHub?
Please, pretty please?
And also the hudbars?
Uhm ... well and while you are at it the hbarmor too?
Trying to stay me.
 

User avatar
Wuzzy
Member
 
Posts: 3241
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: [Mod] Hunger with HUD bar [0.3.2] [hbhunger]

by Wuzzy » Sat Aug 01, 2015 11:49

No. I prefer to use repo.or.cz instead of GitHub.
But I have just uploaded the Git repositories of hbhunger and hbarmor to repo.or.cz. The HUD Bars mod repository was already uploaded on repo.or.cz.

If you really insist on having the repositories on GitHub instead, you have to do it yourselves. I'm pretty sure you can easily import existing repositories. I don't know whether they allow mirroring. On the other hand, I don't think the repository provider should actually matter that much as long as the repository is online.
 

User avatar
Sane
Member
 
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: [Mod] Hunger with HUD bar [0.3.2] [hbhunger]

by Sane » Sat Aug 01, 2015 13:48

Wuzzy wrote:No. I prefer to use repo.or.cz instead of GitHub.
But I have just uploaded the Git repositories of hbhunger and hbarmor to repo.or.cz. The HUD Bars mod repository was already uploaded on repo.or.cz.

Thanks.

Wuzzy wrote:If you really insist on having the repositories on GitHub instead, ...

Nah, it was not about GitHub. Just wanted the mods as a git repository. repo.or.cz is fine (althoug it's design seems to be from the last melenium).
---

Great mods these hud bars!
What i like about the bars is their floating point approach, also I think the optics look better than BlockMan's bars.
hbhunger because it does not hide saturation. All 30 points are shown.
Thank you.
Last edited by Sane on Sun Aug 02, 2015 08:57, edited 1 time in total.
Trying to stay me.
 

User avatar
Minetestforfun
Member
 
Posts: 936
Joined: Tue Aug 05, 2014 14:09
Location: On earth
GitHub: Darcidride
IRC: Darcidride + MinetestForFun
In-game: Darcidride + MinetestForFun
 

Next

Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 10 guests