mirror of
https://github.com/minetest-mods/gauges.git
synced 2025-01-03 14:50:21 +01:00
Improve code formatting
This commit is contained in:
parent
b9ed7d3908
commit
bb7d45a3d7
18
init.lua
18
init.lua
@ -16,19 +16,23 @@ function vector.sqdist(a, b)
|
|||||||
local dx = a.x - b.x
|
local dx = a.x - b.x
|
||||||
local dy = a.y - b.y
|
local dy = a.y - b.y
|
||||||
local dz = a.z - b.z
|
local dz = a.z - b.z
|
||||||
return dx*dx + dy*dy + dz*dz
|
return dx * dx + dy * dy + dz * dz
|
||||||
end
|
end
|
||||||
|
|
||||||
function hp_bar:on_step(dtime)
|
function hp_bar:on_step(dtime)
|
||||||
local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
|
local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
|
||||||
if wielder == nil or
|
|
||||||
vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3 then
|
if
|
||||||
|
wielder == nil or
|
||||||
|
vector.sqdist(wielder:get_pos(), self.object:get_pos()) > 3
|
||||||
|
then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local hp = wielder:get_hp()
|
local hp = wielder:get_hp()
|
||||||
local breath = wielder:get_breath()
|
local breath = wielder:get_breath()
|
||||||
|
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures = {
|
textures = {
|
||||||
"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png",
|
"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png",
|
||||||
@ -42,6 +46,7 @@ local function add_HP_gauge(name)
|
|||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
||||||
|
|
||||||
if ent ~= nil then
|
if ent ~= nil then
|
||||||
ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
|
ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
ent = ent:get_luaentity()
|
ent = ent:get_luaentity()
|
||||||
@ -49,9 +54,10 @@ local function add_HP_gauge(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If health_bars not defined or set to true
|
if
|
||||||
if minetest.setting_getbool("health_bars") ~= false and
|
minetest.setting_getbool("health_bars") ~= false and
|
||||||
minetest.setting_getbool("enable_damage") then
|
minetest.setting_getbool("enable_damage")
|
||||||
|
then
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
minetest.after(1, add_HP_gauge, player:get_player_name())
|
minetest.after(1, add_HP_gauge, player:get_player_name())
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user