-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathlimitset.lua
91 lines (67 loc) · 2.51 KB
/
limitset.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
90
91
local OldRegistered = ACF.LimitSets and ACF.LimitSets.Registered or nil
local LimitSets = {
Registered = OldRegistered or {},
__PostInitLimitSet = false
}
ACF.LimitSets = LimitSets
if SERVER then
LimitSets.acf_has_limitset_notice_been_shown = CreateConVar("__acf_has_limitset_notice_been_shown", 0, FCVAR_ARCHIVE + FCVAR_REPLICATED + FCVAR_UNREGISTERED, "Internal limitset flag", 0, 1)
end
function LimitSets.Create(Name)
local Object = {
ServerData = {}
}
LimitSets.Registered[Name] = Object
Object.Name = Name
function Object:WithAuthor(Author) self.Author = Author end
function Object:WithDescription(Description) self.Description = Description end
function Object:SetServerData(Key, Value)
self.ServerData[Key] = Value
end
-- This allows hot-reloading
if Name == ACF.ServerData.SelectedLimitset and LimitSets.__PostInitLimitSet then
timer.Simple(0, function()
LimitSets.Execute(Name)
end)
end
return Object
end
function LimitSets.Get(Name)
return LimitSets.Registered[Name]
end
function LimitSets.GetAll()
return table.GetKeys(LimitSets.Registered)
end
function LimitSets.Execute(Name)
if CLIENT then return end
if Name == "none" then
return true, "OK"
end
if not isstring(Name) then return false, "Argument #1 (Name) must be a string." end
local LimitSet = LimitSets.Registered[Name]
if not LimitSet then return false, "No limitset with the name '" .. Name .. "'." end
ACF.Utilities.Messages.PrintLog("Info", "Loading the limitset '" .. Name .. "' by " .. (LimitSet.Author or "<no author>") .. "...")
for Key, Value in pairs(LimitSet.ServerData) do
ACF.SetServerData(Key, Value)
end
return true, "OK"
end
local function UpdateLimitSet()
local SelectedLimitsetName = ACF.ServerData.SelectedLimitset or "none"
local SelectedLimitset = ACF.LimitSets.Registered[SelectedLimitsetName]
if SelectedLimitset then
LimitSets.Execute(SelectedLimitsetName)
else
ACF.Utilities.Messages.PrintLog("Info", "No limitset loaded.")
end
ACF.LimitSets.__PostInitLimitSet = true
end
hook.Add("ACF_OnLoadPersistedData", "ACF_LimitSets_Setup", function()
if CLIENT then return end
UpdateLimitSet()
hook.Add("ACF_OnUploadServerData", "ACF_LimitSets_WatchForKey", function(_, Key, _)
if Key ~= "SelectedLimitset" then return end
UpdateLimitSet()
LimitSets.acf_has_limitset_notice_been_shown:SetBool(true)
end)
end)