local isMenuOpen = false local lastInteraction = 0 -- Inicializacija ox_target za modele avtomatov Citizen.CreateThread(function() local models = {} for model, _ in pairs(Config.VendingProps) do table.insert(models, model) end exports.ox_target:addModel(models, { { name = 'vending_machine', icon = 'fas fa-shopping-basket', label = 'Uporabi avtomat', onSelect = function(data) OpenVendingMenu(data.entity) end } }) end) -- Funkcija za odpiranje NUI vmesnika function OpenVendingMenu(entity) local model = GetEntityModel(entity) local vData = Config.VendingProps[model] if not vData then return end local items = Config.Items[vData.type] isMenuOpen = true SetNuiFocus(true, true) SendNUIMessage({ action = "open", items = items, label = vData.label, imgPath = Config.InventoryImagePath }) end -- Callback za nakup artikla RegisterNUICallback('buyItem', function(data, cb) -- Preverjanje cooldowna (da se prepreči spam) if GetGameTimer() - lastInteraction < Config.Settings.Cooldown then exports['prism_uipack']:Notify({ description = 'Avtomat še vedno procesira prejšnjo zahtevo...', type = 'error', position = 'top-center', duration = 3000 }) return cb('ok') end lastInteraction = GetGameTimer() -- Progress bar ob izdajanju artikla local success = exports['prism_uipack']:ProgressBar({ label = 'Izdajanje artikla...', duration = 2000, position = 'bottom-center', canCancel = true, anim = { dict = 'mp_common', clip = 'givetake2_a' }, disable = { move = true, car = true, mouse = false } }) if success then -- Pošiljanje zahteve na strežnik TriggerServerEvent('vending:purchase', data.item, data.price) else -- Obvestilo ob prekinitvi exports['prism_uipack']:Notify({ description = 'Nakup je bil preklican.', type = 'warning', position = 'top-center', duration = 3000 }) end cb('ok') end) -- Callback za zapiranje vmesnika RegisterNUICallback('close', function(_, cb) isMenuOpen = false SetNuiFocus(false, false) cb('ok') end) -- Poskrbi, da se NUI fokus sprosti, če se skripta ugasne (restart) AddEventHandler('onResourceStop', function(resourceName) if (GetCurrentResourceName() ~= resourceName) then return end if isMenuOpen then SetNuiFocus(false, false) end end)