1
0
mirror of https://repo.or.cz/minetest_playereffects.git synced 2025-01-09 10:30:17 +01:00

Add setting use_hud, used to control player HUDs

This commit is contained in:
Wuzzy 2014-07-13 21:57:45 +02:00
parent 25fcabc095
commit bf50528228
2 changed files with 56 additions and 38 deletions

View File

@ -18,6 +18,9 @@ playereffects.inactive_effects = {}
-- Variable for counting the effect_id -- Variable for counting the effect_id
playereffects.last_effect_id = 0 playereffects.last_effect_id = 0
--[=[ Include settings ]=]
dofile(minetest.get_modpath("playereffects").."/settings.lua")
--[=[ Load inactive_effects and last_effect_id from playereffects.mt, if this file exists ]=] --[=[ Load inactive_effects and last_effect_id from playereffects.mt, if this file exists ]=]
do do
local filepath = minetest.get_worldpath().."/playereffects.mt" local filepath = minetest.get_worldpath().."/playereffects.mt"
@ -270,28 +273,32 @@ end)
--[=[ HUD ]=] --[=[ HUD ]=]
function playereffects.hud_update(player) function playereffects.hud_update(player)
local now = os.time() if(playereffects.use_hud == true) then
local effects = playereffects.get_player_effects(player:get_player_name()) local now = os.time()
for e=1,#effects do local effects = playereffects.get_player_effects(player:get_player_name())
local effect = effects[e] for e=1,#effects do
if(effect.hudids.text_id ~= nil) then local effect = effects[e]
local description = playereffects.effect_types[effect.effect_type_id].description if(effect.hudids.text_id ~= nil) then
local time_left = os.difftime(effect.start_time + effect.time_left, now) local description = playereffects.effect_types[effect.effect_type_id].description
player:hud_change(effect.hudids.text_id, "text", description .. " ("..tostring(time_left).." s)") local time_left = os.difftime(effect.start_time + effect.time_left, now)
player:hud_change(effect.hudids.text_id, "text", description .. " ("..tostring(time_left).." s)")
end
end end
end end
end end
function playereffects.hud_clear(player) function playereffects.hud_clear(player)
local playername = player:get_player_name() if(playereffects.use_hud == true) then
local effects = playereffects.get_player_effects(playername) local playername = player:get_player_name()
if(effects ~= nil) then local effects = playereffects.get_player_effects(playername)
for e=1,#effects do if(effects ~= nil) then
if(effects[e].hudids.text_id ~= nil) then for e=1,#effects do
player:hud_remove(effects[e].hudids.text_id) if(effects[e].hudids.text_id ~= nil) then
end player:hud_remove(effects[e].hudids.text_id)
if(effects[e].hudids.icon_id ~= nil) then end
player:hud_remove(effects[e].hudids.icon_id) if(effects[e].hudids.icon_id ~= nil) then
player:hud_remove(effects[e].hudids.icon_id)
end
end end
end end
end end
@ -299,29 +306,34 @@ end
function playereffects.hud_effect(effect_type_id, player, pos, time_left) function playereffects.hud_effect(effect_type_id, player, pos, time_left)
local text_id, icon_id local text_id, icon_id
text_id = player:hud_add({ if(playereffects.use_hud == true) then
hud_elem_type = "text", text_id = player:hud_add({
position = { x = 1, y = 0.3 }, hud_elem_type = "text",
name = "effect_"..effect_type_id,
text = playereffects.effect_types[effect_type_id].description .. " ("..tostring(time_left).." s)",
scale = { x = 170, y = 20},
alignment = { x = -1, y = 0 },
direction = 1,
number = 0xFFFFFF,
offset = { x = -5, y = pos*20 }
})
if(playereffects.effect_types[effect_type_id].icon ~= nil) then
icon_id = player:hud_add({
hud_elem_type = "image",
scale = { x = 1, y = 1 },
position = { x = 1, y = 0.3 }, position = { x = 1, y = 0.3 },
name = "effect_icon_"..effect_type_id, name = "effect_"..effect_type_id,
text = playereffects.effect_types[effect_type_id].icon, text = playereffects.effect_types[effect_type_id].description .. " ("..tostring(time_left).." s)",
alignment = { x = -1, y=0 }, scale = { x = 170, y = 20},
direction = 0, alignment = { x = -1, y = 0 },
offset = { x = -186, y = pos*20 }, direction = 1,
number = 0xFFFFFF,
offset = { x = -5, y = pos*20 }
}) })
end if(playereffects.effect_types[effect_type_id].icon ~= nil) then
icon_id = player:hud_add({
hud_elem_type = "image",
scale = { x = 1, y = 1 },
position = { x = 1, y = 0.3 },
name = "effect_icon_"..effect_type_id,
text = playereffects.effect_types[effect_type_id].icon,
alignment = { x = -1, y=0 },
direction = 0,
offset = { x = -186, y = pos*20 },
})
end
else
text_id = nil
icon_id = nil
end
return { text_id = text_id, icon_id = icon_id } return { text_id = text_id, icon_id = icon_id }
end end

6
settings.lua Normal file
View File

@ -0,0 +1,6 @@
--[[
Settings for Player Effects
]]
-- Wheather to use the HUD to expose the active effects to players (true or false)
playereffects.use_hud = true