-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
82 lines (75 loc) · 2.89 KB
/
Copy pathserver.lua
File metadata and controls
82 lines (75 loc) · 2.89 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local ESX = exports['es_extended']:getSharedObject()
local function getPlayerPreferences(identifier)
local result = MySQL.Sync.fetchAll('SELECT * FROM user_preferences WHERE identifier = @identifier', {
['@identifier'] = identifier
})
if #result == 0 then
MySQL.Sync.execute('INSERT INTO user_preferences (identifier) VALUES (@identifier)', {
['@identifier'] = identifier
})
result = MySQL.Sync.fetchAll('SELECT * FROM user_preferences WHERE identifier = @identifier', {
['@identifier'] = identifier
})
end
return result[1]
end
RegisterServerEvent('FeatureToggleSystem:toggleFeature')
AddEventHandler('FeatureToggleSystem:toggleFeature', function(feature, state)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local preferences = getPlayerPreferences(identifier)
if preferences then
MySQL.Async.execute('UPDATE user_preferences SET ' .. feature .. ' = @state WHERE identifier = @identifier', {
['@state'] = state,
['@identifier'] = identifier
}, function(rowsChanged)
if rowsChanged > 0 then
TriggerClientEvent('FeatureToggleSystem:updateFeatures', source, {
[feature] = state
})
end
end)
end
end)
RegisterServerEvent('FeatureToggleSystem:setFog')
AddEventHandler('FeatureToggleSystem:setFog', function(intensity, color)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local preferences = getPlayerPreferences(identifier)
if preferences then
MySQL.Async.execute('UPDATE user_preferences SET fog_intensity = @intensity, fog_color_r = @r, fog_color_g = @g, fog_color_b = @b WHERE identifier = @identifier', {
['@intensity'] = intensity,
['@r'] = color.r,
['@g'] = color.g,
['@b'] = color.b,
['@identifier'] = identifier
}, function(rowsChanged)
if rowsChanged > 0 then
TriggerClientEvent('FeatureToggleSystem:updateFog', source, intensity, color)
end
end)
end
end)
ESX.RegisterServerCallback('FeatureToggleSystem:getPreferences', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local preferences = getPlayerPreferences(identifier)
if preferences then
cb({
features = {
feature1 = preferences.feature1,
feature2 = preferences.feature2
},
fog = {
intensity = preferences.fog_intensity,
color = {
r = preferences.fog_color_r,
g = preferences.fog_color_g,
b = preferences.fog_color_b
}
}
})
else
cb(nil)
end
end)