mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Cleanup, added available triggers to readme
This commit is contained in:
+7
-45
@@ -3,107 +3,81 @@ ESX = nil
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
function AddLicense(target, type, cb)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)',
|
||||
{
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
},
|
||||
function(rowsChanged)
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function RemoveLicense(target, type, cb)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.execute(
|
||||
'DELETE FROM user_licenses WHERE type = @type AND owner = @owner',
|
||||
{
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
},
|
||||
function(rowsChanged)
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function GetLicense(type, cb)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses WHERE type = @type',
|
||||
{
|
||||
['@type'] = type
|
||||
},
|
||||
function(result)
|
||||
|
||||
}, function(result)
|
||||
local data = {
|
||||
type = type,
|
||||
label = result[1].label
|
||||
}
|
||||
|
||||
cb(data)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function GetLicenses(target, cb)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM user_licenses WHERE owner = @owner',
|
||||
{
|
||||
['@owner'] = xPlayer.identifier
|
||||
},
|
||||
function(result)
|
||||
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
local asyncTasks = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
local scope = function(type)
|
||||
|
||||
table.insert(asyncTasks, function(cb)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses WHERE type = @type',
|
||||
{
|
||||
['@type'] = type
|
||||
},
|
||||
function(result2)
|
||||
}, function(result2)
|
||||
|
||||
table.insert(licenses, {
|
||||
type = type,
|
||||
label = result2[1].label
|
||||
})
|
||||
|
||||
cb()
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
scope(result[i].type)
|
||||
|
||||
end
|
||||
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
@@ -112,21 +86,16 @@ function GetLicenses(target, cb)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function CheckLicense(target, type, cb)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT COUNT(*) as count FROM user_licenses WHERE type = @type AND owner = @owner',
|
||||
{
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
},
|
||||
function(result)
|
||||
|
||||
}, function(result)
|
||||
if tonumber(result[1].count) > 0 then
|
||||
cb(true)
|
||||
else
|
||||
@@ -135,18 +104,14 @@ function CheckLicense(target, type, cb)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function GetLicensesList(cb)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses',
|
||||
{
|
||||
['@type'] = type
|
||||
},
|
||||
function(result)
|
||||
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
@@ -155,12 +120,9 @@ function GetLicensesList(cb)
|
||||
label = result[i].label
|
||||
})
|
||||
end
|
||||
|
||||
cb(licenses)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx_license:addLicense')
|
||||
|
||||
Reference in New Issue
Block a user