From e4fdfa60bffdb440230d99a47ccd450859d9bda3 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Tue, 30 Nov 2021 20:47:01 +0100 Subject: [PATCH] Minor optimization --- src/common.lua | 1 + src/hud.lua | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common.lua b/src/common.lua index 4e02f04..43e5262 100644 --- a/src/common.lua +++ b/src/common.lua @@ -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, diff --git a/src/hud.lua b/src/hud.lua index da6441d..90f191f 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -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