@@ -56,34 +56,46 @@ mod:hook("UIHud", "init", function(func, self, elements, visibility_groups, para
56
56
return func (self , elements , visibility_groups , params )
57
57
end )
58
58
59
- -- Taken from Fracticality
60
59
local function recreate_hud ()
61
60
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
71
61
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
75
71
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
76
81
end
77
82
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
80
90
91
+ mod .on_all_mods_loaded = function ()
92
+ initialized = false
81
93
if mod :get (" show_medical_crate_radius" ) then
82
94
local package_name = " content/levels/training_grounds/missions/mission_tg_basic_combat_01"
83
95
Managers .package :load (package_name , " NumericUI" )
84
96
end
85
97
end
86
98
87
99
mod .on_setting_changed = function ()
88
- recreate_hud ()
100
+ initialized = false
89
101
end
0 commit comments