Help me with this code

someone who knows why the npc police drop in and do not interfere with this code …

local pedindex = {}
 
function SetWeaponDrops() -- This function will set the closest entity to you as the variable entity.
    local handle, ped = FindFirstPed()
    local finished = false -- FindNextPed will turn the first variable to false when it fails to find another ped in the index
    repeat
        if not IsEntityDead(ped) then
                pedindex[ped] = {}
        end
        finished, ped = FindNextPed(handle) -- first param returns true while entities are found
    until not finished
 
    for peds,_ in pairs(pedindex) do
        if peds ~= nil then -- set all peds to not drop weapons on death.
            SetPedDropsWeaponsWhenDead(peds, false)
        end
    end
end
 
 
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        SetWeaponDrops()
    end
end)
1 Like

This is not a release


function SetWeaponDrops() -- This function will set the closest entity to you as the variable entity.
    local handle, ped = FindFirstPed()
    local finished = false -- FindNextPed will turn the first variable to false when it fails to find another ped in the index
    repeat 
        if not IsEntityDead(ped) then
                pedindex[ped] = {}
        end
        finished, ped = FindNextPed(handle) -- first param returns true while entities are found
    until not finished
    EndFindPed(handle)

    for peds,_ in pairs(pedindex) do
        if peds ~= nil then -- set all peds to not drop weapons on death.
            SetPedDropsWeaponsWhenDead(peds, false) 
        end
    end
end


Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        SetWeaponDrops()
    end
end)

What do you mean please explain in greater detail on what you are trying to acheave

Sometimes npc drops and sometimes they do not, is there something wrong with script?

I just dont want npc police drop there pistol but nothing really works , this only works sometime

1 Like

You should ask @JinkLeft it’s his code. But some have already stated it works sometimes and sometimes it don’t. I haven’t had a problem with it yet. In the future don’t create a thread for an issue. Ask in the thread you got the code from.

1 Like

Same here i have not had a problem with it yet

hmm thats weird , maybe i did something wrong when i start the script, i made it as a client.lua and a resource but the dont give me any errors?

1 Like

Looks like you are missing EndFindPed(handle)

Thanks! will take your script you post above and replace mine :slight_smile:

1 Like

Yup no problem if you need any other help just message me

Sorry for the late reply. I’m not as actIve as I used to be on the forums. I’m glad you got the issue worked out. If you have any other issues please let me know.

I tried now but the cops still drop there weapon

if you want to try i can give you my ip to server when i get back home and see for yourself

I have a development server ect but I just don’t actually develop anymore currently as I’ve been pretty busy IRL and I never actually tested that script. It was just a modification of script I used at the request of a friend and they told me it worked so I figured I’d throw it to the community if they wanted to mess around with it.