-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
152 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<meta> | ||
<info author="jbeta" type="script" version="1.1.0" /> | ||
<script src="headshot.lua" type="server" /> | ||
<settings> | ||
<setting name="*removeHeadOnHeadshot" value="true" | ||
friendlyname="Blows off player's head on headshot" | ||
group="General" | ||
accept="false,true" | ||
desc="Should player lose his head when he gets headshot?" /> | ||
</settings> | ||
</meta> | ||
<info name="Headshot" description="Headshot feature for enhanced combat realism and damage effect" author="MTA contributors (github.com/multitheftauto/mtasa-resources)" version="1.0.0" type="script" /> | ||
<min_mta_version server="1.6.0" /> | ||
|
||
<settings> | ||
<setting name="*decap" desc="determines whether the player becomes headless after a headshot" value="[true]" accept="false, true" /> | ||
</settings> | ||
|
||
<script type="server" src="src/headshotSettings.lua" /> | ||
<script type="server" src="src/headshotDamage.lua" /> | ||
<script type="server" src="src/headshotSpawn.lua" /> | ||
</meta> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |