1+ local headshotSettings = {}
2+ local headshotSettingsAvailable = {
3+ {" decap" , " boolean" }
4+ }
5+
6+ local function headshotSettingsNumberize (headshotValue )
7+ if not headshotValue then
8+ return
9+ end
10+
11+ if type (headshotValue ) == " number" then
12+ return headshotValue
13+ end
14+
15+ if type (headshotValue ) == " string" then
16+ return tonumber (headshotValue )
17+ end
18+
19+ return 0
20+ end
21+
22+ local function headshotSettingsBooleanize (headshotValue )
23+ if type (headshotValue ) == " boolean" then
24+ return headshotValue
25+ end
26+
27+ if type (headshotValue ) == " string" then
28+ return headshotValue == " [true]"
29+ end
30+
31+ return false
32+ end
33+
34+ function headshotSettingsGet (headshotSetting )
35+ if not headshotSetting or type (headshotSetting ) ~= " string" then
36+ return
37+ end
38+
39+ return headshotSettings [headshotSetting ]
40+ end
41+
42+ function headshotSettingsSet (headshotSetting , headshotValue )
43+ if not headshotSetting or type (headshotSetting ) ~= " string" then
44+ return
45+ end
46+
47+ local headshotDot = string.find (headshotSetting , " %." )
48+
49+ if headshotDot and type (headshotDot ) == " number" then
50+ headshotSetting = string.sub (headshotSetting , headshotDot + 1 )
51+ end
52+
53+ local headshotFound
54+
55+ for _ , headshotEntry in ipairs (headshotSettingsAvailable ) do
56+ if headshotEntry [1 ] == headshotSetting then
57+ headshotFound = headshotEntry
58+ break
59+ end
60+ end
61+
62+ if not headshotFound then
63+ return
64+ end
65+
66+ local headshotType = headshotFound [2 ]
67+
68+ if headshotType == " string" and type (headshotValue ) == " string" then
69+ headshotSettings [headshotSetting ] = headshotValue
70+ return
71+ end
72+
73+ if headshotType == " number" and type (headshotValue ) == " string" then
74+ headshotSettings [headshotSetting ] = headshotSettingsNumberize (headshotValue )
75+ return
76+ end
77+
78+ if headshotType == " boolean" then
79+ headshotSettings [headshotSetting ] = headshotSettingsBooleanize (headshotValue )
80+ end
81+ end
82+
83+ addEventHandler (" onResourceStart" , resourceRoot ,
84+ function ()
85+ for _ , headshotEntry in ipairs (headshotSettingsAvailable ) do
86+ local headshotSetting = headshotEntry [1 ]
87+ local headshotValue = get (headshotSetting )
88+
89+ headshotSettingsSet (headshotSetting , headshotValue )
90+ end
91+ end
92+ )
93+
94+ addEventHandler (" onSettingChange" , root ,
95+ function (headshotSetting , _ , headshotValue )
96+ headshotSettingsSet (headshotSetting , headshotValue )
97+ end
98+ )
0 commit comments