numerous changes, including a health bar above players

This commit is contained in:
kaadmy 2015-10-04 13:40:36 -07:00
parent bf99cc1d13
commit b1b0a0df0c
13 changed files with 162 additions and 3 deletions

View File

@ -23,6 +23,9 @@ default_privs = interact, shout, spawn, fast
# if you're given the inital stuff; a stone pick and 10 torches
give_initial_stuff = false
# if you drop items in your inventory when you die
drop_items_on_die = true
# mob stuff
mobs_enable_blood = false
@ -50,6 +53,10 @@ testing_enable = false
hunger_enable = true
hunger_step = 2
# headbars
headbars_enable = true
headbars_scale = 1
# ambience noises
flowing_water_sounds = true

View File

@ -21,6 +21,8 @@ armor.slots = {"helmet", "chestplate", "boots"}
local form_armor = default.ui.get_page("core_2part")
default.ui.register_page("core_armor", form_armor)
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
local armor_timer = 10
function armor.is_armor(itemname)
@ -147,7 +149,7 @@ local function on_die(player)
z = pos.z + math.random(-0.2, 0.2)
}
drop = minetest.add_item(rpos, item)
local drop = minetest.add_item(rpos, item)
if drop then
drop:setvelocity(
@ -157,6 +159,9 @@ local function on_die(player)
z = math.random(-0.3, 0.3),
})
end
item:clear()
inv:set_stack("armor_" .. slot, 1, item)
end
end
@ -251,7 +256,9 @@ end
minetest.register_on_newplayer(on_newplayer)
minetest.register_on_joinplayer(on_joinplayer)
minetest.register_on_dieplayer(on_die)
if enable_drop then
minetest.register_on_dieplayer(on_die)
end
minetest.register_globalstep(step)
local form_armor = default.ui.get_page("core_2part")

View File

@ -0,0 +1,7 @@
Drop items on die mod
=====================
By Kaadmy, for Pixture
Players drop their inventory when they die
Source license: WTFPL

View File

@ -0,0 +1 @@
default

View File

@ -0,0 +1,45 @@
--
-- Drop items on die mod
-- By Kaadmy, for Pixture
--
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
local function on_die(player)
local pos = player:getpos()
local inv = player:get_inventory()
for i = 1, inv:get_size("main") do
local item = inv:get_stack("main", i)
local rpos = {
x = pos.x + math.random(-0.3, 0.3),
y = pos.y,
z = pos.z + math.random(-0.3, 0.3)
}
local drop = minetest.add_item(rpos, item)
if drop ~= nil then
local x = math.random(1, 5)
if math.random(1, 2) == 1 then
x = -x
end
local z = math.random(1, 5)
if math.random(1, 2) == 1 then
z = -z
end
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
end
item:clear()
inv:set_stack("main", i, item)
end
end
if enable_drop then
minetest.register_on_dieplayer(on_die)
end
default.log("mod:drop_items_on_die", "loaded")

7
mods/headbars/README.txt Normal file
View File

@ -0,0 +1,7 @@
Headbars mod
============
By Kaadmy, for Pixture
Puts a health bar above players
Source license: WTFPL

View File

@ -0,0 +1 @@
default

84
mods/headbars/init.lua Normal file
View File

@ -0,0 +1,84 @@
--
-- Headbars mod
-- By Kaadmy, for Pixture
--
headbars = {}
local enable_headbars = minetest.setting_getbool("headbars_enable")
if enable_headbars == nil then enable_headbars = true end
local headbars_scale = tonumber(minetest.setting_get("headbars_scale")) or 1
function headbars.get_sprite(icon, background, max, amt)
local img = "[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:0,0=ui_null.png"
if amt < max then
for i = 0, max / 2 do
img = img .. "^[combine:16x16:0,0=ui_null.png:" .. (i * 16) .. ",0=" .. background
end
end
img = img .. "^([combine:" .. (max * 8) .. "x16:0,0=ui_null.png:0,0=ui_null.png"
for i = 0, max / 2 do
if i < (amt - 1) / 2 then
img = img .. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i * 16) .. ",0=" .. icon
elseif i < amt / 2 then
img = img .. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i * 16) .. ",0=" .. icon
img = img .. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i * 16) .. ",0=headbars_half.png"
end
end
img = img .. "^[makealpha:255,0,255)"
return img
end
minetest.register_entity(
"headbars:hpbar",
{
visual = "sprite",
visual_size = {x = 1 * headbars_scale, y = 0.1 * headbars_scale, z = 1},
textures = {headbars.get_sprite("heart.png", "ui_null.png", 20, 20)},
physical = false,
collisionbox = {0, 0, 0, 0, 0, 0},
on_step = function(self, dtime)
local ent = self.wielder
if ent == nil then
self.object:remove()
return
end
local hp = ent:get_hp()
if ent:is_player() then
self.object:set_properties({textures = {headbars.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp)}})
else
self.object:set_properties({textures = {headbars.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp)}})
end
end,
})
function headbars.attach_hpbar(to)
if not enable_headbars then return end
local pos = to:getpos()
local bar = minetest.add_entity(pos, "headbars:hpbar")
if bar == nil then return end
local attach_pos = {x = 0, y = 0, z = 0}
attach_pos = {x = 0, y = 9, z = 0}
bar:set_attach(to, "", attach_pos, {x = 0, y = 0, z = 0})
bar = bar:get_luaentity()
bar.wielder = to
end
minetest.register_on_joinplayer(headbars.attach_hpbar)
default.log("mod:headbars", "loaded")

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

View File

@ -234,7 +234,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge
if player_health_step[name] == nil then player_health_step[name] = 0 end
player_health_step[name] = player_health_step[name] + 1
if player_health_step[name] >= 5 and player:get_hp() < 20 and hunger.hunger[name] >= 16 then
if hp > 0 and hp < 20 and player_health_step[name] >= 5 and hunger.hunger[name] >= 16 then
player_health_step[name] = 0
player:set_hp(hp+1)
end