Skip to content

Commit 101c9a6

Browse files
committed
make numericui hud recreation safer
1 parent 8175ef4 commit 101c9a6

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

NumericUI/scripts/mods/NumericUI/NumericUI.lua

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,46 @@ mod:hook("UIHud", "init", function(func, self, elements, visibility_groups, para
5656
return func(self, elements, visibility_groups, params)
5757
end)
5858

59-
-- Taken from Fracticality
6059
local function recreate_hud()
6160
local ui_manager = Managers.ui
62-
if ui_manager then
63-
local hud = ui_manager._hud
64-
if hud then
65-
local player_manager = Managers.player
66-
local player = player_manager:local_player(1)
67-
local peer_id = player:peer_id()
68-
local local_player_id = player:local_player_id()
69-
local elements = hud._element_definitions
70-
local visibility_groups = hud._visibility_groups
7161

72-
hud:destroy()
73-
ui_manager:create_player_hud(peer_id, local_player_id, elements, visibility_groups)
74-
end
62+
if not ui_manager or not ui_manager._hud then
63+
-- UI manager or HUD is not ready, waiting...
64+
return false
65+
end
66+
local player_manager = Managers.player
67+
local player = player_manager:local_player(1)
68+
if not player then
69+
-- Local player is not ready, waiting...
70+
return false
7571
end
72+
local hud = ui_manager._hud
73+
local peer_id = player:peer_id()
74+
local local_player_id = player:local_player_id()
75+
local elements = hud._element_definitions
76+
local visibility_groups = hud._visibility_groups
77+
78+
hud:destroy()
79+
ui_manager:create_player_hud(peer_id, local_player_id, elements, visibility_groups)
80+
return true
7681
end
7782

78-
mod.on_all_mods_loaded = function()
79-
recreate_hud()
83+
local initialized = false
84+
mod.on_update = function()
85+
if initialized then
86+
return
87+
end
88+
initialized = recreate_hud()
89+
end
8090

91+
mod.on_all_mods_loaded = function()
92+
initialized = false
8193
if mod:get("show_medical_crate_radius") then
8294
local package_name = "content/levels/training_grounds/missions/mission_tg_basic_combat_01"
8395
Managers.package:load(package_name, "NumericUI")
8496
end
8597
end
8698

8799
mod.on_setting_changed = function()
88-
recreate_hud()
100+
initialized = false
89101
end

0 commit comments

Comments
 (0)