diff --git a/[gameplay]/headshot/headshot.lua b/[gameplay]/headshot/headshot.lua
deleted file mode 100644
index 7f02c21de..000000000
--- a/[gameplay]/headshot/headshot.lua
+++ /dev/null
@@ -1,25 +0,0 @@
-local removeHeadOnHeadshot = get("removeHeadOnHeadshot")
-
-addEvent("onPlayerHeadshot", false)
-
-local function checkForHeadshot(attacker, weapon, bodypart, loss)
- if bodypart == 9 then
- local forceDeath = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
-
- if forceDeath then
- killPed(source, attacker, weapon, bodypart)
-
- if removeHeadOnHeadshot then
- setPedHeadless(source, true)
- end
- end
- end
-end
-addEventHandler("onPlayerDamage", root, checkForHeadshot)
-
-local function restorePlayerHead()
- if removeHeadOnHeadshot and isPedHeadless(source) then
- setPedHeadless(source, false) -- Restore head if it got blown off
- end
-end
-addEventHandler("onPlayerSpawn", root, restorePlayerHead)
\ No newline at end of file
diff --git a/[gameplay]/headshot/meta.xml b/[gameplay]/headshot/meta.xml
index 28e79cc7d..c7b5cfb82 100644
--- a/[gameplay]/headshot/meta.xml
+++ b/[gameplay]/headshot/meta.xml
@@ -1,11 +1,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/[gameplay]/headshot/src/headshotDamage.lua b/[gameplay]/headshot/src/headshotDamage.lua
new file mode 100644
index 000000000..c8b7643a9
--- /dev/null
+++ b/[gameplay]/headshot/src/headshotDamage.lua
@@ -0,0 +1,30 @@
+addEvent("onPlayerHeadshot", false)
+addEvent("onPlayerPreHeadshot", false)
+
+addEventHandler("onPlayerDamage", root,
+ function(headshotAttacker, headshotCause, headshotBodypart, headshotDamage)
+ if not headshotAttacker or not isElement(headshotAttacker) or getElementType(headshotAttacker) ~= "player" then
+ return
+ end
+
+ if headshotBodypart ~= 9 then
+ return
+ end
+
+ triggerEvent("onPlayerPreHeadshot", source, headshotAttacker, headshotCause, headshotDamage)
+
+ if wasEventCancelled() then
+ return
+ end
+
+ killPed(source, headshotAttacker, headshotCause, headshotBodypart)
+
+ triggerEvent("onPlayerHeadshot", source, headshotAttacker, headshotCause)
+
+ if not headshotSettingsGet("decap") then
+ return
+ end
+
+ setPedHeadless(source, true)
+ end
+)
\ No newline at end of file
diff --git a/[gameplay]/headshot/src/headshotSettings.lua b/[gameplay]/headshot/src/headshotSettings.lua
new file mode 100644
index 000000000..0c8a68491
--- /dev/null
+++ b/[gameplay]/headshot/src/headshotSettings.lua
@@ -0,0 +1,98 @@
+local headshotSettings = {}
+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
+ end
+
+ return headshotSettings[headshotSetting]
+end
+
+function headshotSettingsSet(headshotSetting, headshotValue)
+ if not headshotSetting or type(headshotSetting) ~= "string" then
+ return
+ end
+
+ local headshotDot = string.find(headshotSetting, "%.")
+
+ if headshotDot and type(headshotDot) == "number" then
+ headshotSetting = string.sub(headshotSetting, headshotDot + 1)
+ end
+
+ 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 ipairs(headshotSettingsAvailable) do
+ local headshotSetting = headshotEntry[1]
+ local headshotValue = get(headshotSetting)
+
+ headshotSettingsSet(headshotSetting, headshotValue)
+ end
+ end
+)
+
+addEventHandler("onSettingChange", root,
+ function(headshotSetting, _, headshotValue)
+ headshotSettingsSet(headshotSetting, headshotValue)
+ end
+)
\ No newline at end of file
diff --git a/[gameplay]/headshot/src/headshotSpawn.lua b/[gameplay]/headshot/src/headshotSpawn.lua
new file mode 100644
index 000000000..68d2d231b
--- /dev/null
+++ b/[gameplay]/headshot/src/headshotSpawn.lua
@@ -0,0 +1,13 @@
+addEventHandler("onPlayerSpawn", root,
+ function()
+ if not isPedHeadless(source) then
+ return
+ end
+
+ if not headshotSettingsGet("decap") then
+ return
+ end
+
+ setPedHeadless(source, false)
+ end
+)
\ No newline at end of file