Skip to content

Commit a5dcd6f

Browse files
authored
headshot: minor improvements (#290)
* Main commit * Implement suggested changes. * Rename functions, and make them local Co-authored-by: majqqq <>
1 parent 37e83c4 commit a5dcd6f

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

[gameplay]/headshot/headshot.lua

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
local removeHeadOnHeadshot = get("removeHeadOnHeadshot");
1+
local removeHeadOnHeadshot = get("removeHeadOnHeadshot")
22

3-
addEvent "onPlayerHeadshot"
3+
addEvent("onPlayerHeadshot", false)
44

5-
addEventHandler("onPlayerDamage", getRootElement(),
6-
function (attacker, weapon, bodypart, loss)
7-
if bodypart == 9 then
8-
local result = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
9-
if result == true then
10-
killPed(source, attacker, weapon, bodypart)
11-
if removeHeadOnHeadshot then
12-
setPedHeadless(source, true)
13-
end
5+
local function checkForHeadshot(attacker, weapon, bodypart, loss)
6+
if bodypart == 9 then
7+
local forceDeath = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
8+
9+
if forceDeath then
10+
killPed(source, attacker, weapon, bodypart)
11+
12+
if removeHeadOnHeadshot then
13+
setPedHeadless(source, true)
1414
end
1515
end
1616
end
17-
)
17+
end
18+
addEventHandler("onPlayerDamage", root, checkForHeadshot)
1819

19-
addEventHandler("onPlayerSpawn", getRootElement(),
20-
function()
21-
-- Restore head if it got blown off
22-
if removeHeadOnHeadshot and isPedHeadless(source) then
23-
setPedHeadless(source, false)
24-
end
20+
local function restorePlayerHead()
21+
if removeHeadOnHeadshot and isPedHeadless(source) then
22+
setPedHeadless(source, false) -- Restore head if it got blown off
2523
end
26-
)
24+
end
25+
addEventHandler("onPlayerSpawn", root, restorePlayerHead)

0 commit comments

Comments
 (0)