Reorganise game into modpacks
88
mods/pvp/gauges/init.lua
Normal file
|
@ -0,0 +1,88 @@
|
|||
-- Adds health bars above players.
|
||||
-- Code by 4aiman, textures by Calinou. Licensed under CC0.
|
||||
|
||||
gauges = {}
|
||||
|
||||
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 vector.sqdist(a, b)
|
||||
local dx = a.x - b.x
|
||||
local dy = a.y - b.y
|
||||
local dz = a.z - b.z
|
||||
return dx*dx + dy*dy + dz*dz
|
||||
end
|
||||
|
||||
function hp_bar:on_step(dtime)
|
||||
local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
|
||||
if wielder == nil then
|
||||
print("[gauges] Gauge removed as null wielder! " .. dump(self.wielder))
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
if vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3 then
|
||||
print("[gauges] Gauge removed as not attached! " .. dump(self.wielder))
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local hp = wielder:get_hp()
|
||||
local 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 gauges.add_HP_gauge(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
local pos = player:get_pos()
|
||||
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
||||
if ent ~= nil then
|
||||
ent:set_attach(player, "", {x = 0, y = 9, z = 0}, {x = 0, y = 0, z = 0})
|
||||
ent = ent:get_luaentity()
|
||||
ent.wielder = player:get_player_name()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- If health_bars not defined or set to true
|
||||
if minetest.settings:get_bool("health_bars") ~= false and
|
||||
minetest.settings:get_bool("enable_damage") then
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(2, gauges.add_HP_gauge, player:get_player_name())
|
||||
end)
|
||||
end
|
||||
|
||||
function gauges.check_gauges()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
local found = false
|
||||
local objects = minetest.get_objects_inside_radius(player:get_pos(), 1)
|
||||
for _, object in pairs(objects) do
|
||||
local le = object:get_luaentity()
|
||||
if le and le.wielder == pname then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
print("Gauge not found!")
|
||||
gauges.add_HP_gauge(pname)
|
||||
end
|
||||
end
|
||||
minetest.after(9.3, gauges.check_gauges)
|
||||
end
|
||||
minetest.after(2, gauges.check_gauges)
|
BIN
mods/pvp/gauges/textures/breath_0.png
Normal file
After Width: | Height: | Size: 131 B |
BIN
mods/pvp/gauges/textures/breath_1.png
Normal file
After Width: | Height: | Size: 170 B |
BIN
mods/pvp/gauges/textures/breath_10.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
mods/pvp/gauges/textures/breath_11.png
Normal file
After Width: | Height: | Size: 68 B |
BIN
mods/pvp/gauges/textures/breath_2.png
Normal file
After Width: | Height: | Size: 171 B |
BIN
mods/pvp/gauges/textures/breath_3.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
mods/pvp/gauges/textures/breath_4.png
Normal file
After Width: | Height: | Size: 162 B |
BIN
mods/pvp/gauges/textures/breath_5.png
Normal file
After Width: | Height: | Size: 155 B |
BIN
mods/pvp/gauges/textures/breath_6.png
Normal file
After Width: | Height: | Size: 151 B |
BIN
mods/pvp/gauges/textures/breath_65535.png
Normal file
After Width: | Height: | Size: 68 B |
BIN
mods/pvp/gauges/textures/breath_7.png
Normal file
After Width: | Height: | Size: 146 B |
BIN
mods/pvp/gauges/textures/breath_8.png
Normal file
After Width: | Height: | Size: 140 B |
BIN
mods/pvp/gauges/textures/breath_9.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
mods/pvp/gauges/textures/health_0.png
Normal file
After Width: | Height: | Size: 68 B |
BIN
mods/pvp/gauges/textures/health_1.png
Normal file
After Width: | Height: | Size: 100 B |
BIN
mods/pvp/gauges/textures/health_10.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_11.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_12.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_13.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_14.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_15.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_16.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_17.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_18.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_19.png
Normal file
After Width: | Height: | Size: 106 B |
BIN
mods/pvp/gauges/textures/health_2.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
mods/pvp/gauges/textures/health_20.png
Normal file
After Width: | Height: | Size: 104 B |
BIN
mods/pvp/gauges/textures/health_3.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_4.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_5.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_6.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_7.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_8.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
mods/pvp/gauges/textures/health_9.png
Normal file
After Width: | Height: | Size: 108 B |