diff --git a/[gameplay]/headshot/meta.xml b/[gameplay]/headshot/meta.xml
index e3e1f490a..4c15bf3d4 100644
--- a/[gameplay]/headshot/meta.xml
+++ b/[gameplay]/headshot/meta.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/[gameplay]/headshot/src/headshotSettings.lua b/[gameplay]/headshot/src/headshotSettings.lua
index 9d9ae4f6b..0c8a68491 100644
--- a/[gameplay]/headshot/src/headshotSettings.lua
+++ b/[gameplay]/headshot/src/headshotSettings.lua
@@ -3,6 +3,34 @@ local headshotSettingsAvailable = {
{"decap", "boolean"}
}
+local function headshotSettingsNumberize(headshotValue)
+ if not headshotValue then
+ return
+ end
+
+ if type(headshotValue) == "number" then
+ return headshotValue
+ end
+
+ if type(headshotValue) == "string" then
+ return tonumber(headshotValue)
+ end
+
+ return 0
+end
+
+local function headshotSettingsBooleanize(headshotValue)
+ if type(headshotValue) == "boolean" then
+ return headshotValue
+ end
+
+ if type(headshotValue) == "string" then
+ return headshotValue == "[true]"
+ end
+
+ return false
+end
+
function headshotSettingsGet(headshotSetting)
if not headshotSetting or type(headshotSetting) ~= "string" then
return
@@ -11,67 +39,60 @@ function headshotSettingsGet(headshotSetting)
return headshotSettings[headshotSetting]
end
-function headshotSettingsBooleanize(headshotValue)
- if not headshotValue or type(headshotValue) ~= "string" then
+function headshotSettingsSet(headshotSetting, headshotValue)
+ if not headshotSetting or type(headshotSetting) ~= "string" then
return
end
- if string.find(headshotValue, "true") then
- return true
+ local headshotDot = string.find(headshotSetting, "%.")
+
+ if headshotDot and type(headshotDot) == "number" then
+ headshotSetting = string.sub(headshotSetting, headshotDot + 1)
end
- return false
+ local headshotFound
+
+ for _, headshotEntry in ipairs(headshotSettingsAvailable) do
+ if headshotEntry[1] == headshotSetting then
+ headshotFound = headshotEntry
+ break
+ end
+ end
+
+ if not headshotFound then
+ return
+ end
+
+ local headshotType = headshotFound[2]
+
+ if headshotType == "string" and type(headshotValue) == "string" then
+ headshotSettings[headshotSetting] = headshotValue
+ return
+ end
+
+ if headshotType == "number" and type(headshotValue) == "string" then
+ headshotSettings[headshotSetting] = headshotSettingsNumberize(headshotValue)
+ return
+ end
+
+ if headshotType == "boolean" then
+ headshotSettings[headshotSetting] = headshotSettingsBooleanize(headshotValue)
+ end
end
addEventHandler("onResourceStart", resourceRoot,
function()
- for _, headshotEntry in pairs(headshotSettingsAvailable) do
+ for _, headshotEntry in ipairs(headshotSettingsAvailable) do
local headshotSetting = headshotEntry[1]
- local headshotType = headshotEntry[2]
local headshotValue = get(headshotSetting)
- if headshotValue and type(headshotValue) == "string" then
- if headshotType == "boolean" then
- headshotSettings[headshotSetting] = headshotSettingsBooleanize(headshotValue)
- else
- headshotSettings[headshotSetting] = headshotValue
- end
- end
+ headshotSettingsSet(headshotSetting, headshotValue)
end
end
)
addEventHandler("onSettingChange", root,
function(headshotSetting, _, headshotValue)
- local headshotDot = string.find(headshotSetting, "%.")
-
- if headshotDot and type(headshotDot) == "number" then
- headshotSetting = string.sub(headshotSetting, headshotDot + 1)
- end
-
- local headshotFound
-
- for _, headshotEntry in pairs(headshotSettingsAvailable) do
- if headshotEntry[1] == headshotSetting then
- headshotFound = headshotEntry
- break
- end
- end
-
- if not headshotFound then
- return
- end
-
- local headshotType = headshotFound[2]
-
- if not headshotValue or type(headshotValue) ~= "string" then
- return
- end
-
- if headshotType == "boolean" then
- headshotSettings[headshotSetting] = headshotSettingsBooleanize(headshotValue)
- else
- headshotSettings[headshotSetting] = headshotValue
- end
+ headshotSettingsSet(headshotSetting, headshotValue)
end
)
\ No newline at end of file