mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-04 17:40:26 +01:00
Added back hbhunger
This commit is contained in:
parent
cf6546609b
commit
a0d0c7f00b
0
minetestforfun_game/mods/jukebox/sounds/jukebox_song.1.ogg
Normal file → Executable file
0
minetestforfun_game/mods/jukebox/sounds/jukebox_song.1.ogg
Normal file → Executable file
75
mods/hbhunger/README.txt
Executable file
75
mods/hbhunger/README.txt
Executable file
|
@ -0,0 +1,75 @@
|
|||
Minetest mod: Hunger [hbhunger]
|
||||
===============================
|
||||
Version: 0.3.0
|
||||
|
||||
License of source code: WTFPL
|
||||
-----------------------------
|
||||
by Wuzzy (2015)
|
||||
|
||||
Forked from the “Better HUD (and hunger)” mod by BlockMen (2013-2014).
|
||||
|
||||
|
||||
Using the mod:
|
||||
--------------
|
||||
This mod adds a mechanic for hunger.
|
||||
This mod depends on the HUD bars mod [hudbars], major version 1.
|
||||
|
||||
You can create a "hunger.conf" file to customize the properties of hunger for your needs.
|
||||
|
||||
About hunger
|
||||
============
|
||||
This mod adds a hunger mechanic to the game.
|
||||
A new player starts with 20 satiation points out of 30.
|
||||
Player actions like digging, placing and walking cause exhausion, which lower the player's
|
||||
satiation. Also every 800 seconds you lose 1 satiation point without doing anything.
|
||||
If you are hungry (0 satiation) you will suffer damage and die in case you don't eat something.
|
||||
If your satiation is greater than 15, you will slowly regenerate health points.
|
||||
Eating food will increase your satiation.
|
||||
Important: Eating food will not directly increase your health anymore, as long as the food item
|
||||
is supported by this mod (see below).
|
||||
|
||||
|
||||
Currently supported food:
|
||||
-------------------------
|
||||
- Apples (default)
|
||||
- Animalmaterials (mobf modpack)
|
||||
- Bread (default)
|
||||
- Bushes
|
||||
- bushes_classic
|
||||
- Creatures
|
||||
- Dwarves (beer and such)
|
||||
- Docfarming
|
||||
- Fishing
|
||||
- Farming plus
|
||||
- Farming (default and Tenplus1's fork)
|
||||
- Food
|
||||
- fruit
|
||||
- Glooptest
|
||||
- JKMod
|
||||
- kpgmobs
|
||||
- Mobfcooking
|
||||
- Mooretrees
|
||||
- Mtfoods
|
||||
- mushroom
|
||||
- mush45
|
||||
- Seaplants (sea)
|
||||
- Simple mobs
|
||||
|
||||
Examples:
|
||||
Eating an apple (from the default Minetest game) increases your satiation by 2,
|
||||
eating a bread (from the default Minetest game) increases your satiation by 4.
|
||||
|
||||
|
||||
License of textures:
|
||||
--------------------
|
||||
hunger_icon.png - PilzAdam (WTFPL), modified by BlockMen
|
||||
hunger_bar.png - Wuzzy (WTFPL)
|
||||
|
||||
everything else is WTFPL:
|
||||
(c) Copyright BlockMen (2013-2015)
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
13
mods/hbhunger/changelog.txt
Executable file
13
mods/hbhunger/changelog.txt
Executable file
|
@ -0,0 +1,13 @@
|
|||
0.1.0
|
||||
-----
|
||||
Initial release
|
||||
|
||||
0.2.0
|
||||
-----
|
||||
- Change “saturation” to “satiation”
|
||||
- Rename global table to “hbhunger” to avoid collisions
|
||||
- General cleanup
|
||||
|
||||
0.3.0
|
||||
-----
|
||||
- Play simple eating sound when something is eaten
|
28
mods/hbhunger/depends.txt
Executable file
28
mods/hbhunger/depends.txt
Executable file
|
@ -0,0 +1,28 @@
|
|||
hudbars
|
||||
default?
|
||||
animalmaterials?
|
||||
bucket?
|
||||
bushes?
|
||||
bushes_classic?
|
||||
cooking?
|
||||
creatures?
|
||||
docfarming?
|
||||
dwarves?
|
||||
ethereal?
|
||||
farming?
|
||||
farming_plus?
|
||||
ferns?
|
||||
fishing?
|
||||
fruit?
|
||||
glooptest?
|
||||
jkanimals?
|
||||
jkfarming?
|
||||
jkwine?
|
||||
kpgmobs?
|
||||
mobfcooking?
|
||||
mobs?
|
||||
moretrees?
|
||||
mtfoods?
|
||||
mush45?
|
||||
mushroom?
|
||||
seaplants?
|
417
mods/hbhunger/hunger.lua
Executable file
417
mods/hbhunger/hunger.lua
Executable file
|
@ -0,0 +1,417 @@
|
|||
-- Keep these for backwards compatibility
|
||||
function hbhunger.save_hunger(player)
|
||||
hbhunger.set_hunger(player)
|
||||
end
|
||||
function hbhunger.load_hunger(player)
|
||||
hbhunger.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)
|
||||
else
|
||||
--reset hud image
|
||||
end
|
||||
if player:get_hp()-1 > 0 then
|
||||
player:set_hp(player:get_hp()-1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function hbhunger.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(hbhunger.hunger[name])
|
||||
local hp = user:get_hp()
|
||||
minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})
|
||||
|
||||
-- Saturation
|
||||
if h < 30 and hunger_change then
|
||||
h = h + hunger_change
|
||||
if h > 30 then h = 30 end
|
||||
hbhunger.hunger[name] = h
|
||||
hbhunger.set_hunger(user)
|
||||
end
|
||||
-- Healing
|
||||
if hp < 20 and heal then
|
||||
hp = hp + heal
|
||||
if hp > 20 then hp = 20 end
|
||||
user:set_hp(hp)
|
||||
end
|
||||
-- Poison
|
||||
if poisen then
|
||||
--set hud-img
|
||||
poisenp(1.0, poisen, 0, user)
|
||||
end
|
||||
|
||||
--sound:eat
|
||||
itemstack:add_item(replace_with_item)
|
||||
end
|
||||
return itemstack
|
||||
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 = hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
|
||||
minetest.registered_items[name] = tab
|
||||
end
|
||||
|
||||
if minetest.get_modpath("default") ~= nil then
|
||||
overwrite("default:apple", 2)
|
||||
end
|
||||
if minetest.get_modpath("farming") ~= nil then
|
||||
overwrite("farming:bread", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mobs") ~= nil then
|
||||
if mobs.mod ~= nil and mobs.mod == "redo" then
|
||||
overwrite("mobs:cheese", 4)
|
||||
overwrite("mobs:meat", 5)
|
||||
overwrite("mobs:meat_raw", 3)
|
||||
overwrite("mobs:rat_cooked", 5)
|
||||
overwrite("mobs:honey", 6)
|
||||
overwrite("mobs:pork_raw", 4, "", 3)
|
||||
overwrite("mobs:pork_cooked", 7)
|
||||
overwrite("mobs:chicken_cooked", 4)
|
||||
overwrite("mobs:chicken_raw", 2, "", 3)
|
||||
overwrite("mobs:egg", 1)
|
||||
overwrite("mobs:chicken_egg_fried", 2)
|
||||
if minetest.get_modpath("bucket") then
|
||||
overwrite("mobs:bucket_milk", 3, "bucket:bucket_empty")
|
||||
end
|
||||
else
|
||||
overwrite("mobs:meat", 6)
|
||||
overwrite("mobs:meat_raw", 3)
|
||||
overwrite("mobs:rat_cooked", 5)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("moretrees") ~= nil then
|
||||
overwrite("moretrees:coconut_milk", 1)
|
||||
overwrite("moretrees:raw_coconut", 2)
|
||||
overwrite("moretrees:acorn_muffin", 3)
|
||||
overwrite("moretrees:spruce_nuts", 1)
|
||||
overwrite("moretrees:pine_nuts", 1)
|
||||
overwrite("moretrees:fir_nuts", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("dwarves") ~= nil then
|
||||
overwrite("dwarves:beer", 2)
|
||||
overwrite("dwarves:apple_cider", 1)
|
||||
overwrite("dwarves:midus", 2)
|
||||
overwrite("dwarves:tequila", 2)
|
||||
overwrite("dwarves:tequila_with_lime", 2)
|
||||
overwrite("dwarves:sake", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("animalmaterials") ~= nil then
|
||||
overwrite("animalmaterials:milk", 2)
|
||||
overwrite("animalmaterials:meat_raw", 3)
|
||||
overwrite("animalmaterials:meat_pork", 3)
|
||||
overwrite("animalmaterials:meat_beef", 3)
|
||||
overwrite("animalmaterials:meat_chicken", 3)
|
||||
overwrite("animalmaterials:meat_lamb", 3)
|
||||
overwrite("animalmaterials:meat_venison", 3)
|
||||
overwrite("animalmaterials:meat_undead", 3, "", 3)
|
||||
overwrite("animalmaterials:meat_toxic", 3, "", 5)
|
||||
overwrite("animalmaterials:meat_ostrich", 3)
|
||||
overwrite("animalmaterials:fish_bluewhite", 2)
|
||||
overwrite("animalmaterials:fish_clownfish", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("fishing") ~= nil then
|
||||
overwrite("fishing:fish_raw", 2)
|
||||
overwrite("fishing:fish_cooked", 4)
|
||||
overwrite("fishing:sushi", 6)
|
||||
overwrite("fishing:shark", 2)
|
||||
overwrite("fishing:shark_cooked", 6)
|
||||
overwrite("fishing:pike", 2)
|
||||
overwrite("fishing:pike_cooked", 6)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("glooptest") ~= nil then
|
||||
overwrite("glooptest:kalite_lump", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("bushes") ~= nil then
|
||||
overwrite("bushes:sugar", 1)
|
||||
overwrite("bushes:strawberry", 2)
|
||||
overwrite("bushes:berry_pie_raw", 3)
|
||||
overwrite("bushes:berry_pie_cooked", 4)
|
||||
overwrite("bushes:basket_pies", 15)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("bushes_classic") then
|
||||
-- bushes_classic mod, as found in the plantlife modpack
|
||||
local berries = {
|
||||
"strawberry",
|
||||
"blackberry",
|
||||
"blueberry",
|
||||
"raspberry",
|
||||
"gooseberry",
|
||||
"mixed_berry"}
|
||||
for _, berry in ipairs(berries) do
|
||||
if berry ~= "mixed_berry" then
|
||||
overwrite("bushes:"..berry, 1)
|
||||
end
|
||||
overwrite("bushes:"..berry.."_pie_raw", 2)
|
||||
overwrite("bushes:"..berry.."_pie_cooked", 5)
|
||||
overwrite("bushes:basket_"..berry, 15)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mushroom") ~= nil then
|
||||
overwrite("mushroom:brown", 1)
|
||||
overwrite("mushroom:red", 1, "", 3)
|
||||
-- mushroom potions: red = strong poison, brown = light restorative
|
||||
if minetest.get_modpath("vessels") then
|
||||
overwrite("mushroom:brown_essence", 1, "vessels:glass_bottle", nil, 4)
|
||||
overwrite("mushroom:poison", 1, "vessels:glass_bottle", 10)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("docfarming") ~= nil then
|
||||
overwrite("docfarming:carrot", 3)
|
||||
overwrite("docfarming:cucumber", 2)
|
||||
overwrite("docfarming:corn", 3)
|
||||
overwrite("docfarming:potato", 4)
|
||||
overwrite("docfarming:bakedpotato", 5)
|
||||
overwrite("docfarming:raspberry", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("farming_plus") ~= nil then
|
||||
overwrite("farming_plus:carrot_item", 3)
|
||||
overwrite("farming_plus:banana", 2)
|
||||
overwrite("farming_plus:orange_item", 2)
|
||||
overwrite("farming:pumpkin_bread", 4)
|
||||
overwrite("farming_plus:strawberry_item", 2)
|
||||
overwrite("farming_plus:tomato_item", 2)
|
||||
overwrite("farming_plus:potato_item", 4)
|
||||
overwrite("farming_plus:rhubarb_item", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mtfoods") ~= nil then
|
||||
overwrite("mtfoods:dandelion_milk", 1)
|
||||
overwrite("mtfoods:sugar", 1)
|
||||
overwrite("mtfoods:short_bread", 4)
|
||||
overwrite("mtfoods:cream", 1)
|
||||
overwrite("mtfoods:chocolate", 2)
|
||||
overwrite("mtfoods:cupcake", 2)
|
||||
overwrite("mtfoods:strawberry_shortcake", 2)
|
||||
overwrite("mtfoods:cake", 3)
|
||||
overwrite("mtfoods:chocolate_cake", 3)
|
||||
overwrite("mtfoods:carrot_cake", 3)
|
||||
overwrite("mtfoods:pie_crust", 3)
|
||||
overwrite("mtfoods:apple_pie", 3)
|
||||
overwrite("mtfoods:rhubarb_pie", 2)
|
||||
overwrite("mtfoods:banana_pie", 3)
|
||||
overwrite("mtfoods:pumpkin_pie", 3)
|
||||
overwrite("mtfoods:cookies", 2)
|
||||
overwrite("mtfoods:mlt_burger", 5)
|
||||
overwrite("mtfoods:potato_slices", 2)
|
||||
overwrite("mtfoods:potato_chips", 3)
|
||||
--mtfoods:medicine
|
||||
overwrite("mtfoods:casserole", 3)
|
||||
overwrite("mtfoods:glass_flute", 2)
|
||||
overwrite("mtfoods:orange_juice", 2)
|
||||
overwrite("mtfoods:apple_juice", 2)
|
||||
overwrite("mtfoods:apple_cider", 2)
|
||||
overwrite("mtfoods:cider_rack", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("fruit") ~= nil then
|
||||
overwrite("fruit:apple", 2)
|
||||
overwrite("fruit:pear", 2)
|
||||
overwrite("fruit:bananna", 3)
|
||||
overwrite("fruit:orange", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mush45") ~= nil then
|
||||
overwrite("mush45:meal", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("seaplants") ~= nil then
|
||||
overwrite("seaplants:kelpgreen", 1)
|
||||
overwrite("seaplants:kelpbrown", 1)
|
||||
overwrite("seaplants:seagrassgreen", 1)
|
||||
overwrite("seaplants:seagrassred", 1)
|
||||
overwrite("seaplants:seasaladmix", 6)
|
||||
overwrite("seaplants:kelpgreensalad", 1)
|
||||
overwrite("seaplants:kelpbrownsalad", 1)
|
||||
overwrite("seaplants:seagrassgreensalad", 1)
|
||||
overwrite("seaplants:seagrassgreensalad", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mobfcooking") ~= nil then
|
||||
overwrite("mobfcooking:cooked_pork", 6)
|
||||
overwrite("mobfcooking:cooked_ostrich", 6)
|
||||
overwrite("mobfcooking:cooked_beef", 6)
|
||||
overwrite("mobfcooking:cooked_chicken", 6)
|
||||
overwrite("mobfcooking:cooked_lamb", 6)
|
||||
overwrite("mobfcooking:cooked_venison", 6)
|
||||
overwrite("mobfcooking:cooked_fish", 6)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("creatures") ~= nil then
|
||||
overwrite("creatures:meat", 6)
|
||||
overwrite("creatures:flesh", 3)
|
||||
overwrite("creatures:rotten_flesh", 3, "", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("ethereal") then
|
||||
overwrite("ethereal:strawberry", 1)
|
||||
overwrite("ethereal:banana", 4)
|
||||
overwrite("ethereal:pine_nuts", 1)
|
||||
overwrite("ethereal:bamboo_sprout", 0, "", 3)
|
||||
overwrite("ethereal:fern_tubers", 1)
|
||||
overwrite("ethereal:banana_bread", 7)
|
||||
overwrite("ethereal:mushroom_plant", 2)
|
||||
overwrite("ethereal:coconut_slice", 2)
|
||||
overwrite("ethereal:golden_apple", 4, "", nil, 10)
|
||||
overwrite("ethereal:wild_onion_plant", 2)
|
||||
overwrite("ethereal:mushroom_soup", 4, "ethereal:bowl")
|
||||
overwrite("ethereal:mushroom_soup_cooked", 6, "ethereal:bowl")
|
||||
overwrite("ethereal:hearty_stew", 6, "ethereal:bowl", 3)
|
||||
overwrite("ethereal:hearty_stew_cooked", 10, "ethereal:bowl")
|
||||
if minetest.get_modpath("bucket") then
|
||||
overwrite("ethereal:bucket_cactus", 2, "bucket:bucket_empty")
|
||||
end
|
||||
overwrite("ethereal:fish_raw", 2)
|
||||
overwrite("ethereal:fish_cooked", 4)
|
||||
overwrite("ethereal:seaweed", 1)
|
||||
overwrite("ethereal:yellowleaves", 1, "", nil, 1)
|
||||
overwrite("ethereal:sashimi", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("farming") and farming.mod == "redo" then
|
||||
overwrite("farming:bread", 5)
|
||||
overwrite("farming:potato", 1)
|
||||
overwrite("farming:baked_potato", 5)
|
||||
overwrite("farming:cucumber", 3)
|
||||
overwrite("farming:tomato", 3)
|
||||
overwrite("farming:carrot", 3)
|
||||
overwrite("farming:carrot_gold", 6, "", nil, 10)
|
||||
overwrite("farming:corn", 3)
|
||||
overwrite("farming:corn_cob", 5)
|
||||
overwrite("farming:melon_slice", 2)
|
||||
overwrite("farming:pumpkin_slice", 1)
|
||||
overwrite("farming:pumpkin_bread", 7)
|
||||
overwrite("farming:coffee_cup", 2, "farming:drinking_cup")
|
||||
overwrite("farming:coffee_cup_hot", 3, "farming:drinking_cup", nil, 2)
|
||||
overwrite("farming:cookie", 2)
|
||||
overwrite("farming:chocolate_dark", 3)
|
||||
overwrite("farming:donut", 4)
|
||||
overwrite("farming:donut_chocolate", 5)
|
||||
overwrite("farming:donut_apple", 5)
|
||||
overwrite("farming:raspberries", 1)
|
||||
overwrite("farming:blueberries", 1)
|
||||
overwrite("farming:muffin_blueberry", 4)
|
||||
overwrite("farming:beans", 1)
|
||||
if minetest.get_modpath("vessels") then
|
||||
overwrite("farming:smoothie_raspberry", 2, "vessels:drinking_glass")
|
||||
end
|
||||
overwrite("farming:rhubarb", 1)
|
||||
overwrite("farming:rhubarb_pie", 5)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("maptools") then
|
||||
overwrite("maptools:superapple", 10, "", nil, 20) -- valeur perso pour "Super Apple" => 10 coeurs, 5 pains
|
||||
end
|
||||
|
||||
if minetest.get_modpath("kpgmobs") ~= nil then
|
||||
overwrite("kpgmobs:uley", 3)
|
||||
overwrite("kpgmobs:meat", 6)
|
||||
overwrite("kpgmobs:rat_cooked", 5)
|
||||
overwrite("kpgmobs:med_cooked", 4)
|
||||
if minetest.get_modpath("bucket") then
|
||||
overwrite("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("jkfarming") ~= nil then
|
||||
overwrite("jkfarming:carrot", 3)
|
||||
overwrite("jkfarming:corn", 3)
|
||||
overwrite("jkfarming:melon_part", 2)
|
||||
overwrite("jkfarming:cake", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("jkanimals") ~= nil then
|
||||
overwrite("jkanimals:meat", 6)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("jkwine") ~= nil then
|
||||
overwrite("jkwine:grapes", 2)
|
||||
overwrite("jkwine:winebottle", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("cooking") ~= nil then
|
||||
overwrite("cooking:meat_beef_cooked", 4)
|
||||
overwrite("cooking:fish_bluewhite_cooked", 3)
|
||||
overwrite("cooking:fish_clownfish_cooked", 1)
|
||||
overwrite("cooking:meat_chicken_cooked", 2)
|
||||
overwrite("cooking:meat_cooked", 2)
|
||||
overwrite("cooking:meat_pork_cooked", 3)
|
||||
overwrite("cooking:meat_toxic_cooked", -3)
|
||||
overwrite("cooking:meat_venison_cooked", 3)
|
||||
overwrite("cooking:meat_undead_cooked", 1)
|
||||
end
|
||||
|
||||
-- ferns mod of plantlife_modpack
|
||||
if minetest.get_modpath("ferns") ~= nil then
|
||||
overwrite("ferns:fiddlehead", 1, "", 1)
|
||||
overwrite("ferns:fiddlehead_roasted", 3)
|
||||
overwrite("ferns:ferntuber_roasted", 3)
|
||||
overwrite("ferns:horsetail_01", 1)
|
||||
end
|
||||
|
||||
-- Food mod by Rubenwardy ( https://github.com/rubenwardy/food )
|
||||
if minetest.get_modpath("food") ~= nil then
|
||||
overwrite("food:apple_juice", 1)
|
||||
overwrite("food:rainbow_juice", 6)
|
||||
overwrite("food:cheese", 4)
|
||||
overwrite("food:cactus_juice", 3)
|
||||
overwrite("food:cake", 5)
|
||||
overwrite("food:cake_carrot", 6)
|
||||
overwrite("food:cake_choco", 7)
|
||||
overwrite("food:milk", 3)
|
||||
overwrite("food:milk_chocolate", 4)
|
||||
overwrite("food:pasta_bake", 7)
|
||||
overwrite("food:soup_chicken", 4)
|
||||
overwrite("food:soup_tomato", 4)
|
||||
end
|
||||
|
||||
-- player-action based hunger changes
|
||||
function hbhunger.handle_node_actions(pos, oldnode, player, ext)
|
||||
if not player or not player:is_player() then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local exhaus = hbhunger.exhaustion[name]
|
||||
local new = HUNGER_EXHAUST_PLACE
|
||||
-- placenode event
|
||||
if not ext then
|
||||
new = HUNGER_EXHAUST_DIG
|
||||
end
|
||||
-- assume its send by main timer when movement detected
|
||||
if not pos and not oldnode then
|
||||
new = HUNGER_EXHAUST_MOVE
|
||||
end
|
||||
exhaus = exhaus + new
|
||||
if exhaus > HUNGER_EXHAUST_LVL then
|
||||
exhaus = 0
|
||||
local h = tonumber(hbhunger.hunger[name])
|
||||
h = h - 1
|
||||
if h < 0 then h = 0 end
|
||||
hbhunger.hunger[name] = h
|
||||
hbhunger.set_hunger(player)
|
||||
end
|
||||
hbhunger.exhaustion[name] = exhaus
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(hbhunger.handle_node_actions)
|
||||
minetest.register_on_dignode(hbhunger.handle_node_actions)
|
143
mods/hbhunger/init.lua
Executable file
143
mods/hbhunger/init.lua
Executable file
|
@ -0,0 +1,143 @@
|
|||
if minetest.setting_getbool("enable_damage") then
|
||||
|
||||
hbhunger = {}
|
||||
|
||||
-- HUD statbar values
|
||||
hbhunger.hunger = {}
|
||||
hbhunger.hunger_out = {}
|
||||
|
||||
-- HUD item ids
|
||||
local hunger_hud = {}
|
||||
|
||||
HUNGER_HUD_TICK = 0.1
|
||||
|
||||
--Some hunger settings
|
||||
hbhunger.exhaustion = {} -- Exhaustion is experimental!
|
||||
|
||||
HUNGER_HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
||||
HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
|
||||
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
||||
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
||||
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
||||
|
||||
|
||||
--load custom settings
|
||||
local set = io.open(minetest.get_modpath("hbhunger").."/hbhunger.conf", "r")
|
||||
if set then
|
||||
dofile(minetest.get_modpath("hbhunger").."/hbhunger.conf")
|
||||
set:close()
|
||||
end
|
||||
|
||||
local function custom_hud(player)
|
||||
hb.init_hudbar(player, "satiation", hbhunger.get_hunger(player))
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
|
||||
|
||||
-- register satiation hudbar
|
||||
hb.register_hudbar("satiation", 0xFFFFFF, "Satiation", { icon = "hbhunger_icon.png", bar = "hbhunger_bar.png" }, 20, 30, false)
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--hunger
|
||||
local h_out = tonumber(hbhunger.hunger_out[name])
|
||||
local h = tonumber(hbhunger.hunger[name])
|
||||
if h_out ~= h then
|
||||
hbhunger.hunger_out[name] = h
|
||||
hb.change_hudbar(player, "satiation", h)
|
||||
end
|
||||
end
|
||||
|
||||
hbhunger.get_hunger = function(player)
|
||||
local inv = player:get_inventory()
|
||||
if not inv then return nil end
|
||||
local hgp = inv:get_stack("hunger", 1):get_count()
|
||||
if hgp == 0 then
|
||||
hgp = 21
|
||||
inv:set_stack("hunger", 1, ItemStack({name=":", count=hgp}))
|
||||
else
|
||||
hgp = hgp
|
||||
end
|
||||
return hgp-1
|
||||
end
|
||||
|
||||
hbhunger.set_hunger = function(player)
|
||||
local inv = player:get_inventory()
|
||||
local name = player:get_player_name()
|
||||
local value = hbhunger.hunger[name]
|
||||
if not inv or not value then return nil end
|
||||
if value > 30 then value = 30 end
|
||||
if value < 0 then value = 0 end
|
||||
|
||||
inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1}))
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local inv = player:get_inventory()
|
||||
inv:set_size("hunger",1)
|
||||
hbhunger.hunger[name] = hbhunger.get_hunger(player)
|
||||
hbhunger.hunger_out[name] = hbhunger.hunger[name]
|
||||
hbhunger.exhaustion[name] = 0
|
||||
custom_hud(player)
|
||||
hbhunger.set_hunger(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
-- reset hunger (and save)
|
||||
local name = player:get_player_name()
|
||||
hbhunger.hunger[name] = 20
|
||||
hbhunger.set_hunger(player)
|
||||
hbhunger.exhaustion[name] = 0
|
||||
end)
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
if main_timer > HUNGER_HUD_TICK or timer > 4 or timer2 > HUNGER_HUNGER_TICK then
|
||||
if main_timer > HUNGER_HUD_TICK then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
local h = tonumber(hbhunger.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
if timer > 4 then
|
||||
-- heal player by 1 hp if not dead and satiation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 and player:get_breath() > 0 then
|
||||
player:set_hp(hp+1)
|
||||
-- or damage player by 1 hp if satiation is < 2 (of 30)
|
||||
elseif h <= 1 then
|
||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||
end
|
||||
end
|
||||
-- lower satiation by 1 point after xx seconds
|
||||
if timer2 > HUNGER_HUNGER_TICK then
|
||||
if h > 0 then
|
||||
h = h-1
|
||||
hbhunger.hunger[name] = h
|
||||
hbhunger.set_hunger(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
|
||||
local controls = player:get_player_control()
|
||||
-- Determine if the player is walking
|
||||
if controls.up or controls.down or controls.left or controls.right then
|
||||
hbhunger.handle_node_actions(nil, nil, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
if timer2 > HUNGER_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
|
||||
end
|
BIN
mods/hbhunger/sounds/hbhunger_eat_generic.ogg
Executable file
BIN
mods/hbhunger/sounds/hbhunger_eat_generic.ogg
Executable file
Binary file not shown.
BIN
mods/hbhunger/textures/hbhunger_bar.png
Executable file
BIN
mods/hbhunger/textures/hbhunger_bar.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 80 B |
BIN
mods/hbhunger/textures/hbhunger_icon.png
Executable file
BIN
mods/hbhunger/textures/hbhunger_icon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 522 B |
Loading…
Reference in New Issue
Block a user