Update HUD mod
This commit is contained in:
parent
59a054543b
commit
f246b187f3
@ -1,10 +1,10 @@
|
||||
Minetest mod "Better HUD"
|
||||
=========================
|
||||
version: 1.1
|
||||
Version: 1.3
|
||||
|
||||
License of source code: WTFPL
|
||||
-----------------------------
|
||||
(c) Copyright BlockMen (2013)
|
||||
(c) Copyright BlockMen (2013-2014)
|
||||
|
||||
|
||||
License of textures:
|
||||
@ -33,12 +33,12 @@ Using the mod:
|
||||
|
||||
This mod changes the HUD of Minetest.
|
||||
It improves the apperance of the health and breath bar and adds a more fancy hotbar. Furthermore it adds a
|
||||
costum crosshair, an armor bar (only for 3darmor mod) and a hunger bar. It includes also a mechanic for hunger.
|
||||
custom crosshair, an armor bar (only for 3darmor mod) and a hunger bar. It includes also a mechanic for hunger.
|
||||
|
||||
|
||||
You can create a "hud.conf" to costumize the positions of health, hunger, armor and breath bar. Take a look at "hud.conf.example" to get more infos.
|
||||
You can create a "hud.conf" to customize the positions of health, hunger, armor and breath bar. Take a look at "hud.conf.example" to get more infos.
|
||||
|
||||
!!NOTICE: Keep in mind if running a server with this mod, that the costum position should be displayed correct on every screen size!!
|
||||
!!NOTICE: Keep in mind if running a server with this mod, that the custom position should be displayed correct on every screen size!!
|
||||
|
||||
|
||||
Hunger:
|
||||
@ -46,17 +46,24 @@ This mod adds hunger to the game. You can disable this by setting "HUD_HUNGER_EN
|
||||
|
||||
Currently supported food:
|
||||
- Apples (default)
|
||||
- Bread (default)
|
||||
- Drawves (beer and such)
|
||||
- Mooretrees
|
||||
- Simple mobs
|
||||
- Animalmaterials (mobf modpack)
|
||||
- Fishing
|
||||
- Glooptest
|
||||
- Bread (default)
|
||||
- Bushes
|
||||
- bushes_classic
|
||||
- Dwarves (beer and such)
|
||||
- Docfarming
|
||||
- Fishing
|
||||
- Farming plus
|
||||
- Food
|
||||
- fruit
|
||||
- Glooptest
|
||||
- Mobfcooking
|
||||
- Mooretrees
|
||||
- Mtfoods
|
||||
- mushroom
|
||||
- mush45
|
||||
- Seaplants (sea)
|
||||
- Simple mobs
|
||||
|
||||
Example: 1 apple fills up the hunger bar by 1 bread, 1 bread (from farming) 2 breads in bar.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
0.2 Beta
|
||||
--------
|
||||
- added support of costum config files
|
||||
- added support of custom config files
|
||||
- you can eat max. 50% more than before (although it isnt shown in hunger bar)
|
||||
- you get healed with 8 breads and more (in hunger bar) now
|
||||
- a bread (from farming) == 2 breads in hunger bar
|
||||
@ -45,3 +45,21 @@
|
||||
- added support for stu's 3darmor mod
|
||||
- restructured and cleaned up code
|
||||
- added support for poisen food (damages player, but does not kill)
|
||||
|
||||
1.2
|
||||
---
|
||||
- Send statbar values only to client when changed
|
||||
- Hide armor bar if not wearing armor
|
||||
- More reliable food overrides (by CiaranG)
|
||||
- Support for bushes_classic foods (plantlife modpack) (by CiaranG)
|
||||
- Add support for mushroom mod food/poison (by CiaranG)
|
||||
- Add support for mods: fruit and mush45
|
||||
- New images for hotbar, smaller armor icons
|
||||
|
||||
1.3
|
||||
---
|
||||
- New way hunger is saved (all old files in world dirctory can get deleted [e.g. hud_BlockMen_hunger])
|
||||
- Fixed healing (not while drowning, fix after death)
|
||||
- Add support for mods: seaplants[sea] and mobfcooking (by Xanthin)
|
||||
- Tweaked hand image
|
||||
- Player can die caus of starving now
|
||||
|
@ -1 +1,18 @@
|
||||
default
|
||||
default
|
||||
creatures?
|
||||
mobs?
|
||||
moretrees?
|
||||
dwarves?
|
||||
animalmaterials?
|
||||
fishing?
|
||||
glooptest?
|
||||
bushes?
|
||||
docfarming?
|
||||
farmingplus?
|
||||
mtfoods?
|
||||
bushes_classic?
|
||||
mushroom?
|
||||
fruit?
|
||||
mush45?
|
||||
seaplants?
|
||||
mobfcooking?
|
||||
|
@ -1,29 +1,18 @@
|
||||
-- Keep these for backwards compatibility
|
||||
function hud.save_hunger(player)
|
||||
local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "w+")
|
||||
if file then
|
||||
file:write(hud.hunger[player:get_player_name()])
|
||||
file:close()
|
||||
end
|
||||
hud.set_hunger(player)
|
||||
end
|
||||
|
||||
function hud.load_hunger(player)
|
||||
local file = io.open(minetest.get_worldpath().."/hud_"..player:get_player_name().."_hunger", "r")
|
||||
if file then
|
||||
hud.hunger[player:get_player_name()] = file:read("*all")
|
||||
file:close()
|
||||
return hud.hunger[player:get_player_name()]
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
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
|
||||
if player:get_hp()-1 > 0 then
|
||||
player:set_hp(player:get_hp()-1)
|
||||
end
|
||||
|
||||
@ -31,12 +20,13 @@ end
|
||||
|
||||
function hud.item_eat(hunger_change, replace_with_item, poisen)
|
||||
return function(itemstack, user, pointed_thing)
|
||||
if itemstack:take_item() ~= nil then
|
||||
local h = tonumber(hud.hunger[user:get_player_name()])
|
||||
if itemstack:take_item() ~= nil and user ~= nil then
|
||||
local name = user:get_player_name()
|
||||
local h = tonumber(hud.hunger[name])
|
||||
h=h+hunger_change
|
||||
if h>30 then h=30 end
|
||||
hud.hunger[user:get_player_name()]=h
|
||||
hud.save_hunger(user)
|
||||
hud.hunger[name]=h
|
||||
hud.set_hunger(user)
|
||||
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
|
||||
--sound:eat
|
||||
if poisen then
|
||||
@ -54,14 +44,17 @@ local function overwrite(name, hunger_change, replace_with_item, poisen)
|
||||
minetest.registered_items[name] = tab
|
||||
end
|
||||
|
||||
minetest.after(0.5, function()--ensure all other mods get loaded
|
||||
overwrite("default:apple", 2)
|
||||
overwrite("default:old_apple", 1, "", 1)
|
||||
overwrite("default:old_bread", 4, "", 3)
|
||||
|
||||
if minetest.get_modpath("farming") ~= nil then
|
||||
overwrite("farming:bread", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("creatures") ~= nil then
|
||||
overwrite("creatures:flesh", 5)
|
||||
overwrite("creatures:rotten_flesh", 4, "", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mobs") ~= nil then
|
||||
@ -79,6 +72,15 @@ if minetest.get_modpath("moretrees") ~= nil then
|
||||
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)
|
||||
@ -98,6 +100,10 @@ if minetest.get_modpath("fishing") ~= nil then
|
||||
overwrite("fishing:fish_raw", 2)
|
||||
overwrite("fishing:fish", 4)
|
||||
overwrite("fishing:sushi", 6)
|
||||
overwrite("fishing:shark", 4)
|
||||
overwrite("fishing:shark_cooked", 8)
|
||||
overwrite("fishing:pike", 4)
|
||||
overwrite("fishing:pike_cooked", 8)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("glooptest") ~= nil then
|
||||
@ -112,6 +118,30 @@ if minetest.get_modpath("bushes") ~= nil then
|
||||
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)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("docfarming") ~= nil then
|
||||
overwrite("docfarming:carrot", 2)
|
||||
overwrite("docfarming:cucumber", 2)
|
||||
@ -125,10 +155,11 @@ 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_plus:pumpkin_bread", 4)
|
||||
overwrite("farming:pumpkin_bread", 4)
|
||||
overwrite("farming_plus:strawberry_item", 2)
|
||||
overwrite("farming_plus:tomato_item", 2)
|
||||
overwrite("farming_plus:potatoe_item", 4)
|
||||
overwrite("farming_plus:potato_item", 4)
|
||||
overwrite("farming_plus:rhubarb_item", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mtfoods") ~= nil then
|
||||
@ -159,4 +190,36 @@ if minetest.get_modpath("mtfoods") ~= nil then
|
||||
overwrite("mtfoods:apple_cider", 2)
|
||||
overwrite("mtfoods:cider_rack", 2)
|
||||
end
|
||||
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
|
||||
|
@ -1,20 +1,22 @@
|
||||
hud = {}
|
||||
|
||||
local health_hud = {}
|
||||
-- HUD statbar values
|
||||
hud.health = {}
|
||||
hud.hunger = {}
|
||||
hud.air = {}
|
||||
hud.armor = {}
|
||||
hud.hunger_out = {}
|
||||
hud.armor_out = {}
|
||||
|
||||
-- HUD item ids
|
||||
local health_hud = {}
|
||||
local hunger_hud = {}
|
||||
local air_hud = {}
|
||||
hud.armor = {}
|
||||
local armor_hud = {}
|
||||
local armor_hud_bg = {}
|
||||
|
||||
local SAVE_INTERVAL = 0.5*60--currently useless
|
||||
|
||||
--default settings
|
||||
HUD_ENABLE_HUNGER = minetest.setting_getbool("hud_hunger_enable")
|
||||
HUD_SHOW_ARMOR = false
|
||||
if minetest.get_modpath("3d_armor") ~= nil then HUD_SHOW_ARMOR = true end
|
||||
if HUD_ENABLE_HUNGER == nil then HUD_ENABLE_HUNGER = minetest.setting_getbool("enable_damage") end
|
||||
HUD_HUNGER_TICK = 120
|
||||
-- default settings
|
||||
-- statbar positions
|
||||
HUD_HEALTH_POS = {x=0.5,y=0.9}
|
||||
HUD_HEALTH_OFFSET = {x=-175, y=2}
|
||||
HUD_HUNGER_POS = {x=0.5,y=0.9}
|
||||
@ -24,7 +26,20 @@ HUD_AIR_OFFSET = {x=15,y=-15}
|
||||
HUD_ARMOR_POS = {x=0.5,y=0.9}
|
||||
HUD_ARMOR_OFFSET = {x=-175, y=-15}
|
||||
|
||||
--load costum settings
|
||||
HUD_TICK = 0.2
|
||||
HUD_HUNGER_TICK = 120
|
||||
|
||||
HUD_ENABLE_HUNGER = minetest.setting_getbool("hud_hunger_enable")
|
||||
if HUD_ENABLE_HUNGER == nil then
|
||||
HUD_ENABLE_HUNGER = minetest.setting_getbool("enable_damage")
|
||||
end
|
||||
|
||||
HUD_SHOW_ARMOR = false
|
||||
if minetest.get_modpath("3d_armor") ~= nil then
|
||||
HUD_SHOW_ARMOR = true
|
||||
end
|
||||
|
||||
--load custom settings
|
||||
local set = io.open(minetest.get_modpath("hud").."/hud.conf", "r")
|
||||
if set then
|
||||
dofile(minetest.get_modpath("hud").."/hud.conf")
|
||||
@ -35,18 +50,19 @@ else
|
||||
end
|
||||
end
|
||||
|
||||
--minetest.after(SAVE_INTERVAL, timer, SAVE_INTERVAL)
|
||||
|
||||
local function hide_builtin(player)
|
||||
player:hud_set_flags({crosshair = true, hotbar = true, healthbar = false, wielditem = true, breathbar = false})
|
||||
end
|
||||
|
||||
|
||||
local function costum_hud(player)
|
||||
local function custom_hud(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
--fancy hotbar
|
||||
player:hud_set_hotbar_image("hud_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("hud_hotbar_selected.png")
|
||||
-- fancy hotbar (only when no crafting mod present)
|
||||
if minetest.get_modpath("crafting") == nil then
|
||||
player:hud_set_hotbar_image("hud_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("hud_hotbar_selected.png")
|
||||
end
|
||||
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
--hunger
|
||||
@ -60,13 +76,14 @@ local function costum_hud(player)
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
})
|
||||
|
||||
hunger_hud[player:get_player_name()] = player:hud_add({
|
||||
local h = hud.hunger[name]
|
||||
if h == nil or h > 20 then h = 20 end
|
||||
hunger_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "hud_hunger_fg.png",
|
||||
number = 20,
|
||||
number = h,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
})
|
||||
@ -81,8 +98,7 @@ local function costum_hud(player)
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
})
|
||||
|
||||
health_hud[player:get_player_name()] = player:hud_add({
|
||||
health_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
scale = {x=1, y=1},
|
||||
@ -93,7 +109,7 @@ local function costum_hud(player)
|
||||
})
|
||||
|
||||
--air
|
||||
air_hud[player:get_player_name()] = player:hud_add({
|
||||
air_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
scale = {x=1, y=1},
|
||||
@ -105,17 +121,16 @@ local function costum_hud(player)
|
||||
|
||||
--armor
|
||||
if HUD_SHOW_ARMOR then
|
||||
player:hud_add({
|
||||
armor_hud_bg[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "hud_armor_bg.png",
|
||||
number = 20,
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_ARMOR_OFFSET,
|
||||
})
|
||||
|
||||
armor_hud[player:get_player_name()] = player:hud_add({
|
||||
armor_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
@ -126,41 +141,9 @@ local function costum_hud(player)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
text = "hud_over.png",
|
||||
position = {x=0,y=0},
|
||||
scale = {x=1, y=1},
|
||||
offset = {x=200,y=112},
|
||||
})
|
||||
|
||||
player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
text = "hud_over.png^hud_over.png^[transformfx",--^hud_crack.png",
|
||||
position = {x=1,y=0},
|
||||
scale = {x=1, y=1},
|
||||
offset = {x=-200,y=112},
|
||||
})
|
||||
player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
text = "hud_over2.png",
|
||||
position = {x=0,y=1},
|
||||
scale = {x=1, y=1},
|
||||
offset = {x=200,y=-112},
|
||||
})
|
||||
|
||||
player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
text = "hud_over2.png^[transformfx",
|
||||
position = {x=1,y=1},
|
||||
scale = {x=1, y=1},
|
||||
offset = {x=-200,y=-112},
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
--needs to be set always(for 3darmor)
|
||||
--needs to be defined for older version of 3darmor
|
||||
function hud.set_armor()
|
||||
end
|
||||
|
||||
@ -168,79 +151,150 @@ end
|
||||
if HUD_ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end
|
||||
if HUD_SHOW_ARMOR then dofile(minetest.get_modpath("hud").."/armor.lua") end
|
||||
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--air
|
||||
local air = player:get_breath()*2
|
||||
if player:get_breath() > 10 then air = 0 end
|
||||
player:hud_change(air_hud[player:get_player_name()], "number", air)
|
||||
local air = tonumber(hud.air[name])
|
||||
if player:get_breath() ~= air then
|
||||
air = player:get_breath()
|
||||
hud.air[name] = air
|
||||
if air > 10 then air = 0 end
|
||||
player:hud_change(air_hud[name], "number", air*2)
|
||||
end
|
||||
--health
|
||||
player:hud_change(health_hud[player:get_player_name()], "number", player:get_hp())
|
||||
local hp = tonumber(hud.health[name])
|
||||
if player:get_hp() ~= hp then
|
||||
hp = player:get_hp()
|
||||
hud.health[name] = hp
|
||||
player:hud_change(health_hud[name], "number", hp)
|
||||
end
|
||||
--armor
|
||||
local arm = tonumber(hud.armor[player:get_player_name()])
|
||||
local arm_out = tonumber(hud.armor_out[name])
|
||||
if not arm_out then arm_out = 0 end
|
||||
local arm = tonumber(hud.armor[name])
|
||||
if not arm then arm = 0 end
|
||||
player:hud_change(armor_hud[player:get_player_name()], "number", arm)
|
||||
if arm_out ~= arm then
|
||||
hud.armor_out[name] = arm
|
||||
player:hud_change(armor_hud[name], "number", arm)
|
||||
-- hide armor bar completely when there is none
|
||||
if (not armor.def[name].count or armor.def[name].count == 0) and arm == 0 then
|
||||
player:hud_change(armor_hud_bg[name], "number", 0)
|
||||
else
|
||||
player:hud_change(armor_hud_bg[name], "number", 20)
|
||||
end
|
||||
end
|
||||
--hunger
|
||||
local h = tonumber(hud.hunger[player:get_player_name()])
|
||||
if h>20 then h=20 end
|
||||
player:hud_change(hunger_hud[player:get_player_name()], "number", h)
|
||||
local h_out = tonumber(hud.hunger_out[name])
|
||||
local h = tonumber(hud.hunger[name])
|
||||
if h_out ~= h then
|
||||
hud.hunger_out[name] = h
|
||||
-- bar should not have more than 10 icons
|
||||
if h>20 then h=20 end
|
||||
player:hud_change(hunger_hud[name], "number", h)
|
||||
end
|
||||
end
|
||||
|
||||
local function timer(interval, player)
|
||||
if interval > 0 then
|
||||
hud.save_hunger(player)
|
||||
minetest.after(interval, timer, interval, player)
|
||||
hud.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
|
||||
|
||||
hud.set_hunger = function(player)
|
||||
local inv = player:get_inventory()
|
||||
local name = player:get_player_name()
|
||||
local value = hud.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)
|
||||
hud.armor[player:get_player_name()] = 0
|
||||
if HUD_ENABLE_HUNGER then hud.hunger[player:get_player_name()] = hud.load_hunger(player) end
|
||||
if not hud.hunger[player:get_player_name()] then
|
||||
hud.hunger[player:get_player_name()] = 20
|
||||
local name = player:get_player_name()
|
||||
local inv = player:get_inventory()
|
||||
inv:set_size("hunger",1)
|
||||
hud.health[name] = player:get_hp()
|
||||
if HUD_ENABLE_HUNGER then
|
||||
hud.hunger[name] = hud.get_hunger(player)
|
||||
hud.hunger_out[name] = hud.hunger[name]
|
||||
end
|
||||
hud.armor[name] = 0
|
||||
hud.armor_out[name] = 0
|
||||
local air = player:get_breath()
|
||||
hud.air[name] = air
|
||||
minetest.after(0.5, function()
|
||||
hide_builtin(player)
|
||||
costum_hud(player)
|
||||
if HUD_ENABLE_HUNGER then hud.save_hunger(player) end
|
||||
custom_hud(player)
|
||||
if HUD_ENABLE_HUNGER then hud.set_hunger(player) end
|
||||
end)
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
-- reset player breath since the engine doesnt
|
||||
player:set_breath(11)
|
||||
-- reset hunger (and save)
|
||||
hud.hunger[player:get_player_name()] = 20
|
||||
minetest.after(0.5, function()
|
||||
if HUD_ENABLE_HUNGER then hud.save_hunger(player) end
|
||||
end)
|
||||
if HUD_ENABLE_HUNGER then
|
||||
minetest.after(0.5, hud.set_hunger, player)
|
||||
end
|
||||
end)
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.after(2.5, function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
if main_timer > HUD_TICK or timer > 4 or timer2 > HUD_HUNGER_TICK then
|
||||
if main_timer > HUD_TICK then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- only proceed if damage is enabled
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
local h = tonumber(hud.hunger[player:get_player_name()])
|
||||
local h = tonumber(hud.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
if HUD_ENABLE_HUNGER and timer > 4 then
|
||||
if h>=15 and player:get_hp() > 0 then
|
||||
player:set_hp(player:get_hp()+1)
|
||||
elseif h<=1 and minetest.setting_getbool("enable_damage") then
|
||||
if player:get_hp()-1 >= 0 then player:set_hp(player:get_hp()-1) end
|
||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 and hud.air[name] > 0 then
|
||||
player:set_hp(hp+1)
|
||||
-- or damage player by 1 hp if saturation is < 2 (of 30)
|
||||
elseif h <= 1 and minetest.setting_getbool("enable_damage") then
|
||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||
end
|
||||
end
|
||||
if HUD_ENABLE_HUNGER and timer2>HUD_HUNGER_TICK then
|
||||
if h>0 then
|
||||
h=h-1
|
||||
hud.hunger[player:get_player_name()]=h
|
||||
hud.save_hunger(player)
|
||||
-- lower saturation by 1 point after xx seconds
|
||||
if HUD_ENABLE_HUNGER and timer2 > HUD_HUNGER_TICK then
|
||||
if h > 0 then
|
||||
h = h-1
|
||||
hud.hunger[name] = h
|
||||
hud.set_hunger(player)
|
||||
end
|
||||
end
|
||||
-- update current armor level
|
||||
if HUD_SHOW_ARMOR then hud.get_armor(player) end
|
||||
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
if timer>4 then timer=0 end
|
||||
if timer2>HUD_HUNGER_TICK then timer2=0 end
|
||||
if timer > 4 then timer = 0 end
|
||||
if timer2 > HUD_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
end)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 311 B After Width: | Height: | Size: 424 B |
Binary file not shown.
Before Width: | Height: | Size: 507 B After Width: | Height: | Size: 3.1 KiB |
Loading…
x
Reference in New Issue
Block a user