68 lines
2.1 KiB
Lua
68 lines
2.1 KiB
Lua
local use = "Use Vending Machine"
|
|
local outOfOrder = "Out of order"
|
|
|
|
local function GetMachineData(prop)
|
|
local ok, data = pcall(function()
|
|
return exports['BigDaddy-VendingMachines']:GetMachineData(prop)
|
|
end)
|
|
if not ok or type(data) ~= 'table' then
|
|
return { isAlive = false, isVending = false }
|
|
end
|
|
return { isAlive = data.isAlive == true, isVending = data.isVending == true }
|
|
end
|
|
|
|
RegisterNetEvent('BigDaddy-VendingMachines:SetupOxTarget', function(models)
|
|
SetUpMachines(models)
|
|
end)
|
|
|
|
RegisterNetEvent('BigDaddy-VendingMachines:SetLocales', function(usetext, outofordertext)
|
|
use = usetext or use
|
|
outOfOrder = outofordertext or outOfOrder
|
|
end)
|
|
|
|
function SetUpMachines(models)
|
|
if not GetResourceState('ox_target'):find('start') then
|
|
CreateThread(function()
|
|
while not GetResourceState('ox_target'):find('start') do
|
|
Wait(250)
|
|
end
|
|
SetUpCarts(models)
|
|
end)
|
|
return
|
|
end
|
|
|
|
exports.ox_target:addModel(models, {
|
|
{
|
|
name = 'VendingMachines:Vending',
|
|
icon = 'fa-solid fa-coins',
|
|
label = use,
|
|
distance = 1.8,
|
|
canInteract = function(entity, distance, coords, name)
|
|
local x = GetMachineData(entity)
|
|
if x and x.isAlive == true and x.isVending == false then
|
|
return true
|
|
end
|
|
return false
|
|
end,
|
|
event = 'BigDaddy-VendingMachines:DoVendingEvent'
|
|
}
|
|
})
|
|
|
|
exports.ox_target:addModel(models, {
|
|
{
|
|
name = 'VendingMachines:OutOfOrder',
|
|
icon = 'fa-solid fa-xmark',
|
|
label = outOfOrder,
|
|
distance = 1.8,
|
|
canInteract = function(entity, distance, coords, name)
|
|
local x = GetMachineData(entity)
|
|
if x and x.isAlive == false then
|
|
return true
|
|
end
|
|
return false
|
|
end,
|
|
event = 'BigDaddy-VendingMachines:OutOfOrderEvent'
|
|
}
|
|
})
|
|
print("BigDaddy-VendingMachines: Ox Target options added.")
|
|
end |