-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
42 lines (36 loc) · 1.66 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
lib.locale()
local QBCore = exports['qb-core']:GetCoreObject()
local ox_inventory = exports.ox_inventory
local MenuMachines = {}
ItemsName = {}
for item, data in pairs(ox_inventory:Items()) do
ItemsName[item] = data.label
end
for typeMachine, dataMachine in pairs(Config.Machines) do
local clientEventTarget = 'neko_vendingmachine:open:'..typeMachine
-- === Generate qb-targets
exports['qb-target']:AddTargetModel(dataMachine.props, {
options = { { typeMachine = 'client', event = clientEventTarget, icon = dataMachine.icon, label = dataMachine.label } },
distance = Config.QbTargetDistance
})
-- === Create menu base
MenuMachines[typeMachine] = { id = 'vending_machine:'..typeMachine, title = dataMachine.label, options = {} }
-- === Add items on menu
for itemId, itemCod in pairs(dataMachine.items) do
MenuMachines[typeMachine].options[itemCod] = {
title = ItemsName[itemCod],
description = locale('option_description', ItemsName[itemCod], dataMachine.price),
icon = dataMachine.icon,
serverEvent = 'neko_vendingmachine:server:sellitem',
args = { item = itemCod, type = typeMachine, label = ItemsName[itemCod] }
}
end
lib.registerContext(MenuMachines[typeMachine])
AddEventHandler(clientEventTarget, function()
QBCore.Functions.GetPlayerData(function(Player)
if not Player.metadata["isdead"] and not Player.metadata["inlaststand"] and not Player.metadata["ishandcuffed"] and not IsPauseMenuActive() then
lib.showContext(MenuMachines[typeMachine].id)
end
end)
end)
end