Description
Get KO’d with this script. This script will block any damage from fists and/or blunt weapons (configurable) and instead will knock out the player after too much damage.
v2.2 Hotfix
- Fixed major health calculation error (Thanks to SaltoQC)
v2.1 Features (All configurable)
- Ability to help players up using /helpup [ID] (Thanks to Chafe for request)
- Player can’t help themselves up, and helping player must be close
- Can disable in config with
allowPlayerHelp=false
- Ability to take damage after KO and die (Thanks to SummonerDeath)
- Players will die from fists after KO’d if
dieAfterKnockout=true
- Players will die from fists after KO’d if
- Damage will reduce over time depending on config amount
- Separated config into shared file so server can have access too
I plan to keep updating and eventually release a medical system that will work together.
Default Config Options
blackOutScreen=true, -- Toggle blacking out the screen while knocked out
fistsOnly=false, -- Toggle whether blunt melee weapons also knockout
knockoutLengthFist=30, -- Time (seconds) that player will be knocked out from fists
knockoutLengthMelee=60, -- Time (seconds) that player will be knocked out from melee weapon
maximumDamageKO=200, -- Damage limit until player gets knocked out
reduceDamageAmount=10, -- Amount of damage that is reduced every 5 seconds
allowPlayerHelp=true, -- Allow other players to help up the knocked out player
dieAfterKnockout=false, -- Allows player to die from damage received while knocked out
Screenshot
Download and Installation
To use, simply put the unzipped folder in your server resources folder, then add Knockout to your server.cfg
Knockout v2.2.zip (2.3 KB)
Open Source Code
local ko = {active=false, ped=0, prev=200, health=200, damage=0, timer=0, reducing=false}
RegisterNetEvent("ko:helpPlayer")
AddEventHandler("ko:helpPlayer", function(sender)
if #(GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(sender)))-GetEntityCoords(ko.ped)) < 10.0 then
ko.active=false
ko.timer=0
ko.damage=0
SetPedToRagdoll(ko.ped, 100, 100, 0, 0, 0, 0)
if KO_Config.blackOutScreen then DoScreenFadeIn(8000) end
end
end)
function KnockoutPlayer(length)
ko.timer=length
ko.active=true
SetPedToRagdoll(ko.ped, 6000, 6000, 0, 0, 0, 0)
ShowNotification("~r~You were knocked out!")
if KO_Config.blackOutScreen then DoScreenFadeOut(1000) end
Citizen.CreateThread(function()
while ko.active do
Wait(5000)
ko.timer=ko.timer-5
if ko.timer<=0 then
if KO_Config.blackOutScreen then DoScreenFadeIn(10000) end
ko.damage=0
ko.active=false
else
SetPedToRagdoll(ko.ped, 6000, 6000, 0, 0, 0, 0)
ResetPedRagdollTimer(ko.ped)
end
end
end)
end
function ReduceDamage()
if not ko.reducing and KO_Config.reduceDamageAmount>0 then
ko.reducing=true
Citizen.CreateThread(function()
while ko.damage > 0 do
Wait(5000)
ko.damage=ko.damage-KO_Config.reduceDamageAmount if ko.damage<0 then ko.damage=0 end
end
ko.reducing=false
end)
end
end
Citizen.CreateThread(function()
ko.ped = GetPlayerPed(-1)
SetEntityMaxHealth(ko.ped, 200)
while true do
Wait(1)
ko.ped = GetPlayerPed(-1)
ko.health = GetEntityHealth(ko.ped)
if ko.active and not KO_Config.blackOutScreen then
DisablePlayerFiring(PlayerId(), true)
end
if ko.active and KO_Config.dieAfterKnockout then
-- Let player receive damage
else
if ko.health<ko.prev then -- Has been damaged
if HasEntityBeenDamagedByWeapon(ko.ped, 0xA2719263, 0) then -- Fists
ko.damage=ko.damage+(ko.prev-ko.health) ReduceDamage()
ClearPedLastWeaponDamage(ko.ped) SetEntityHealth(ko.ped, ko.prev)
if ko.damage>KO_Config.maximumDamageKO then KnockoutPlayer(KO_Config.knockoutLengthFist) end
elseif not KO_Config.fistsOnly then
if HasEntityBeenDamagedByWeapon(ko.ped, 0, 1) then -- Blunt Melee
ko.damage=ko.damage+(ko.prev-ko.health) ReduceDamage()
ClearPedLastWeaponDamage(ko.ped) SetEntityHealth(ko.ped, ko.prev)
if ko.damage>KO_Config.maximumDamageKO then KnockoutPlayer(KO_Config.knockoutLengthMelee) end
end
end
end
end
ko.prev=ko.health
end
end)
Let me know if you find any bugs or have ideas for other features.