Cleanup, added available triggers to readme

This commit is contained in:
ElPumpo
2018-04-21 11:51:28 +02:00
parent 642ff683a0
commit f3e14bb2c5
2 changed files with 15 additions and 45 deletions
+8
View File
@@ -19,3 +19,11 @@ fvm install --save --folder=esx esx-org/esx_license
```
start esx_license
```
### Available triggers (server side)
- `'esx_license:addLicense', function(target, type, cb)`
- `'esx_license:removeLicense', function(target, type, cb)`
- `'esx_license:getLicense', function(source, cb, type)` (callback)
- `'esx_license:getLicenses', function(source, cb, target)` (callback)
- `'esx_license:checkLicense', function(source, cb, target, type)` (callback)
- `'esx_license:getLicensesList', function(source, cb)` (callback)
+7 -45
View File
@@ -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')