Open a stash with command

In most servers there is an option to open inventories via admin menu or command.
But it is only for a specific player inventory that is online, but what about stashes?
I bet you that in your FiveM server admins needed the option to open stashes because the player did not follow your server rules. But how do you open a stash with a command? This problem was very big in the FiveM server that I am developing, I was receiving a lot of DM’s from admins to take something specific from a stash, and if you looked once in the SQL of stash items you know it’s a pain to do that.

So, because of that I created a script for it, the script creates a command named “openstash” and after it you can enter the stash name, for example:
/openstash apartment4712
And then it will open the stash, there can be up to 4 spaces in between the stash name, for example:
/openstash vinewood street block number 5
Ofcourse you can add more by yourself im just to lazy to add more.

Paste this in client.lua

RegisterNetEvent('openstash:open')
AddEventHandler('openstash:open', function(box)
    local name = box
    TriggerServerEvent("inventory:server:OpenInventory", "stash", name, {
        maxweight = 25000000,
        slots = 100,
    })
    TriggerEvent("inventory:client:SetCurrentStash", name)
end)

Paste this in server.lua

QBCore.Commands.Add('openstash', 'Open evidence storage [case-number]', {}, false, function(source, args)
    local src = source

    if args[5] then
        TriggerClientEvent('openstash:open', src, args[1] .." "..args[2] .." "..args[3] .." "..args[4] .." "..args[5])
    elseif args[4] then
        TriggerClientEvent('openstash:open', src, args[1] .." "..args[2] .." "..args[3] .." "..args[4])
    elseif args[3] then
        TriggerClientEvent('openstash:open', src, args[1] .." "..args[2] .." "..args[3])
    elseif args[2] then
        TriggerClientEvent('openstash:open', src, args[1] .." "..args[2])
    elseif args[1] then
        TriggerClientEvent('openstash:open', src, args[1])
    end
end, "god")

This script is only for QBCore framework, and only for “god” permissions, you can change it to “admin” or anything you want.
Please change the triggers to suit your inventory triggers.
It is not the best, I am sure that I could do something better with less lines. If you want you can reply to this post with the shorter script.
If you need any support don’t hesitate asking :grinning:

5 Likes

genius

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.