11Menu = {}
2- Menu ._index = Menu
3- Menu .currentElements = {}
4-
5- function Menu :OpenMenu ()
6- ESX .OpenContext (" left" , self .currentElements , self .onUse , nil , false )
7- end
8-
9- function Menu :Close ()
10- self .currentElements = {}
11- ESX .CloseContext ()
12- end
132
143function Menu :CheckModel (character )
154 if not character .model and character .skin then
@@ -23,18 +12,6 @@ function Menu:CheckModel(character)
2312 end
2413end
2514
26- function Menu :AddCharacters ()
27- for _ , v in pairs (Multicharacter .Characters ) do
28- self :CheckModel (v )
29-
30- local label = (" %s %s" ):format (v .firstname , v .lastname )
31- self .currentElements [# self .currentElements + 1 ] = { title = label , icon = " fa-regular fa-user" , value = v .id }
32- end
33- if # self .currentElements - 1 < Multicharacter .slots then
34- self .currentElements [# self .currentElements + 1 ] = { title = TranslateCap (" create_char" ), icon = " fa-solid fa-plus" , value = (# self .currentElements + 1 ), new = true }
35- end
36- end
37-
3815local GetSlot = function ()
3916 for i = 1 , Multicharacter .slots do
4017 if not Multicharacter .Characters [i ] then
@@ -44,7 +21,6 @@ local GetSlot = function()
4421end
4522
4623function Menu :NewCharacter ()
47- self :Close ()
4824 local slot = GetSlot ()
4925
5026 TriggerServerEvent (" esx_multicharacter:CharacterChosen" , slot , true )
@@ -59,133 +35,43 @@ function Menu:NewCharacter()
5935end
6036
6137
62- function Menu :SelectCharacter ()
38+ function Menu :InitCharacter ()
6339 local Characters = Multicharacter .Characters
6440 local Character = next (Characters )
6541 self :CheckModel (Characters [Character ])
6642
6743 if not Multicharacter .spawned then
6844 Multicharacter :SetupCharacter (Character )
6945 end
70-
71- self .currentElements = {
72- {
73- title = TranslateCap (" select_char" ),
74- icon = " fa-solid fa-users" ,
75- description = TranslateCap (" select_char_description" ),
76- unselectable = true
46+ Wait (500 )
47+
48+ SendNUIMessage ({
49+ action = " ToggleMulticharacter" ,
50+ data = {
51+ show = true ,
52+ Characters = Characters ,
53+ CanDelete = Config .CanDelete ,
54+ AllowedSlot = Multicharacter .slots ,
55+ Locale = Locales [Config .Locale ].UI ,
7756 }
78- }
79-
80- self :AddCharacters ()
81- self .onUse = function (_ , SelectedCharacter )
82- if SelectedCharacter .new then
83- self :NewCharacter ()
84- else
85- if SelectedCharacter .value ~= Multicharacter .spawned then
86- Multicharacter :SetupCharacter (SelectedCharacter .value )
87- local playerPed = PlayerPedId ()
88- SetPedAoBlobRendering (playerPed , true )
89- ResetEntityAlpha (playerPed )
90- end
91- self :CharacterOptions ()
92- end
93- end
57+ })
9458
95- self : OpenMenu ( )
59+ SetNuiFocus ( true , true )
9660end
9761
98-
99- function Menu :CharacterOptions ()
100- local currentCharacter = Multicharacter .Characters [Multicharacter .spawned ]
101- local elements = {
102- {
103- title = TranslateCap (" character" , currentCharacter .firstname .. " " .. currentCharacter .lastname ),
104- icon = " fa-regular fa-user" ,
105- unselectable = true
106- },
107- {
108- title = TranslateCap (" return" ),
109- unselectable = false ,
110- icon = " fa-solid fa-arrow-left" ,
111- description = TranslateCap (" return_description" ),
112- action = " return"
113- },
114- }
115-
116- if not currentCharacter .disabled then
117- elements [3 ] = {
118- title = TranslateCap (" char_play" ),
119- description = TranslateCap (" char_play_description" ),
120- icon = " fa-solid fa-play" ,
121- action = " play" ,
122- }
123- else
124- elements [3 ] = {
125- title = TranslateCap (" char_disabled" ),
126- icon = " fa-solid fa-xmark" ,
127- description = TranslateCap (" char_disabled_description" )
128- }
129- end
130- if Config .CanDelete then
131- elements [4 ] = {
132- title = TranslateCap (" char_delete" ),
133- icon = " fa-solid fa-xmark" ,
134- description = TranslateCap (" char_delete_description" ),
135- action = " delete" ,
136- }
137- end
138-
139- self .currentElements = elements
140- self .onUse = function (_ , Action )
141- if Action .action == " play" then
142- Multicharacter :CloseUI ()
143- self :Close ()
144-
145- TriggerServerEvent (" esx_multicharacter:CharacterChosen" , Multicharacter .spawned , false )
146- elseif Action .action == " delete" then
147- self :ConfirmDeletion ()
148- elseif Action .action == " return" then
149- self :SelectCharacter ()
150- end
151- end
152-
153- self :OpenMenu ()
62+ function Menu :SelectCharacter (index )
63+ Multicharacter :SetupCharacter (index )
64+ local playerPed = PlayerPedId ()
65+ SetPedAoBlobRendering (playerPed , true )
66+ ResetEntityAlpha (playerPed )
15467end
15568
156- function Menu :ConfirmDeletion ()
157- self .currentElements = {
158- {
159- title = TranslateCap (" char_delete_confirmation" ),
160- icon = " fa-solid fa-users" ,
161- description = TranslateCap (" char_delete_confirmation_description" ),
162- unselectable = true
163- },
164- {
165- title = TranslateCap (" char_delete" ),
166- icon = " fa-solid fa-xmark" ,
167- description = TranslateCap (" char_delete_yes_description" ),
168- action = " delete" ,
169- },
170- {
171- title = TranslateCap (" return" ),
172- unselectable = false ,
173- icon = " fa-solid fa-arrow-left" ,
174- description = TranslateCap (" char_delete_no_description" ),
175- action = " return"
176- },
177- }
178-
179- self .onUse = function (_ , Action )
180- if Action .action == " delete" then
181- self :Close ()
182-
183- TriggerServerEvent (" esx_multicharacter:DeleteCharacter" , Multicharacter .spawned )
184- Multicharacter .spawned = false
185- elseif Action .action == " return" then
186- self :CharacterOptions ()
187- end
188- end
69+ function Menu :PlayCharacter ()
70+ Multicharacter :CloseUI ()
71+ TriggerServerEvent (" esx_multicharacter:CharacterChosen" , Multicharacter .spawned , false )
72+ end
18973
190- self :OpenMenu ()
74+ function Menu :DeleteCharacter ()
75+ TriggerServerEvent (" esx_multicharacter:DeleteCharacter" , Multicharacter .spawned )
76+ Multicharacter .spawned = false
19177end
0 commit comments