[Release] Player Knockout [Updated v2.2]

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
  • 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

http://i.imgur.com/LDQSEUv.jpg

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.

29 Likes

Thanks for this script ! Can we do the same for weapon shot ? I tried so things but no one working

3 Likes

I got knocked out by weapon with this script x)

3 Likes

Is it possible to make it so the 1st time you get knocked out its only 10 seconds but every time you get knocked out it’s 10 seconds longer? So 1st: 10 2nd: 20 3rd: 30? And after that you die instead of being knocked out. Thanks for this by the way

5 Likes

ok so ive got the script working but i feel as if my character gets knocked out way too easy… its like after the first time i get knocked out when i get back up the npc is constantly able to knock me out again and again… would be good if someone could help me change the knock out animation so theres less chance of getting KO’D

1 Like

for some weird reason, players join knocked out on my server and die

2 Likes

Here at ValorRP we have been using this resource since its release and we have had 0 problems. Try double checking your other resources to see if anything is interfering with this resource.

It’s a good script but go knockout the whole and not dying is kinda OP!

1 Like

I cant get this to work for some reason. Does it have any dependencies im missing?

1 Like

you have to incremente the time count on himself while your in the loop of 60 second that made " a fight ".

Good luck.

I have a little problem :slight_smile:

When the knockout happens, I get the message that I was knocked out, my HP starts to regenerate, but the base identifies me as dead. I don’t get up after regenerating my HP.
(I’m using VRPx)

i seem to die from fists but get knocked out by melee weapons

I want something like this, but I’d like it to knockout instead of death for fists. Even if they wake back up, it should only knock them out again instead of killing. Melee weapons should still kill. Can someone help me achieve this?

am i the only one that can get knocked out ny this? i kill others when i fight them

Just reading the messages, it seems alot of people are having issues with this script. Has this been updated since or have u guys got any help from it? If not them might have to pass. Looks like a great script thou.

any updates on this ?

i couldnt get it to work

User Messages

I totally forgot about this and just realized that it was very outdated and did not function any longer.

I wrote an updated knockout script, that includes a config with options, since it seems like there is still some interest. Download the resource or copy the client code. This version is updated and improved.

Default Config

blackOutScreen=true,		-- Toggle blacking out the screen while knocked out
fistsOnly=false,			-- Toggle whether blunt melee weapons also knockout
knockoutLengthFist=15,		-- Time (seconds) that player will be knocked out from fists
knockoutLengthMelee=30,		-- Time (seconds) that player will be knocked out from melee weapon
maximumDamageKO=200,		-- Damage limit until player gets knocked out
Open Source Client Code
local config = {
	blackOutScreen=true,		-- Toggle blacking out the screen while knocked out
	fistsOnly=false,			-- Toggle whether blunt melee weapons also knockout
	knockoutLengthFist=15,		-- Time (seconds) that player will be knocked out from fists
	knockoutLengthMelee=30,		-- Time (seconds) that player will be knocked out from melee weapon
	maximumDamageKO=150,		-- Damage limit until player gets knocked out
}


--=== EDIT BELOW AT YOUR OWN RISK ===--

local ko = {active=false, ped=0, prev=200, health=200, damage=0, timer=0}

function KnockoutPlayer(length)
	ko.timer=length
	ko.active=true
	SetPedToRagdoll(ko.ped, 5500, 5500, 0, 0, 0, 0)
	if config.blackOutScreen then DoScreenFadeOut(1000) end
	Citizen.CreateThread(function()
		while ko.active do
			Wait(5000)
			SetPedToRagdoll(ko.ped, 5500, 5500, 0, 0, 0, 0)
			ResetPedRagdollTimer(ko.ped)
			ko.timer=ko.timer-5
			if ko.timer<=0 then
				if config.blackOutScreen then DoScreenFadeIn(6000) end
				ko.damage=0
				ko.active=false
			end
		end
	end)
end

Citizen.CreateThread(function()
	while true do
		Wait(1)
		ko.ped  = GetPlayerPed(-1)
		ko.health = GetEntityHealth(ko.ped)

		if ko.active then DisablePlayerFiring(PlayerId(), true) end

		if ko.health<ko.prev then -- Has been damaged
			if HasEntityBeenDamagedByWeapon(ko.ped, 0xA2719263, 0) then -- Fists
				ko.damage=ko.damage+(200-ko.health)
				ClearPedLastWeaponDamage(ko.ped)
				ko.health=ko.prev SetEntityHealth(ko.ped, ko.health)
				if ko.damage>config.maximumDamageKO then KnockoutPlayer(config.knockoutLengthFist) end
			elseif not config.fistsOnly then
				if HasEntityBeenDamagedByWeapon(ko.ped, 0, 1) then -- Blunt Melee
					ko.damage=ko.damage+(200-ko.health)
					ClearPedLastWeaponDamage(ko.ped)
					ko.health=ko.prev SetEntityHealth(ko.ped, ko.health)
					if ko.damage>config.maximumDamageKO then KnockoutPlayer(config.knockoutLengthMelee) end
				end
			end
		end
	end
end)

Knockout.zip (1.2 KB)

Let me know if there are other options or features I should add!

1 Like

/helpup so other players could help up whoevers down.

Weirdly this is working every time on my character but I had another one of our devs fly in and I could hit her with fists and melee weapons and it doesn’t seem to be returning HasEntityBeenDamagedByWeapon() as true no matter how I hit her. However my client is working flawlessly… I looked over the code and tried to make some adjustments to try to help but it didn’t make any change.

Any ideas?

1 Like