1+ local Keys = {
2+ [" ESC" ] = 322 , [" F1" ] = 288 , [" F2" ] = 289 , [" F3" ] = 170 , [" F5" ] = 166 , [" F6" ] = 167 , [" F7" ] = 168 , [" F8" ] = 169 , [" F9" ] = 56 , [" F10" ] = 57 ,
3+ [" ~" ] = 243 , [" 1" ] = 157 , [" 2" ] = 158 , [" 3" ] = 160 , [" 4" ] = 164 , [" 5" ] = 165 , [" 6" ] = 159 , [" 7" ] = 161 , [" 8" ] = 162 , [" 9" ] = 163 , [" -" ] = 84 , [" =" ] = 83 , [" BACKSPACE" ] = 177 ,
4+ [" TAB" ] = 37 , [" Q" ] = 44 , [" W" ] = 32 , [" E" ] = 38 , [" R" ] = 45 , [" T" ] = 245 , [" Y" ] = 246 , [" U" ] = 303 , [" P" ] = 199 , [" [" ] = 39 , [" ]" ] = 40 , [" ENTER" ] = 18 ,
5+ [" CAPS" ] = 137 , [" A" ] = 34 , [" S" ] = 8 , [" D" ] = 9 , [" F" ] = 23 , [" G" ] = 47 , [" H" ] = 74 , [" K" ] = 311 , [" L" ] = 182 ,
6+ [" LEFTSHIFT" ] = 21 , [" Z" ] = 20 , [" X" ] = 73 , [" C" ] = 26 , [" V" ] = 0 , [" B" ] = 29 , [" N" ] = 249 , [" M" ] = 244 , [" ," ] = 82 , [" ." ] = 81 ,
7+ [" LEFTCTRL" ] = 36 , [" LEFTALT" ] = 19 , [" SPACE" ] = 22 , [" RIGHTCTRL" ] = 70 ,
8+ [" HOME" ] = 213 , [" PAGEUP" ] = 10 , [" PAGEDOWN" ] = 11 , [" DELETE" ] = 178 ,
9+ [" LEFT" ] = 174 , [" RIGHT" ] = 175 , [" TOP" ] = 27 , [" DOWN" ] = 173 ,
10+ [" NENTER" ] = 201 , [" N4" ] = 108 , [" N5" ] = 60 , [" N6" ] = 107 , [" N+" ] = 96 , [" N-" ] = 97 , [" N7" ] = 117 , [" N8" ] = 61 , [" N9" ] = 118
11+ }
12+
13+ ESX = nil
14+ local HasAlreadyEnteredMarker = false
15+ local LastZone = nil
16+ local CurrentAction = nil
17+ local CurrentActionMsg = ' '
18+ local CurrentActionData = {}
19+ local isDead = false
20+
21+ Citizen .CreateThread (function ()
22+ while ESX == nil do
23+ TriggerEvent (' esx:getSharedObject' , function (obj ) ESX = obj end )
24+ Citizen .Wait (0 )
25+ end
26+ end )
27+
28+ function OpenAccessoryMenu ()
29+ ESX .UI .Menu .Open (' default' , GetCurrentResourceName (), ' set_unset_accessory' ,
30+ {
31+ title = _U (' set_unset' ),
32+ align = ' top-left' ,
33+ elements = {
34+ {label = _U (' helmet' ), value = ' Helmet' },
35+ {label = _U (' ears' ), value = ' Ears' },
36+ {label = _U (' mask' ), value = ' Mask' },
37+ {label = _U (' glasses' ), value = ' Glasses' }
38+ }
39+ }, function (data , menu )
40+ menu .close ()
41+ SetUnsetAccessory (data .current .value )
42+
43+ end , function (data , menu )
44+ menu .close ()
45+ end )
46+ end
47+
48+ function SetUnsetAccessory (accessory )
49+ ESX .TriggerServerCallback (' esx_accessories:get' , function (hasAccessory , accessorySkin )
50+ local _accessory = string.lower (accessory )
51+
52+ if hasAccessory then
53+ TriggerEvent (' skinchanger:getSkin' , function (skin )
54+ local mAccessory = - 1
55+ local mColor = 0
56+
57+ if _accessory == " mask" then
58+ mAccessory = 0
59+ end
60+
61+ if skin [_accessory .. ' _1' ] == mAccessory then
62+ mAccessory = accessorySkin [_accessory .. ' _1' ]
63+ mColor = accessorySkin [_accessory .. ' _2' ]
64+ end
65+
66+ local accessorySkin = {}
67+ accessorySkin [_accessory .. ' _1' ] = mAccessory
68+ accessorySkin [_accessory .. ' _2' ] = mColor
69+ TriggerEvent (' skinchanger:loadClothes' , skin , accessorySkin )
70+ end )
71+ else
72+ ESX .ShowNotification (_U (' no_' .. _accessory ))
73+ end
74+
75+ end , accessory )
76+ end
77+
78+ function OpenShopMenu (accessory )
79+ local _accessory = string.lower (accessory )
80+ local restrict = {}
81+
82+ restrict = { _accessory .. ' _1' , _accessory .. ' _2' }
83+
84+ TriggerEvent (' esx_skin:openRestrictedMenu' , function (data , menu )
85+
86+ menu .close ()
87+
88+ ESX .UI .Menu .Open (' default' , GetCurrentResourceName (), ' shop_confirm' ,
89+ {
90+ title = _U (' valid_purchase' ),
91+ align = ' top-left' ,
92+ elements = {
93+ {label = _U (' no' ), value = ' no' },
94+ {label = _U (' yes' , ESX .Math .GroupDigits (Config .Price )), value = ' yes' }
95+ }
96+ }, function (data , menu )
97+ menu .close ()
98+ if data .current .value == ' yes' then
99+ ESX .TriggerServerCallback (' esx_accessories:checkMoney' , function (hasEnoughMoney )
100+ if hasEnoughMoney then
101+ TriggerServerEvent (' esx_accessories:pay' )
102+ TriggerEvent (' skinchanger:getSkin' , function (skin )
103+ TriggerServerEvent (' esx_accessories:save' , skin , accessory )
104+ end )
105+ else
106+ TriggerEvent (' esx_skin:getLastSkin' , function (skin )
107+ TriggerEvent (' skinchanger:loadSkin' , skin )
108+ end )
109+ ESX .ShowNotification (_U (' not_enough_money' ))
110+ end
111+ end )
112+ end
113+
114+ if data .current .value == ' no' then
115+ local player = PlayerPedId ()
116+ TriggerEvent (' esx_skin:getLastSkin' , function (skin )
117+ TriggerEvent (' skinchanger:loadSkin' , skin )
118+ end )
119+ if accessory == " Ears" then
120+ ClearPedProp (player , 2 )
121+ elseif accessory == " Mask" then
122+ SetPedComponentVariation (player , 1 , 0 ,0 , 2 )
123+ elseif accessory == " Helmet" then
124+ ClearPedProp (player , 0 )
125+ elseif accessory == " Glasses" then
126+ SetPedPropIndex (player , 1 , - 1 , 0 , 0 )
127+ end
128+ end
129+ CurrentAction = ' shop_menu'
130+ CurrentActionMsg = _U (' press_access' )
131+ CurrentActionData = {}
132+ end , function (data , menu )
133+ menu .close ()
134+ CurrentAction = ' shop_menu'
135+ CurrentActionMsg = _U (' press_access' )
136+ CurrentActionData = {}
137+
138+ end )
139+ end , function (data , menu )
140+ menu .close ()
141+ CurrentAction = ' shop_menu'
142+ CurrentActionMsg = _U (' press_access' )
143+ CurrentActionData = {}
144+ end , restrict )
145+ end
146+
147+ AddEventHandler (' playerSpawned' , function ()
148+ isDead = false
149+ end )
150+
151+ AddEventHandler (' esx:onPlayerDeath' , function ()
152+ isDead = true
153+ end )
154+
155+ AddEventHandler (' esx_accessories:hasEnteredMarker' , function (zone )
156+ CurrentAction = ' shop_menu'
157+ CurrentActionMsg = _U (' press_access' )
158+ CurrentActionData = { accessory = zone }
159+ end )
160+
161+ AddEventHandler (' esx_accessories:hasExitedMarker' , function (zone )
162+ ESX .UI .Menu .CloseAll ()
163+ CurrentAction = nil
164+ end )
165+
166+ -- Create Blips --
167+ Citizen .CreateThread (function ()
168+ for k ,v in pairs (Config .ShopsBlips ) do
169+ if v .Pos ~= nil then
170+ for i = 1 , # v .Pos , 1 do
171+ local blip = AddBlipForCoord (v .Pos [i ].x , v .Pos [i ].y , v .Pos [i ].z )
172+
173+ SetBlipSprite (blip , v .Blip .sprite )
174+ SetBlipDisplay (blip , 4 )
175+ SetBlipScale (blip , 1.0 )
176+ SetBlipColour (blip , v .Blip .color )
177+ SetBlipAsShortRange (blip , true )
178+
179+ BeginTextCommandSetBlipName (" STRING" )
180+ AddTextComponentString (_U (' shop' , _U (string.lower (k ))))
181+ EndTextCommandSetBlipName (blip )
182+ end
183+ end
184+ end
185+ end )
186+
187+ -- Display markers
188+ Citizen .CreateThread (function ()
189+ while true do
190+ Citizen .Wait (0 )
191+ local coords = GetEntityCoords (PlayerPedId ())
192+ for k ,v in pairs (Config .Zones ) do
193+ for i = 1 , # v .Pos , 1 do
194+ if (Config .Type ~= - 1 and GetDistanceBetweenCoords (coords , v .Pos [i ].x , v .Pos [i ].y , v .Pos [i ].z , true ) < Config .DrawDistance ) then
195+ DrawMarker (Config .Type , v .Pos [i ].x , v .Pos [i ].y , v .Pos [i ].z , 0.0 , 0.0 , 0.0 , 0 , 0.0 , 0.0 , Config .Size .x , Config .Size .y , Config .Size .z , Config .Color .r , Config .Color .g , Config .Color .b , 100 , false , true , 2 , false , false , false , false )
196+ end
197+ end
198+ end
199+ end
200+ end )
201+
202+
203+ Citizen .CreateThread (function ()
204+ while true do
205+ Citizen .Wait (200 )
206+
207+ local coords = GetEntityCoords (PlayerPedId ())
208+ local isInMarker = false
209+ local currentZone = nil
210+ for k ,v in pairs (Config .Zones ) do
211+ for i = 1 , # v .Pos , 1 do
212+ if GetDistanceBetweenCoords (coords , v .Pos [i ].x , v .Pos [i ].y , v .Pos [i ].z , true ) < Config .Size .x then
213+ isInMarker = true
214+ currentZone = k
215+ end
216+ end
217+ end
218+
219+ if (isInMarker and not HasAlreadyEnteredMarker ) or (isInMarker and LastZone ~= currentZone ) then
220+ HasAlreadyEnteredMarker = true
221+ LastZone = currentZone
222+ TriggerEvent (' esx_accessories:hasEnteredMarker' , currentZone )
223+ end
224+
225+ if not isInMarker and HasAlreadyEnteredMarker then
226+ HasAlreadyEnteredMarker = false
227+ TriggerEvent (' esx_accessories:hasExitedMarker' , LastZone )
228+ end
229+
230+ end
231+ end )
232+
233+ -- Key controls
234+ Citizen .CreateThread (function ()
235+ while true do
236+ Citizen .Wait (0 )
237+
238+ if CurrentAction ~= nil then
239+ ESX .ShowHelpNotification (CurrentActionMsg )
240+
241+ if IsControlJustReleased (0 , Keys [' E' ]) and CurrentActionData .accessory then
242+ OpenShopMenu (CurrentActionData .accessory )
243+ CurrentAction = nil
244+ end
245+ elseif CurrentAction == nil and not Config .EnableControls then
246+ Citizen .Wait (500 )
247+ end
248+
249+ if Config .EnableControls then
250+ if IsControlJustReleased (0 , Keys [' K' ]) and GetLastInputMethod (2 ) and not isDead then
251+ OpenAccessoryMenu ()
252+ end
253+ end
254+
255+ end
256+ end )
0 commit comments