[ESX]Item Duplication Fix (lockinventorymethod)

ATTENTION THIS METHOD WORKS ONLY WITH ESX FRAMEWORK

I have seen many of you struggling with item duplications, one AK became 10…

There a couple of methods in order to prevent such an action 2 of which I am using my self

So the first one is pretty easy:
You simply add the following line in your remove weapon from inventory line in server side

Citizen.Wait(math.random(500, 100))

The second method needs basic coding knowledge such as Trigger/Register Events, passing arguments with those events and server callbacks! To get thing straight this method will lock the inventory whenever a player is already using it. Lets get started, shall we??

First thing you gonna need is server side event registration, like this:(example from my policejob)

RegisterNetEvent('policejob:togglelock')
AddEventHandler('policejob:togglelock',function(locked)
    lockedInventories = locked
end)

In the server side you are going to need a ServerCallback:

local lockedInventories = false
ESX.RegisterServerCallback('policejob:locked',function(source, cb)

    cb(lockedInventories)

end)

That’s all with server side, lets move into client side!

You need to find where the code call the OpenMenu function
and edit it so it would look like this

ESX.TriggerServerCallback('policejob:locked',function(isLocked)
                                if isLocked then
                                    OpenArmoryMenu()
                                else
                                    ESX.ShowNotification("~r~ This inventory is occupied")
                                end
                            end,isLocked )

In the function OpenArmoryMenu(), the function that you are locking
add this:

locked = true
TriggerServerEvent('policejob:togglelock', locked)

Last thing you want to do is re enable the inventory when the player is done with the action
I prefer unlocking it when a player leave the marker:
So find the hasExitedMarker handler and add this:

if locked == false then

            locked = false

            TriggerServerEvent('policejob:togglelock', locked)

        end

That’s all for now, i will update later on how to lock inventories like properties, esx_thief etc!!

3 Likes

I like what you did but I am too much beginer and cant handle 2nd method due to low knowledge, can you make some examples for pure beginers please? Post is great but I think we need more PokaYoke to avoid idiotism. So please make it more beginer friendly :slight_smile:

1 Like

Sure thing, i will upload some snipets of my policejob

Hello, would you like to help me i’ve tryed to do the steps above explained but isntead locking the bodysearch inventory it is opening the Buy Weapon Menu

Sure thing, send me a snippet of your code

1 Like

Hey! Have u managed to do the esx_thief lock? Thanks!!!