Help me with this code


#1

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)

#2

This is not a release


#3

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)

#4

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


#5

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


#6

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.


#7

Same here i have not had a problem with it yet


#8

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?


#9

Looks like you are missing EndFindPed(handle)


#10

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


#11

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


#12

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.


#13

I tried now but the cops still drop there weapon


#14

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


#15

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.