[RELEASE] Stagger when shot

A simple function to have a 20% chance to fall when shot with selected guns (Heavy pistol/MK2 Pistol)
this can be changed to whatever weapons you’d like, same with the % chance to fall. just change the math.random :slight_smile:

Must be in a client.lua

client.lua (663 Bytes)

12 Likes

Hell yeah man great work!!!

1 Like

How does it sync between clients? Have you tested it?

Shooting

Shot

Have not experienced anything wrong with it so far. hopefully, the videos help for questions of the sync between clients.

1 Like

Looks great, some optimization is needed tho. You don’t need to loop player ped every frame, you can make separate loop for that and do 500ms or more.

2 Likes

Untested optimized


local weaponsList = {
  3523564046,
  3219281620
}
local playerPed = nil

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5000)
		playerPed = PlayerPedId()
    end
end)

Citizen.CreateThread(function()
Citizen.Wait(5500)
	while true do
		Citizen.Wait(0)
		if playerPed ~= nil then
			if HasEntityBeenDamagedByWeapon(playerPed, 0, 0) then -- 0 is any weaponhash according to natives docs
				for i, weaponHash in ipairs(weaponsList) do
				  if HasEntityBeenDamagedByWeapon(playerPed, weaponHash, 0) then
					local RNG = math.random(1,100)
					if RNG >= 80 then
						WoopsTripped(playerPed)
					end
					ClearEntityLastDamageEntity(playerPed)
				  end

				end
			end
		else
			Citizen.Wait(5000)
		end
    end
end)

function WoopsTripped()
	if IsEntityDead(playerPed) or IsPedInAnyVehicle(playerPed , false) then return false end
	SetPedToRagdoll(playerPed, 2000, 2000, 3, 0, 0, 0)
end
1 Like

playerPed = PlayerPedId()
^ is also faster, won’t feel any difference, but it’s always good to use whats faster.

1 Like

Changed it, thx :smiley:

can also use for with an list for hashes, something like that

weaponsList = {
  3523564046,
  3219281620
}
-- add to code
for i, weaponHash in ipairs(weaponsList) do
  if HasEntityBeenDamagedByWeapon(playerPed, weaponHash, 0) then
-- add code
end

just a simple idea if u want to improve it more :smiley:

1 Like

Hello, is this script 100% functional? and synced?
thanks!

You can make a new client.lua or throw it in an existing one.

Please look at the video/talk above

Edited it with the weapon list, thanks :smiley:

is there a download link?

download for what :joy: you literally have whole code here

1 Like

Shhhhhhh don’t tell him! :wink:

1 Like

I’m new to all of this, it’s cool nobody has to tell me anything, you’re not the first and definitely won’t be the last

Someone has already told you, there is no download the code is posted in the original post, there are edits people made to optimize it. Enjoy :smiley:

i’ve been trying to make this work for 2 years, no joke. I was not checking for entity damage, but ped damage. crazy man you are a g

1 Like