forked from smallo92/xnTattoos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
46 lines (43 loc) · 1.44 KB
/
server.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
43
44
45
46
local QBCore = exports['qb-core']:GetCoreObject()
QBCore.Functions.CreateCallback('SmallTattoos:GetPlayerTattoos', function(source, cb)
local src = source
local xPlayer = QBCore.Functions.GetPlayer(src)
if xPlayer then
MySQL.Sync.fetchAll('SELECT tattoos FROM players WHERE citizenid = ?', {
xPlayer.PlayerData.citizenid
}, function(result)
if result[1].tattoos then
cb(json.decode(result[1].tattoos))
else
cb()
end
end)
else
cb()
end
end)
QBCore.Functions.CreateCallback('SmallTattoos:PurchaseTattoo', function(source, cb, tattooList, price, tattoo, tattooName)
local src = source
local xPlayer = QBCore.Functions.GetPlayer(src)
if xPlayer.Functions.GetMoney('cash') >= price then
xPlayer.Functions.RemoveMoney('cash', price)
tattooList[#tattooList + 1] = tattoo
MySQL.Async.execute('UPDATE players SET tattoos = ? WHERE citizenid = ?', {
json.encode(tattooList),
xPlayer.PlayerData.citizenid
})
TriggerClientEvent('QBCore:Notify', src, 'You bought the '..tattooName..' tattoo for $'..price)
cb(true)
else
TriggerClientEvent('QBCore:Notify', src, 'Not enough money', 'error')
cb(false)
end
end)
RegisterServerEvent('SmallTattoos:RemoveTattoo')
AddEventHandler('SmallTattoos:RemoveTattoo', function (tattooList)
local xPlayer = QBCore.Functions.GetPlayer(source)
MySQL.Async.execute('UPDATE players SET tattoos = ? WHERE citizenid = ?', {
json.encode(tattooList),
xPlayer.PlayerData.citizenid
})
end)