commit 61d988823f8be9ac2e705c3a390ea38139c2a878 Author: 4aiman <4aiman@inbox.ru> Date: Thu Oct 12 15:48:40 2017 +0100 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ff7418 --- /dev/null +++ b/.gitignore @@ -0,0 +1,111 @@ + +# Created by https://www.gitignore.io/api/lua,linux,macos,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Lua ### +# Compiled Lua sources +luac.out + +# luarocks build files +*.src.rock +*.zip +*.tar.gz + +# Object files +*.o +*.os +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo +*.def +*.exp + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/lua,linux,macos,windows + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..48dc176 --- /dev/null +++ b/init.lua @@ -0,0 +1,43 @@ +-- Adds health bars above players. +-- Code by 4aiman, textures by Calinou. Licensed under CC0. + +local hp_bar = { + physical = false, + collisionbox = {x = 0, y = 0, z = 0}, + visual = "sprite", + textures = {"20.png"}, -- The texture is changed later in the code. + visual_size = {x = 1.5, y = 0.09375, z = 1.5}, -- Y value is (1 / 16) * 1.5. + wielder = nil, +} + +function hp_bar:on_step(dtime) + local wielder = self.wielder + if wielder == nil then + self.object:remove() + return + elseif minetest.env:get_player_by_name(wielder:get_player_name()) == nil then + self.object:remove() + return + end + hp = wielder:get_hp() + breath = wielder:get_breath() + self.object:set_properties({textures = {"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png",},} + ) +end + +minetest.register_entity("gauges:hp_bar", hp_bar) + +function add_HP_gauge(pl) + local pos = pl:getpos() + local ent = minetest.env:add_entity(pos, "gauges:hp_bar") + if ent ~= nil then + ent:set_attach(pl, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0}) + ent = ent:get_luaentity() + ent.wielder = pl + end +end + +if minetest.setting_getbool("health_bars") ~= false -- “If not defined or set to true then” +and minetest.setting_getbool("enable_damage") then -- Health bars only display when damage is enabled. + minetest.register_on_joinplayer(add_HP_gauge) +end