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