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