mirror of
https://repo.or.cz/minetest_playereffects.git
synced 2025-01-09 18:40:18 +01:00
Add setting use_hud, used to control player HUDs
This commit is contained in:
parent
25fcabc095
commit
bf50528228
12
init.lua
12
init.lua
@ -18,6 +18,9 @@ playereffects.inactive_effects = {}
|
||||
-- Variable for counting the effect_id
|
||||
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 ]=]
|
||||
do
|
||||
local filepath = minetest.get_worldpath().."/playereffects.mt"
|
||||
@ -270,6 +273,7 @@ end)
|
||||
|
||||
--[=[ HUD ]=]
|
||||
function playereffects.hud_update(player)
|
||||
if(playereffects.use_hud == true) then
|
||||
local now = os.time()
|
||||
local effects = playereffects.get_player_effects(player:get_player_name())
|
||||
for e=1,#effects do
|
||||
@ -280,9 +284,11 @@ function playereffects.hud_update(player)
|
||||
player:hud_change(effect.hudids.text_id, "text", description .. " ("..tostring(time_left).." s)")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.hud_clear(player)
|
||||
if(playereffects.use_hud == true) then
|
||||
local playername = player:get_player_name()
|
||||
local effects = playereffects.get_player_effects(playername)
|
||||
if(effects ~= nil) then
|
||||
@ -295,10 +301,12 @@ function playereffects.hud_clear(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function playereffects.hud_effect(effect_type_id, player, pos, time_left)
|
||||
local text_id, icon_id
|
||||
if(playereffects.use_hud == true) then
|
||||
text_id = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x = 1, y = 0.3 },
|
||||
@ -322,6 +330,10 @@ function playereffects.hud_effect(effect_type_id, player, pos, time_left)
|
||||
offset = { x = -186, y = pos*20 },
|
||||
})
|
||||
end
|
||||
else
|
||||
text_id = nil
|
||||
icon_id = nil
|
||||
end
|
||||
return { text_id = text_id, icon_id = icon_id }
|
||||
end
|
||||
|
||||
|
6
settings.lua
Normal file
6
settings.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user