[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

The Code

Citizen.CreateThread(function()

while true do

    Citizen.Wait(0)

    local playerPed = GetPlayerPed(-1)

    local RNG = math.random(1,100)

        if HasEntityBeenDamagedByWeapon(playerPed, 3523564046, 0) or HasEntityBeenDamagedByWeapon(playerPed, 3219281620, 0) then

            if RNG >= 80 then

                WoopsTripped(playerPed, RNG)

        end

            ClearEntityLastDamageEntity(playerPed)

        end

    end

end)

function WoopsTripped(ped)

if IsEntityDead(ped) then return false end

SetPedToRagdoll(GetPlayerPed(-1), 2000, 2000, 3, 0, 0, 0)

end

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

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:

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

Where should I put the code?

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: