From 09fc5ee48ae2a9adc7752e8521302b3263573436 Mon Sep 17 00:00:00 2001 From: BlockMen Date: Fri, 13 Sep 2013 20:18:16 +0200 Subject: [PATCH] Add support for 3darmor mod, add poisen food and restructure code --- README.txt | 13 ++++-- armor.lua | 31 +++++++++++++ changelog.txt | 6 +++ hunger.lua | 44 ++++++++++++++++-- init.lua | 94 ++++++++++++++++++++++---------------- textures/hud_armor_bg.png | Bin 0 -> 311 bytes textures/hud_armor_fg.png | Bin 0 -> 507 bytes 7 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 armor.lua create mode 100644 textures/hud_armor_bg.png create mode 100644 textures/hud_armor_fg.png diff --git a/README.txt b/README.txt index c0da4e0..0656f33 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,6 @@ Minetest mod "Better HUD" ========================= -version: 1.0 +version: 1.1 License of source code: WTFPL ----------------------------- @@ -15,6 +15,8 @@ hud_hunger_fg.png - PilzAdam (WTFPL), modified by BlockMen hud_hunger_bg.png - PilzAdam (WTFPL), modified by BlockMen wieldhand.png (from character.png) - Jordach (CC BY-SA 3.0), modified by BlockMen hud_air_fg.png - kaeza (WTFPL), modified by BlockMen +hud_armor_fg.png - Stu (CC BY-SA 3.0), modified by BlockMen +hud_armor_bg.png - Stu (CC BY-SA 3.0), modified by BlockMen everything else is WTFPL: (c) Copyright BlockMen (2013) @@ -29,11 +31,12 @@ http://sam.zoy.org/wtfpl/COPYING for more details. Using the mod: -------------- -This mod changes the HUD of Minetest. It adds a costum crosshair, a improved health bar, breath bar and a more fancy inventory bar. -Also it adds hunger to the game and and hunger bar to the HUD. +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. -You can create a "hud.conf" to costumize the positions of health, hunger and breath bar. Take a look at "hud.conf.example" to get more infos. +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. !!NOTICE: Keep in mind if running a server with this mod, that the costum position should be displayed correct on every screen size!! @@ -56,3 +59,5 @@ Currently supported food: - Mtfoods Example: 1 apple fills up the hunger bar by 1 bread, 1 bread (from farming) 2 breads in bar. + +Altough it show 20 hunger points (10 breads) in hunger bar you can fill it up to 30 points. (5 breads not shown then) diff --git a/armor.lua b/armor.lua new file mode 100644 index 0000000..2030c42 --- /dev/null +++ b/armor.lua @@ -0,0 +1,31 @@ +minetest.after(0, function() + if not armor.def then + minetest.after(2,minetest.chat_send_all,"#Better HUD: Please update your version of 3darmor") + HUD_SHOW_ARMOR = false + end +end) + +function hud.get_armor(player) + if not player or not armor.def then + return + end + local name = player:get_player_name() + hud.set_armor(player, armor.def[name].state, armor.def[name].count) +end + +function hud.set_armor(player, ges_state, items) + if not player then return end + + local max_items = 4 + if items == 5 then max_items = items end + local max = max_items*65535 + local lvl = max - ges_state + lvl = lvl/max + if ges_state == 0 and items == 0 then + lvl = 0 + end + + hud.armor[player:get_player_name()] = lvl*(items*(20/max_items)) + + +end \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index 537fb53..50b024c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -39,3 +39,9 @@ - fixed revival of player when drown - hunger bar is not shown anymore if hunger is disabled - hunger can be disabled by minetest.conf ("hud_hunger_enable = false") + +1.1 +--- +- added support for stu's 3darmor mod +- restructured and cleaned up code +- added support for poisen food (damages player, but does not kill) diff --git a/hunger.lua b/hunger.lua index acabf83..106fe6c 100644 --- a/hunger.lua +++ b/hunger.lua @@ -1,4 +1,35 @@ -function hud.item_eat(hunger_change, replace_with_item) +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 +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 + +end + +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) return function(itemstack, user, pointed_thing) if itemstack:take_item() ~= nil then local h = tonumber(hud.hunger[user:get_player_name()]) @@ -8,15 +39,18 @@ function hud.item_eat(hunger_change, replace_with_item) hud.save_hunger(user) itemstack:add_item(replace_with_item) -- note: replace_with_item is optional --sound:eat + if poisen then + poisenp(1.0, poisen, 0, user) + end end return itemstack end end -local function overwrite(name, hunger_change, replace_with_item) +local function overwrite(name, hunger_change, replace_with_item, poisen) local tab = minetest.registered_items[name] if tab == nil then return end - tab.on_use = hud.item_eat(hunger_change)--, replace_with_item) + tab.on_use = hud.item_eat(hunger_change, replace_with_item, poisen) minetest.registered_items[name] = tab end @@ -58,8 +92,8 @@ if minetest.get_modpath("animalmaterials") ~= nil then overwrite("animalmaterials:meat_chicken", 3) overwrite("animalmaterials:meat_lamb", 3) overwrite("animalmaterials:meat_venison", 3) - --overwrite("animalmaterials:meat_undead", 3)-- -3 damage - --overwrite("animalmaterials:meat_toxic", 3)-- -5 damage + 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) diff --git a/init.lua b/init.lua index 9902e66..18afa39 100644 --- a/init.lua +++ b/init.lua @@ -4,12 +4,15 @@ local health_hud = {} hud.hunger = {} local hunger_hud = {} local air_hud = {} -local inv_hud = {} +hud.armor = {} +local armor_hud = {} 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 = 300 HUD_HEALTH_POS = {x=0.5,y=0.9} @@ -18,6 +21,8 @@ HUD_HUNGER_POS = {x=0.5,y=0.9} HUD_HUNGER_OFFSET = {x=15, y=2} HUD_AIR_POS = {x=0.5,y=0.9} 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 local set = io.open(minetest.get_modpath("hud").."/hud.conf", "r") @@ -93,40 +98,63 @@ local function costum_hud(player) position = HUD_AIR_POS, scale = {x=1, y=1}, text = "hud_air_fg.png", - number = 20, + number = 0, alignment = {x=-1,y=-1}, offset = HUD_AIR_OFFSET, }) + + --armor + if HUD_SHOW_ARMOR then + player:hud_add({ + hud_elem_type = "statbar", + position = HUD_ARMOR_POS, + scale = {x=1, y=1}, + text = "hud_armor_bg.png", + number = 20, + alignment = {x=-1,y=-1}, + offset = HUD_ARMOR_OFFSET, + }) + + armor_hud[player:get_player_name()] = player:hud_add({ + hud_elem_type = "statbar", + position = HUD_ARMOR_POS, + scale = {x=1, y=1}, + text = "hud_armor_fg.png", + number = 0, + alignment = {x=-1,y=-1}, + offset = HUD_ARMOR_OFFSET, + }) + end end end +--needs to be set always(for 3darmor) +function hud.set_armor() +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 + local function update_hud(player) ---health + --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) + --health player:hud_change(health_hud[player:get_player_name()], "number", player:get_hp()) ---hunger + --armor + local arm = tonumber(hud.armor[player:get_player_name()]) + if not arm then arm = 0 end + player:hud_change(armor_hud[player:get_player_name()], "number", arm) + --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) end -local function update_fast(player) ---air - local air = player:get_breath()*2 - if player:get_breath() >= 11 then air = 0 end - player:hud_change(air_hud[player:get_player_name()], "number", air) -end - - -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 -end - local function timer(interval, player) if interval > 0 then hud.save_hunger(player) @@ -134,35 +162,23 @@ local function timer(interval, player) end end -local function 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 - -end - - minetest.register_on_joinplayer(function(player) - hud.hunger[player:get_player_name()] = load_hunger(player) - if hud.hunger[player:get_player_name()] == nil then + 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 end minetest.after(0.5, function() - hud.save_hunger(player) hide_builtin(player) costum_hud(player) + if HUD_ENABLE_HUNGER then hud.save_hunger(player) end end) end) minetest.register_on_respawnplayer(function(player) hud.hunger[player:get_player_name()] = 20 minetest.after(0.5, function() - hud.save_hunger(player) + if HUD_ENABLE_HUNGER then hud.save_hunger(player) end end) end) @@ -173,7 +189,6 @@ minetest.after(2.5, function() timer = timer + dtime timer2 = timer2 + dtime for _,player in ipairs(minetest.get_connected_players()) do - update_fast(player) if minetest.setting_getbool("enable_damage") then local h = tonumber(hud.hunger[player:get_player_name()]) if HUD_ENABLE_HUNGER and timer > 4 then @@ -190,6 +205,7 @@ minetest.after(2.5, function() hud.save_hunger(player) end end + if HUD_SHOW_ARMOR then hud.get_armor(player) end update_hud(player) end end @@ -197,5 +213,3 @@ minetest.after(2.5, function() if timer2>HUD_HUNGER_TICK then timer2=0 end end) end) - -if HUD_ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end diff --git a/textures/hud_armor_bg.png b/textures/hud_armor_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..24a43d1aec1bda8572f06896863814c497006226 GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GGLLkg|>2BR0px{eS z7srr_IZG!w_O&R8xY#x=cR0|YV^F5?gks422jN4UR>;w1}V9`q&~!^C*`}`# z9xfV6XU=bZQ~Ye#I$Z{b&%VJ%12r^q;!tXU|5q-1}WN;a9G{K(;QU$+0Oy%QLl} zc^_abJQq5bVL|aaqx(#8k1O6wI_)so&$_2+T@UXA>AwvBD*jj`35Zt$JgTe~ HDWM4f*|LDX literal 0 HcmV?d00001 diff --git a/textures/hud_armor_fg.png b/textures/hud_armor_fg.png new file mode 100644 index 0000000000000000000000000000000000000000..ef49dc04b8a5fbd4a289c36a5b10c8f375a35f3c GIT binary patch literal 507 zcmVYVRcoznq2pGgPkTwPvtxs!s~WR`Sir=cFPv<)0Amd@wi;_Sl29?hO8{<3c()GyuG!+YO`Uv zUb9@U8AcJ~JSQoN7O0x$7+7sK_-RU96l7&dR+dyv!!U|4d5%gFTw}0251po`0h8xU zrc;ulATA2#&(C1{nnO1_PWR xpfBZK`7H49FFa%R{@`%$EN}>&o43Gc@(%%m`3U;HM7#h1002ovPDHLkV1kb5>EHkW literal 0 HcmV?d00001