Minor optimization

This commit is contained in:
Jean-Patrick Guerrero 2021-11-30 20:47:01 +01:00
parent b5bb00b90c
commit e4fdfa60bf
2 changed files with 11 additions and 4 deletions

View File

@ -656,6 +656,7 @@ local _ = {
str_to_pos = core.string_to_pos,
check_privs = core.check_player_privs,
get_player_by_name = core.get_player_by_name,
get_connected_players = core.get_connected_players,
-- Inventory
get_stack = get_stack,

View File

@ -1,4 +1,4 @@
IMPORT("get_player_by_name", "str_to_pos", "add_hud_waypoint")
IMPORT("get_connected_players", "str_to_pos", "add_hud_waypoint")
local function init_hud(player)
local name = player:get_player_name()
@ -90,9 +90,15 @@ local function show_hud(player, data)
end
core.register_globalstep(function()
for name, data in pairs(i3.data) do
if data.show_hud ~= nil then
local player = get_player_by_name(name)
local players = get_connected_players()
players[0] = #players
for i = 1, players[0] do
local player = players[i]
local name = player:get_player_name()
local data = i3.data[name]
if data and data.show_hud ~= nil then
show_hud(player, data)
end
end