From b1b0a0df0cf34ebfa373e016a6370d9d6045fd67 Mon Sep 17 00:00:00 2001 From: kaadmy Date: Sun, 4 Oct 2015 13:40:36 -0700 Subject: [PATCH] numerous changes, including a health bar above players --- minetest.conf | 7 ++ mods/armor/init.lua | 11 ++- mods/drop_items_on_die/README.txt | 7 ++ mods/drop_items_on_die/depends.txt | 1 + mods/drop_items_on_die/init.lua | 45 ++++++++++ mods/headbars/README.txt | 7 ++ mods/headbars/depends.txt | 1 + mods/headbars/init.lua | 84 +++++++++++++++++++ mods/headbars/textures/headbars_half.png | Bin 0 -> 354 bytes mods/headbars/textures/headbars_half.xcf | Bin 0 -> 1312 bytes mods/headbars/textures/headbars_heart_bg.png | Bin 0 -> 293 bytes mods/headbars/textures/headbars_heart_bg.xcf | Bin 0 -> 948 bytes mods/hunger/init.lua | 2 +- 13 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 mods/drop_items_on_die/README.txt create mode 100644 mods/drop_items_on_die/depends.txt create mode 100644 mods/drop_items_on_die/init.lua create mode 100644 mods/headbars/README.txt create mode 100644 mods/headbars/depends.txt create mode 100644 mods/headbars/init.lua create mode 100644 mods/headbars/textures/headbars_half.png create mode 100644 mods/headbars/textures/headbars_half.xcf create mode 100644 mods/headbars/textures/headbars_heart_bg.png create mode 100644 mods/headbars/textures/headbars_heart_bg.xcf diff --git a/minetest.conf b/minetest.conf index ad43133..ea82a37 100644 --- a/minetest.conf +++ b/minetest.conf @@ -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 diff --git a/mods/armor/init.lua b/mods/armor/init.lua index e509662..4f4807c 100644 --- a/mods/armor/init.lua +++ b/mods/armor/init.lua @@ -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") diff --git a/mods/drop_items_on_die/README.txt b/mods/drop_items_on_die/README.txt new file mode 100644 index 0000000..48e401c --- /dev/null +++ b/mods/drop_items_on_die/README.txt @@ -0,0 +1,7 @@ +Drop items on die mod +===================== +By Kaadmy, for Pixture + +Players drop their inventory when they die + +Source license: WTFPL diff --git a/mods/drop_items_on_die/depends.txt b/mods/drop_items_on_die/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/mods/drop_items_on_die/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/drop_items_on_die/init.lua b/mods/drop_items_on_die/init.lua new file mode 100644 index 0000000..c8934ae --- /dev/null +++ b/mods/drop_items_on_die/init.lua @@ -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") \ No newline at end of file diff --git a/mods/headbars/README.txt b/mods/headbars/README.txt new file mode 100644 index 0000000..83496b0 --- /dev/null +++ b/mods/headbars/README.txt @@ -0,0 +1,7 @@ +Headbars mod +============ +By Kaadmy, for Pixture + +Puts a health bar above players + +Source license: WTFPL diff --git a/mods/headbars/depends.txt b/mods/headbars/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/mods/headbars/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/headbars/init.lua b/mods/headbars/init.lua new file mode 100644 index 0000000..b829663 --- /dev/null +++ b/mods/headbars/init.lua @@ -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") \ No newline at end of file diff --git a/mods/headbars/textures/headbars_half.png b/mods/headbars/textures/headbars_half.png new file mode 100644 index 0000000000000000000000000000000000000000..aed8671e2cdbf32762d32405deaadb6885a963ef GIT binary patch literal 354 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~7mKjIapa-%|A0c0C9V-A&iT2ysd*&~&PAz-C8;S2 z<(VZJ3hti10pX2&;y^{GJY5_^EKVo?`TyUZIqtxThHyq<=GF$**aJt7u(Z~)55 zJ798d&XulJhh{Z!^PS;M*O*y1ec?W%{zf2pc=Pjgo}fvOT&f#SDpsm813~kYB^EN1 zW!R1?3h}(GyvhRv1=9tx1-ulJe$1E9KOkW{^Hf3jgj5C{h55Gio>dZG)>S%A`}|PP zfzM?VPsf@YPL)A^-rk2_bs6)#J0h*{v)GzhUtId|=j-v3Dy};fg)~)`FvsbcwVl6T lXZWFDvr)~zZ`~UDK))=qSSGJtdjiN}@O1TaS?83{1OU_hd^Z39 literal 0 HcmV?d00001 diff --git a/mods/headbars/textures/headbars_half.xcf b/mods/headbars/textures/headbars_half.xcf new file mode 100644 index 0000000000000000000000000000000000000000..a73991743ee79909b582fc2c4ec421e848712fe7 GIT binary patch literal 1312 zcmbVKziZn-6xN+YWIIih{+v1px;TSN!fhSXAruoZ6tpX{tcciBuoRk1p_A9vTS1E# zPo6YsC}`5Ap?^aEiw4`t^*#A6R%i+(51!t4-}~O(J>7G?!I^Pk_l%y`cNDN4;fSAs z69S(X;I)IVih>UI5?mAhT13>n0{tPxEf=$KdV*F_H0L}`Z6W#2Kvpzn2e8_k|;2mN4ZG|SK$y2qBW_inGW2f)5a z?Lz7C1En%={2O5DMR;b}p6?p_@+=@PA0h?UI`_TE@O=Bk39&xt^+G4QyC7EoO|6*w zrT8C&kz@t5_kxgbgnxDOz_L%>VQ}u3zm5vY21I-z4qg)&<#mA}C~qpbQNf!P{G@`n zDtH?(?ki0Pfajsf>5z8;iVn)mdb~hOzuf2OH(bBvDywtC)I#Ss8B0h)iyFUWg$Chz z%2<*V1&7>}6)I56X~qhaET)(uYw=1^$6B?3@SUlw!RJXf%`y(_ETM@GJLw9#3g_wy z!IN`cxry0~%qSwxat-2dK4NS(%X4KzSpv>cw&0_fyPZG-t92na~s)Pc;bFZN?^(G{wf-ELDM8woR6zWYNYHS<+ zY#fB^#ye))G_i5BLp!qV$47W8IfvVyoW5g6Uf>%?R(OifC}%;=;T3TIGlx$_EzT-# guY!ZgkwRLS_5*;t0r1*Skr15r3)id1eSDXH06ybA{Qv*} literal 0 HcmV?d00001 diff --git a/mods/headbars/textures/headbars_heart_bg.png b/mods/headbars/textures/headbars_heart_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..05897aa3ecada62484d22f70bfb5c52a59c183b2 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~7mEn5PMP_nbwDA>64!_l=ltB<)VvY~=c3falGGH1 z^30M91$R&1fbd2>aiF4JPZ!4!i_=FZ@8&(CAmDO;-a2{q=>aWw+qSE%lSoqMlL`~U?*g8OpU*(|^ie4RY99!IZQ!fr z;`;*sndli}M@ccCr+JONlIGs`GL7qWs&7qwsn5|xiS_aLxTy`~#I}wwI@vJl`ubxcqj%MHoR~b*C+=Gi z?>C878{Ool)+SFb(@N$GqAIOl4=B^`r59y=RPMo+_scP??tSD&2d8mzm6gR!-dvk+ zZ6Q{99R|9Vi@j$#7WHj~_gDB}g>S8Jd1=X%`UFU>s}6|kxqpT`3tGOhMt5|0{fBkU z|0(+e_Gmd~4@<}``ZH$osm(nKct9= 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