208 lines
7.1 KiB
Lua
208 lines
7.1 KiB
Lua
if Config.JobCheck.ESX.Enabled or Config.PlaceGeneratorCommand.Permissions.ESX.Enabled then
|
|
ESX = exports["es_extended"]:getSharedObject()
|
|
end
|
|
|
|
if Config.JobCheck.vRP.Enabled or Config.PlaceGeneratorCommand.Permissions.vRP.Enabled then
|
|
local Tunnel = module("vrp", "lib/Tunnel")
|
|
local Proxy = module("vrp", "lib/Proxy")
|
|
vRP = Proxy.getInterface("vRP")
|
|
vRPclient = Tunnel.getInterface("vRP","vRP")
|
|
end
|
|
|
|
if Config.JobCheck.QBCore.Enabled or Config.PlaceGeneratorCommand.Inventory.qbCore or Config.PlaceGeneratorCommand.Permissions.QBCore.Enabled then
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
end
|
|
|
|
local itemEnabled = Config.PlaceGeneratorCommand.Inventory.qbCore or Config.PlaceGeneratorCommand.Inventory.vRP or Config.PlaceGeneratorCommand.Inventory.ESX or Config.PlaceGeneratorCommand.Inventory.coreInventory or Config.PlaceGeneratorCommand.Inventory.oxInventory
|
|
|
|
usedGenerator = {}
|
|
|
|
if itemEnabled then
|
|
RegisterNetEvent("Server:GeneratorWithItem", function(src)
|
|
if HandleInventoryItems(src, Config.PlaceGeneratorCommand.Inventory.ItemName, false) then
|
|
usedGenerator[src] = true
|
|
TriggerClientEvent("SupplyLine:Client:EquipPortableGenerator", src)
|
|
else
|
|
TriggerClientEvent("SupplyLine:Client:showNotification", src, Config.Translations.noItem)
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterNetEvent("Server:ReturnGenerator", function()
|
|
local source = source
|
|
if usedGenerator[source] ~= nil and usedGenerator[source] ~= false then
|
|
HandleInventoryItems(source, Config.PlaceGeneratorCommand.Inventory.ItemName, true)
|
|
usedGenerator[source] = nil
|
|
end
|
|
end)
|
|
|
|
if Config.PlaceGeneratorCommand.Inventory.qbCore then
|
|
CreateThread(function()
|
|
QBCore.Functions.CreateUseableItem(Config.PlaceGeneratorCommand.Inventory.ItemName, function(source, item)
|
|
TriggerEvent("Server:GeneratorWithItem", source)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
if Config.PlaceGeneratorCommand.Inventory.ESX then
|
|
CreateThread(function()
|
|
ESX.RegisterUsableItem(Config.PlaceGeneratorCommand.Inventory.ItemName, function(playerId)
|
|
TriggerEvent("Server:GeneratorWithItem", playerId)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
if Config.PlaceGeneratorCommand.Inventory.oxInventory then
|
|
exports('OxUseGenerator', function(event, item, inventory)
|
|
if event == 'usingItem' then
|
|
usedGenerator[inventory.player.source] = true
|
|
TriggerClientEvent("SupplyLine:Client:EquipPortableGenerator", inventory.player.source)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function UserHasPermission(source, location)
|
|
|
|
if not location.EnablePermissions then
|
|
return true
|
|
end
|
|
|
|
if location.AcePermissions.Enabled then
|
|
if location.AcePermissions.Permission ~= nil then
|
|
if IsPlayerAceAllowed(source, location.AcePermissions.Permission) then
|
|
return true
|
|
end
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
|
|
-- ESX Permissions
|
|
if location.ESX.Enabled then
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
if location.ESX.CheckJob.Enabled then
|
|
for k, v in pairs(location.ESX.CheckJob.Jobs) do
|
|
if xPlayer.job.name == v then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- vRP Permission
|
|
if location.vRP.Enabled then
|
|
if location.vRP.CheckPermission.Enabled then
|
|
for k, v in pairs(location.vRP.CheckPermission.Permissions) do
|
|
if vRP.hasPermission({vRP.getUserId({source}),v}) then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
|
|
if location.vRP.CheckGroup.Enabled then
|
|
for k, v in pairs(location.vRP.CheckGroup.Groups) do
|
|
if vRP.hasGroup({vRP.getUserId({source}),v}) then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- QBCore Permission
|
|
if location.QBCore.Enabled then
|
|
local player = QBCore.Functions.GetPlayer(source)
|
|
if location.QBCore.CheckJob.Enabled then
|
|
for k, v in pairs(location.QBCore.CheckJob.Jobs) do
|
|
if player.PlayerData.job.name == v then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
if location.QBCore.CheckPermission.Enabled then
|
|
for k, v in pairs(location.QBCore.CheckPermission.permissions) do
|
|
if QBCore.Functions.HasPermission(source, v) then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
if location.QBX.Enabled then
|
|
local player = exports.qbx_core:GetPlayer(source)
|
|
if location.QBX.CheckJob.Enabled then
|
|
for k, v in pairs(location.QBX.CheckJob.Jobs) do
|
|
if player.PlayerData.job.name == v then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function HandleInventoryItems(source, itemName, give)
|
|
if Config.PlaceGeneratorCommand.Inventory.vRP then
|
|
local userID = vRP.getUserId({source})
|
|
if give then
|
|
vRP.giveInventoryItem({userId, itemName, 1, false})
|
|
else
|
|
if vRP.tryGetInventoryItem({userID, itemName, 1, false}) then
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
elseif Config.PlaceGeneratorCommand.Inventory.qbCore then
|
|
if give then
|
|
exports['qb-inventory']:AddItem(source, itemName, 1, false, false, GetCurrentResourceName())
|
|
else
|
|
local successful = exports['qb-inventory']:RemoveItem(source, itemName, 1, false, GetCurrentResourceName())
|
|
|
|
return successful
|
|
end
|
|
elseif Config.PlaceGeneratorCommand.Inventory.ESX then
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
if give then
|
|
xPlayer.addInventoryItem(itemName, 1)
|
|
else
|
|
local returnedItem = xPlayer.getInventoryItem(itemName)
|
|
|
|
if returnedItem.canRemove then
|
|
xPlayer.removeInventoryItem(itemName, 1)
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
elseif Config.PlaceGeneratorCommand.Inventory.oxInventory then
|
|
if give then
|
|
exports.ox_inventory:AddItem(source, itemName, 1)
|
|
else
|
|
local successful = exports.ox_inventory:RemoveItem(source, itemName, 1)
|
|
|
|
return successful
|
|
end
|
|
elseif Config.PlaceGeneratorCommand.Inventory.quasarInventory then
|
|
if give then
|
|
exports['qs-inventory']:AddItem(source, itemName, 1)
|
|
else
|
|
local quantity = exports['qs-inventory']:GetItemTotalAmount(source, itemName)
|
|
if quantity > 0 then
|
|
exports['qs-inventory']:RemoveItem(source, itemName, 1)
|
|
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
elseif Config.PlaceGeneratorCommand.Inventory.coreInventory then
|
|
if give then
|
|
exports.core_Inventory:addItem(source, itemName, 1)
|
|
else
|
|
local successful = exports.core_Inventory:removeItem(source, itemName, 1)
|
|
|
|
return successful
|
|
end
|
|
end
|
|
end |