Update hud and hunger
parent
a24a0f7cdb
commit
3f28ff0161
|
@ -0,0 +1,38 @@
|
|||
hud.register(name, def)
|
||||
-- name: statbar name (health, air, hunger, armor already used by default)
|
||||
-- def: <HUD item definition> (see below)
|
||||
|
||||
hud.change_item(player, name, def)
|
||||
-- player: player object
|
||||
-- name: statbar name
|
||||
-- def: table containing new values
|
||||
-- currently supported: number, text and offset
|
||||
|
||||
hud.swap_statbar(player, name1, name2) -- swaps position and offset of statbar with name1 with statbar with name2
|
||||
-- player: player object
|
||||
-- name1: statbar name
|
||||
-- name2: statbar name
|
||||
|
||||
hud.remove_item(player, name)
|
||||
|
||||
HUD item definition
|
||||
{
|
||||
hud_elem_type = "statbar", -- currently only supported type (same as in lua-api.txt)
|
||||
position = {x=<x>, y=<y>}, -- position of statbar (same as in lua-api.txt)
|
||||
size = {x=24, y=24}, -- statbar texture size (default 24x24), needed to be scaled correctly
|
||||
text = "hud_heart_fg.png", -- texture name (same as in lua-api.txt)
|
||||
number = 20, -- number/2 = number of full textures(e.g. hearts)
|
||||
max = 20, -- used to prevent "overflow" of statbars
|
||||
alignment = {x=-1,y=-1}, -- alignment on screen (same as in lua-api.txt)
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
background = "hud_heart_bg.png", -- statbar background texture name
|
||||
autohide_bg = false, -- hide statbar background textures when number = 0
|
||||
events = { -- called on events "damage" and "breath_changed" of players
|
||||
{
|
||||
type = "damage",
|
||||
func = function(player)
|
||||
-- do something here
|
||||
end
|
||||
}
|
||||
},
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
Minetest mod "Better HUD"
|
||||
=========================
|
||||
Version: 2.1.3
|
||||
Version: 2.1.4
|
||||
|
||||
(c) Copyright BlockMen (2013-2015)
|
||||
|
||||
|
|
|
@ -86,6 +86,10 @@ function hud.swap_statbar(player, item1, item2)
|
|||
local elem1 = hud_id[p_name.."_"..item1]
|
||||
local elem2 = hud_id[p_name.."_"..item2]
|
||||
|
||||
if not elem1 or not elem2 or not elem1.id or not elem2.id then
|
||||
return false
|
||||
end
|
||||
|
||||
player:hud_change(elem2.id, "offset", def1.offset)
|
||||
player:hud_change(elem1.id, "offset", def2.offset)
|
||||
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
-------------------------------------------------------------------------
|
||||
-- Wasteland
|
||||
-- Copyright (C) 2015 BlockMen <blockmen2015@gmail.de>
|
||||
--
|
||||
-- This file is part of Wasteland
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
|
||||
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
|
|
@ -1,246 +0,0 @@
|
|||
-------------------------------------------------------------------------
|
||||
-- Wasteland
|
||||
-- Copyright (C) 2015 BlockMen <blockmen2015@gmail.de>
|
||||
--
|
||||
-- This file is part of Wasteland
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
|
||||
-- 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)
|
||||
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])
|
||||
h=h+hunger_change
|
||||
if h>30 then h=30 end
|
||||
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
|
||||
poisenp(1.0, poisen, 0, user)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
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, poisen)
|
||||
minetest.registered_items[name] = tab
|
||||
end
|
||||
|
||||
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
|
||||
overwrite("mobs:meat", 6)
|
||||
overwrite("mobs:meat_raw", 3)
|
||||
overwrite("mobs:rat_cooked", 5)
|
||||
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", 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
|
||||
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)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("docfarming") ~= nil then
|
||||
overwrite("docfarming:carrot", 2)
|
||||
overwrite("docfarming:cucumber", 2)
|
||||
overwrite("docfarming:corn", 2)
|
||||
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
|
|
@ -0,0 +1,9 @@
|
|||
-- Register food with given values to change eating actions
|
||||
|
||||
hunger.register_food(name, saturation, replace_with_item, poisen, heal, sound)
|
||||
-- name: item name, e.g. "default:apple"
|
||||
-- saturation: amount of added saturation
|
||||
-- replace_with_item: item name that get returned after eating (can be nil)
|
||||
-- poisen: duration in seconds (1hp damage per second, player can't die) (can be nil)
|
||||
-- heal: added HP when eating this food (can be nil)
|
||||
-- sound: costum eating sound (replaces default eating sound) (can be nil)
|
|
@ -1,6 +1,6 @@
|
|||
Minetest mod "Hunger"
|
||||
=====================
|
||||
Version: 1.1
|
||||
Version: 1.1.3
|
||||
|
||||
(c) Copyright BlockMen (2015)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ end
|
|||
function hunger.save(player)
|
||||
local inv = player:get_inventory()
|
||||
local name = player:get_player_name()
|
||||
local value = hunger[name].lvl
|
||||
local value = hunger.players[name].lvl
|
||||
if not inv or not value then
|
||||
return nil
|
||||
end
|
||||
|
@ -40,17 +40,17 @@ function hunger.update_hunger(player, new_lvl)
|
|||
return false
|
||||
end
|
||||
if minetest.setting_getbool("enable_damage") == false then
|
||||
hunger[name] = 20
|
||||
hunger.players[name] = 20
|
||||
return
|
||||
end
|
||||
local lvl = hunger[name].lvl
|
||||
local lvl = hunger.players[name].lvl
|
||||
if new_lvl then
|
||||
lvl = new_lvl
|
||||
end
|
||||
if lvl > HUNGER_MAX then
|
||||
lvl = HUNGER_MAX
|
||||
end
|
||||
hunger[name].lvl = lvl
|
||||
hunger.players[name].lvl = lvl
|
||||
if lvl > 20 then
|
||||
lvl = 20
|
||||
end
|
||||
|
@ -65,13 +65,13 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
|
|||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if not name or not hunger[name] then
|
||||
if not name or not hunger.players[name] then
|
||||
return
|
||||
end
|
||||
|
||||
local exhaus = hunger[name].exhaus
|
||||
|
||||
local exhaus = hunger.players[name].exhaus
|
||||
if not exhaus then
|
||||
hunger[name].exhaus = 0
|
||||
hunger.players[name].exhaus = 0
|
||||
--return
|
||||
end
|
||||
|
||||
|
@ -91,13 +91,13 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
|
|||
|
||||
if exhaus > HUNGER_EXHAUST_LVL then
|
||||
exhaus = 0
|
||||
local h = tonumber(hunger[name].lvl)
|
||||
local h = tonumber(hunger.players[name].lvl)
|
||||
if h > 0 then
|
||||
update_hunger(player, h - 1)
|
||||
end
|
||||
end
|
||||
|
||||
hunger[name].exhaus = exhaus
|
||||
hunger.players[name].exhaus = exhaus
|
||||
end
|
||||
|
||||
|
||||
|
@ -126,7 +126,7 @@ local function hunger_globaltimer(dtime)
|
|||
if hunger_timer > HUNGER_TICK then
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local tab = hunger[name]
|
||||
local tab = hunger.players[name]
|
||||
if tab then
|
||||
local hunger = tab.lvl
|
||||
if hunger > 0 then
|
||||
|
@ -141,7 +141,7 @@ local function hunger_globaltimer(dtime)
|
|||
if health_timer > HUNGER_HEALTH_TICK then
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local tab = hunger[name]
|
||||
local tab = hunger.players[name]
|
||||
if tab then
|
||||
local air = player:get_breath() or 0
|
||||
local hp = player:get_hp()
|
||||
|
@ -212,6 +212,10 @@ function hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing
|
|||
local def = food[item]
|
||||
if not def then
|
||||
def = {}
|
||||
if type(hp_change) ~= "number" then
|
||||
hp_change = 1
|
||||
core.log("error", "Wrong on_use() definition for item '" .. item .. "'")
|
||||
end
|
||||
def.saturation = hp_change * 1.3
|
||||
def.replace = replace_with_item
|
||||
end
|
||||
|
@ -223,7 +227,10 @@ function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound)
|
|||
return function(itemstack, user, pointed_thing)
|
||||
if itemstack:take_item() ~= nil and user ~= nil then
|
||||
local name = user:get_player_name()
|
||||
local sat = tonumber(hunger[name].lvl)
|
||||
if not hunger.players[name] then
|
||||
return itemstack
|
||||
end
|
||||
local sat = tonumber(hunger.players[name].lvl or 0)
|
||||
local hp = user:get_hp()
|
||||
-- Saturation
|
||||
if sat < HUNGER_MAX and hunger_change then
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
hunger = {}
|
||||
hunger.players = {}
|
||||
hunger.food = {}
|
||||
|
||||
HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
||||
|
@ -31,10 +32,10 @@ if minetest.setting_getbool("enable_damage") then
|
|||
inv:set_size("hunger", 1)
|
||||
|
||||
local name = player:get_player_name()
|
||||
hunger[name] = {}
|
||||
hunger[name].lvl = hunger.read(player)
|
||||
hunger[name].exhaus = 0
|
||||
local lvl = hunger[name].lvl
|
||||
hunger.players[name] = {}
|
||||
hunger.players[name].lvl = hunger.read(player)
|
||||
hunger.players[name].exhaus = 0
|
||||
local lvl = hunger.players[name].lvl
|
||||
if lvl > 20 then
|
||||
lvl = 20
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue