-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
105 lines (92 loc) · 2.6 KB
/
client.lua
File metadata and controls
105 lines (92 loc) · 2.6 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
debugging = false
RegisterNetEvent("sc-sync:SetDebugStatus", function(allowed)
if allowed then
debugging = not debugging
if debugging then
print("Debug enabled")
else
print("Debug disabled")
end
else
debugging = false
print("Debug permissions refused")
end
end)
globals = {}
TriggerServerEvent("sc-sync:GetGlobals")
exports("GetGlobal", function (key)
local value = globals[key]
if debugging then
print("GetGlobal(" .. json.encode(key) .. "): " .. json.encode(value))
end
return value
end)
exports("SetGlobal", function (key, value, callback)
local id = tostring(GetGameTimer())
local result_handler
local function handleResult(allowed)
pcall(callback, allowed)
if debugging then
print("Server: SetGlobal.Result[" .. json.encode(id) .. "]: " .. json.encode(allowed))
end
RemoveEventHandler(result_handler)
end
result_handler = AddEventHandler("sc-sync:SetGlobal:Result:" .. id, handleResult)
TriggerServerEvent("sc-sync:SetGlobal", key, value, id)
if debugging then
print("SetGlobal(" .. json.encode(key) .. ", " .. json.encode(value) .. "): " .. json.encode(id))
end
return id
end)
RegisterNetEvent("sc-sync:SetGlobal", function(key, value)
globals[key] = value
if debugging then
print("Server: SetGlobal(" .. json.encode(key) .. ", " .. json.encode(value) .. ")")
end
end)
privates = {}
TriggerServerEvent("sc-sync:InitializePrivate")
exports("GetPrivate", function (key)
local value = privates[key]
if debugging then
print("GetPrivate(" .. json.encode(key) .. "): " .. json.encode(value))
end
return value
end)
exports("SetPrivate", function (key, value)
privates[key] = value
TriggerServerEvent("sc-sync:SetPrivate", key, value)
if debugging then
print("SetPrivate(" .. json.encode(key) .. ", " .. json.encode(value) .. ")")
end
end)
RegisterNetEvent("sc-sync:SetPrivate", function(key, value)
privates[key] = value
if debugging then
print("Server: SetPrivate(" .. json.encode(key) .. ", " .. json.encode(value) .. ")")
end
end)
RegisterCommand("SCSglobals", function()
if debugging then
local exist = false
for key,value in pairs(globals) do
print(json.encode(key) .. " => " .. json.encode(value))
exist = true
end
if not exist then
print("Empty \"globals\"")
end
end
end)
RegisterCommand("SCSprivates", function()
if debugging then
local exist = false
for key,value in pairs(privates) do
print(json.encode(key) .. " => " .. json.encode(value))
exist = true
end
if not exist then
print("Empty \"privates\"")
end
end
end)