mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-23 06:32:25 +01:00
emeralds in HUD
This commit is contained in:
parent
cfe0d6be8f
commit
ffc7fa5b1f
80
hud.lua
Normal file
80
hud.lua
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
|
||||||
|
-- Copyright (C) 2021, 2024 Sandro del Toro
|
||||||
|
|
||||||
|
-- This file is part of Emeraldbank Minetest Mod.
|
||||||
|
|
||||||
|
-- Emeraldbank is free software: you can redistribute it and/or modify
|
||||||
|
-- it under the terms of the GNU Affero General Public License as
|
||||||
|
-- published by the Free Software Foundation, either version 3 of the
|
||||||
|
-- License, or (at your option) any later version.
|
||||||
|
|
||||||
|
-- Emeraldbank is distributed in the hope that it will be useful,
|
||||||
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
-- GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
-- You should have received a copy of the GNU Affero General Public License
|
||||||
|
-- along with Emeraldbank. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
local modname = core.get_current_modname()
|
||||||
|
local S = core.get_translator(modname)
|
||||||
|
|
||||||
|
local HUD_TIME = tonumber(core.settings:get("emeraldbank.hud_time")) or 3
|
||||||
|
|
||||||
|
--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==
|
||||||
|
|
||||||
|
local ad_huds = {}
|
||||||
|
|
||||||
|
local function print_emeralds()
|
||||||
|
for _, player in ipairs(core.get_connected_players()) do
|
||||||
|
local nm = player:get_player_name()
|
||||||
|
local emeralds = emeraldbank.get_emeralds(nm)
|
||||||
|
|
||||||
|
-- Already have a HUD, get rid of it
|
||||||
|
if ad_huds[nm] and ad_huds[nm].header and ad_huds[nm].sub then
|
||||||
|
player:hud_remove(ad_huds[nm].header)
|
||||||
|
player:hud_remove(ad_huds[nm].sub)
|
||||||
|
end
|
||||||
|
|
||||||
|
ad_huds[nm] = {}
|
||||||
|
|
||||||
|
if not emeralds then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- build tables
|
||||||
|
local hud_table_header = {
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = {x = 0.5, y = 0.5},
|
||||||
|
offset = {x = -300, y = 450},
|
||||||
|
text = "mcl_core_emerald.png",
|
||||||
|
alignment = {x = -1, y = 1},
|
||||||
|
scale = { x = 3, y = 3},
|
||||||
|
}
|
||||||
|
|
||||||
|
local hud_table_sub = table.copy(hud_table_header)
|
||||||
|
hud_table_sub.hud_elem_type = "text"
|
||||||
|
hud_table_sub.offset = {
|
||||||
|
x = hud_table_header.offset.x+30,
|
||||||
|
y = hud_table_header.offset.y+20
|
||||||
|
}
|
||||||
|
hud_table_sub.scale = {x=300, y=30}
|
||||||
|
hud_table_sub.text = "x "..emeralds
|
||||||
|
hud_table_sub.number = 0xFFFF00
|
||||||
|
|
||||||
|
-- show tables
|
||||||
|
ad_huds[nm].header = player:hud_add(hud_table_header)
|
||||||
|
ad_huds[nm].sub = player:hud_add(hud_table_sub)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local ad_tick = 0.0
|
||||||
|
core.register_globalstep(function(dt)
|
||||||
|
ad_tick = ad_tick + dt
|
||||||
|
if ad_tick >= HUD_TIME then
|
||||||
|
print_emeralds()
|
||||||
|
ad_tick = 0.0
|
||||||
|
end
|
||||||
|
end)
|
3
init.lua
3
init.lua
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
-- Copyright (C) 2021, 2023 Ale
|
-- Copyright (C) 2021, 2024 Sandro del Toro
|
||||||
|
|
||||||
-- This file is part of Emeraldbank Minetest Mod.
|
-- This file is part of Emeraldbank Minetest Mod.
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ dofile(modpath .. "/bank.lua")
|
|||||||
dofile(modpath .. "/shop.lua")
|
dofile(modpath .. "/shop.lua")
|
||||||
dofile(modpath .. "/fancyshop.lua") -- file adapted from fancy_vend mod.
|
dofile(modpath .. "/fancyshop.lua") -- file adapted from fancy_vend mod.
|
||||||
dofile(modpath .. "/commands.lua")
|
dofile(modpath .. "/commands.lua")
|
||||||
|
dofile(modpath .. "/hud.lua")
|
||||||
|
|
||||||
if income_enabled then
|
if income_enabled then
|
||||||
dofile(modpath .. "/income.lua")
|
dofile(modpath .. "/income.lua")
|
||||||
|
@ -19,6 +19,9 @@ emeraldbank.income_count (number of emeralds) int 1
|
|||||||
# Length of time (in seconds) between checking if a player should get income
|
# Length of time (in seconds) between checking if a player should get income
|
||||||
emeraldbank.income_period (time between income) int 1800
|
emeraldbank.income_period (time between income) int 1800
|
||||||
|
|
||||||
|
# Length of time (in seconds) between updating emeralds player HUD
|
||||||
|
emeraldbank.hud_time (HUD update time) int 3
|
||||||
|
|
||||||
[Shops]
|
[Shops]
|
||||||
|
|
||||||
# If true shop can be crafted
|
# If true shop can be crafted
|
||||||
|
Loading…
Reference in New Issue
Block a user