forked from R1CKY6/Ricky-VinewoodSign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.lua
89 lines (81 loc) · 3.02 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
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
83
84
85
86
87
88
89
local ESX = nil
local QBCore = nil
local FrameworkFound = nil
LoadFramework = function()
if Config.Framework == 'esx' then
ESX = exports['es_extended']:getSharedObject()
FrameworkFound = 'esx'
elseif Config.Framework == 'qbcore' then
QBCore = exports["qb-core"]:GetCoreObject()
FrameworkFound = 'qbcore'
elseif Config.Framework == 'autodetect' then
if GetResourceState('es_extended') == 'started' then
ESX = exports['es_extended']:getSharedObject()
FrameworkFound = 'esx'
elseif GetResourceState('qb-core') == 'started' then
QBCore = exports["qb-core"]:GetCoreObject()
FrameworkFound = 'qbcore'
else
FrameworkFound = 'standalone'
end
elseif Config.Framework == 'standalone' then
FrameworkFound = 'standalone'
end
print('[Ricky-VinewoodSign] Framework found: ' .. FrameworkFound)
end
AddEventHandler('onResourceStart', function(resourceName)
if resourceName == GetCurrentResourceName() then
LoadFramework()
end
end)
Authorized = function(source)
if FrameworkFound == 'esx' then
local xPlayer = ESX.GetPlayerFromId(source)
for k, v in pairs(Config.AuthorizedGroups.group) do
if xPlayer.getGroup() == v then
return true
end
end
elseif FrameworkFound == 'qbcore' then
for k, v in pairs(Config.AuthorizedGroups.group) do
if QBCore.Functions.HasPermission(source, v) then
return true
end
end
elseif FrameworkFound == 'standalone' then
for k, v in pairs(Config.AuthorizedGroups.identifier) do
for k, v2 in pairs(GetPlayerIdentifiers(source)) do
if v2 == v then
return true
end
end
end
end
return false
end
GetFileData = function()
local file = LoadResourceFile(GetCurrentResourceName(), Config.FileName)
file = json.decode(file)
return file
end
RegisterCommand(Config.Command, function(source, args, rawCommand)
if not Authorized(source) then return
end
TriggerClientEvent('ricky-vinewood:openNui', source, GetFileData()[1], GetFileData()[2])
end)
RegisterServerEvent('ricky-vinewood:saveText')
AddEventHandler('ricky-vinewood:saveText', function(data)
if not Authorized(source) then return end
local newText = data.text
local newColor = data.color
local file = LoadResourceFile(GetCurrentResourceName(), Config.FileName)
file = json.decode(file)
file[1] = newText
file[2] = newColor
SaveResourceFile(GetCurrentResourceName(), Config.FileName, json.encode(file, {indent = true}), -1)
TriggerClientEvent('ricky-vinewood:saveText', -1, file)
end)
RegisterServerEvent('ricky-vinewood:loadText')
AddEventHandler('ricky-vinewood:loadText', function()
TriggerClientEvent('ricky-vinewood:saveText', source, GetFileData())
end)