Adding QB-SHOPS to SafeZone Peds

This snippet will explain to you how to convert the QB-SHOPS into export based so you can open shops using exports

In qb-shops script

In qb-shops/client/main.lua

  • old code

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    PlayerData = QBCore.Functions.GetPlayerData()
    createBlips()
    createPeds()
    TriggerServerEvent('qb-shops:server:SetShopList')
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
    deletePeds()
    PlayerData = nil
end)

RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
    PlayerData = val
end)

AddEventHandler('onResourceStart', function(resourceName)
    if GetCurrentResourceName() ~= resourceName then return end
    createBlips()
    createPeds()
    TriggerServerEvent('qb-shops:server:SetShopList')
end)

AddEventHandler('onResourceStop', function(resourceName)
    if GetCurrentResourceName() ~= resourceName then return end

    deletePeds()
end)
  • new code

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    PlayerData = QBCore.Functions.GetPlayerData()
    --createBlips()
    --createPeds()
    TriggerServerEvent('qb-shops:server:SetShopList')
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
    --deletePeds()
    PlayerData = nil
end)

RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
    PlayerData = val
end)

AddEventHandler('onResourceStart', function(resourceName)
    if GetCurrentResourceName() ~= resourceName then return end
    --createBlips()
    --createPeds()
    TriggerServerEvent('qb-shops:server:SetShopList')
end)

AddEventHandler('onResourceStop', function(resourceName)
    if GetCurrentResourceName() ~= resourceName then return end

    --deletePeds()
end)
  • code you have to add to the file

function openShopExport(k)
    openShop(k, Config.Locations[k])
end

exports('openShopExport',openShopExport)

In hrs_zombies script

In hrs_zombies/config.lua

Config.safezonePedsAndProps = {
    ['shop_ped'] = {
        type = 'ped',
        model = `csb_ramp_marine`,
        coords = vector3(-2277.5537, 387.5620, 174.6018),
        heading = 90.0,
        drawDistance = 160.0,
        anim = {
            animDict = "amb@world_human_aa_smoke@male@idle_a", 
	    animName = "idle_a"
        },
        targetInfo = { 
            options = { 
                { 
                    num = 1, 
                    icon = 'fa-solid fa-basket-shopping', 
                    label = 'Open Shop', 
                    targeticon = 'fas fa-example', 
                    action = function(entity) 
                        exports['qb-shops']:openShopExport("247supermarket") 
                        -- the argument of the export is the index of the shop
                        -- in qb-shops/config.lua in the section Config.Locations
                    end,
                    canInteract = function(entity, distance, data) 
                        return true
                    end,
                }
            },
            distance = 2.5,
        },
        blip = {
            label = "Gun Shop",
            color = 2,
            alpha = 128,
            scale = 1.0,
            sprite = 150,
            shortRange = true 
        }
    },
}

example of the qb-shops

Config.Locations = {
    -- 24/7 Locations
    ["247supermarket"] = { --- this is the index "247supermarket"
        ["label"] = "24/7 Supermarket",
        ["coords"] = vector4(24.47, -1346.62, 29.5, 271.66),
        ["ped"] = 'mp_m_shopkeep_01',
        ["scenario"] = "WORLD_HUMAN_STAND_MOBILE",
        ["radius"] = 1.5,
        ["targetIcon"] = "fas fa-shopping-basket",
        ["targetLabel"] = "Open Shop",
        ["products"] = Config.Products["normal"],
        ["showblip"] = true,
        ["blipsprite"] = 52,
        ["blipscale"] = 0.6,
        ["blipcolor"] = 0
    },
}

Last updated