-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
50 lines (44 loc) · 2.03 KB
/
Copy pathserver.lua
File metadata and controls
50 lines (44 loc) · 2.03 KB
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
47
48
49
50
local ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
ESX.RegisterServerCallback('driftPointSystem:getPoints', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.fetchScalar('SELECT points FROM drift_points WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(points)
if points then
cb(points)
else
MySQL.Async.execute('INSERT INTO drift_points (identifier, points) VALUES (@identifier, 0)', {
['@identifier'] = xPlayer.identifier
}, function()
cb(0)
end)
end
end)
end)
RegisterServerEvent('driftPointSystem:earnPoints')
AddEventHandler('driftPointSystem:earnPoints', function()
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.fetchScalar('SELECT points FROM drift_points WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(points)
if points then
local newPoints = points + Config.DriftPoint.Reward
MySQL.Async.execute('UPDATE drift_points SET points = @points WHERE identifier = @identifier', {
['@points'] = newPoints,
['@identifier'] = xPlayer.identifier
}, function()
xPlayer.addAccountMoney('bank', Config.DriftPoint.Reward)
TriggerClientEvent('esx:showNotification', source, 'You earned ~g~' .. Config.DriftPoint.Reward .. '~s~ points!')
end)
else
MySQL.Async.execute('INSERT INTO drift_points (identifier, points) VALUES (@identifier, @points)', {
['@identifier'] = xPlayer.identifier,
['@points'] = Config.DriftPoint.Reward
}, function()
xPlayer.addAccountMoney('bank', Config.DriftPoint.Reward)
TriggerClientEvent('esx:showNotification', source, 'You earned ~g~' .. Config.DriftPoint.Reward .. '~s~ points!')
end)
end
end)
end)