# \[QB] Adding core\_crafting crafting in Base Building

## In core\_crafting

#### core\_crafting\client\main.lua

* **OLD CODE:**

```lua
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1)
        local ped = PlayerPedId()
        local coords = GetEntityCoords(ped)
        for _, v in ipairs(Config.Workbenches) do
            local dst = #(coords - v.coords)
            if dst < 20 then
                DrawText3D(v.coords[1], v.coords[2], v.coords[3], Config.Text['workbench_hologram'])
            end
            if dst < 2 then
                if IsControlJustReleased(0, 38) then
                    local open = false
                        local gang = QBCore.Functions.GetPlayerData().gang.name
                    for _, g in ipairs(v.jobs) do
                        if g == job then
                            open = true
                        end
                    end

                    for _, g in ipairs(v.gangs) do
                        if g == gang then
                            open = true
                        end
                    end  

                        if open or (#v.jobs == 0 and #v.gangs == 0) then
                        openWorkbench(v)
                    else
                        QBCore.Functions.Notify(Config.Text['wrong_job'], 'error')
                    end
                end
            end
        end
    end
end)


RegisterNetEvent("open:workbench")
AddEventHandler("open:workbench", function()
    for _, v in ipairs(Config.Workbenches) do
        local open = false
         local gang = QBCore.Functions.GetPlayerData().gang.name

        for _, g in ipairs(v.jobs) do
            if g == job then
                open = true
            end
        end

         for _, g in ipairs(v.gangs) do
            if g == gang then
                open = true
            end
        end

        if open or (#v.jobs == 0 and #v.gangs == 0) then
            openWorkbench(v)
        else
            QBCore.Functions.Notify(Config.Text['wrong_job'], 'error')
        end
    end
end)



```

* **NEW CODE:**

```lua
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1)
        local ped = PlayerPedId()
        local coords = GetEntityCoords(ped)
        for _, v in ipairs(Config.Workbenches) do
            local dst = #(coords - v.coords)
            if dst < 20 then
                DrawText3D(v.coords[1], v.coords[2], v.coords[3], Config.Text['workbench_hologram'])
            end
            if dst < 2 then
                if IsControlJustReleased(0, 38) then
                    local open = false
                        local gang = QBCore.Functions.GetPlayerData().gang.name
                    for _, g in ipairs(v.jobs) do
                        if g == job then
                            open = true
                        end
                    end

                    for _, g in ipairs(v.gangs) do
                        if g == gang then
                            open = true
                        end
                    end  

                        if open or (#v.jobs == 0 and #v.gangs == 0) then
                        openWorkbench(v)
                    else
                        QBCore.Functions.Notify(Config.Text['wrong_job'], 'error')
                    end
                end
            end
        end
    end
end) --- if you don't want to use coords based craftings anymore this can be removed

RegisterNetEvent("open:workbench")
AddEventHandler("open:workbench", function(index)
    v = Config.Workbenches[index] --- this index is the i value in Config.Workbenches

   
        local open = false
         local gang = QBCore.Functions.GetPlayerData().gang.name

        for _, g in ipairs(v.jobs) do
            if g == job then
                open = true
            end
        end

         for _, g in ipairs(v.gangs) do
            if g == gang then
                open = true
            end
        end

        if open or (#v.jobs == 0 and #v.gangs == 0) then
            openWorkbench(v)
        else
            QBCore.Functions.Notify(Config.Text['wrong_job'], 'error')
        end
    
end)
```

#### core\_crafting\config.lua

```lua
CraftingStopWithDistance = false, -- You need to set this false
```

<pre class="language-lua"><code class="lang-lua">Workbenches = { 
    {
        coords = vector3(101.26113891602,6615.810546875,33.58126831054), 
        jobs = {},
        gangs = {}, 
        blip = false, 
        recipes = {"model_base_wood","model_window_wood"}, -- examples normal crafting table
        radius = 3.0 
    }, ---- index = 1
    {
        coords = vector3(101.26113891602,6615.810546875,33.58126831054), 
        jobs = {},
<strong>        gangs = {},  
</strong>        blip = false, 
        recipes = {"bandage","medikit"}, -- examples medic table
        radius = 3.0 
    }, ---- index = 2
    {
        coords = vector3(101.26113891602,6615.810546875,33.58126831054), 
        jobs = {},
        gangs = {}, 
        blip = false, 
        recipes = {"weapon_pistol","weapon_musket"}, -- examples weapon table
        radius = 3.0 
    } ---- index = 3
},-- here you have to setup your different crafting tables options
</code></pre>

## **In HRS\_base\_building**

#### hrs\_base\_building\config.lua

```lua
    ["prop_tool_bench02_ld"] = {
        item = "prop_tool_bench02_ld",
        life = 10000.0,
        type = "crafting",
        subtype = "findGroud",
        noFoundationNeed = true,
        TriggerEvent = {
            type = "client",
            event = "open:workbench",
            args = {1}, --normal crafting table
            entityAsArg = "hrs_base_entity" --- in the arguments, this word will be replaced by the Entity
        },
        crafting = {
            {name = "wood",count = 20}
        }
    },
```

```lua
    ["gr_prop_gr_bench_02a"] = {
        item = "gr_prop_gr_bench_02a",
        life = 20000.0,
        type = "crafting",
        subtype = "findGroud",
        noFoundationNeed = true,
        TriggerEvent = {
            type = "client",
            event = "open:workbench",
            args = {3}, -- weapon crafting table
            entityAsArg = "hrs_base_entity" --- in the arguments, this word will be replaced by the Entity
        },
        crafting = {
            {name = "wood",count = 20},
            {name = "metalscrap",count = 20}
        }
    },
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hrs-scripts.gitbook.io/hrs-scripts-doc/hrs-base-building/snippets/crafting-related/qb-adding-core_crafting-crafting-in-base-building.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
