[ESX] Adding core_crafting crafting in Base Building
This snippet will help you setup crafting from core_crafting as events to use on other scripts like hrs_base_building
In core_crafting
core_crafting\client\main.lua
OLD CODE:
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] - 0.8, Config.Text["workbench_hologram"])
end
if dst < 2 then
if IsControlJustReleased(0, Keys["E"]) then
local open = false
for _, g in ipairs(v.jobs) do
if g == job then
open = true
end
end
if open or #v.jobs == 0 then
openWorkbench(v)
else
SendTextMessage(Config.Text["wrong_job"])
end
end
end
end
end
end
)
NEW CODE:
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] - 0.8, Config.Text["workbench_hologram"])
end
if dst < 2 then
if IsControlJustReleased(0, Keys["E"]) then
local open = false
for _, g in ipairs(v.jobs) do
if g == job then
open = true
end
end
if open or #v.jobs == 0 then
openWorkbench(v)
else
SendTextMessage(Config.Text["wrong_job"])
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
for _, g in ipairs(v.jobs) do
if g == job then
open = true
end
end
if open or #v.jobs == 0 then
openWorkbench(v)
else
SendTextMessage(Config.Text["wrong_job"])
end
end)
core_crafting\config.lua
CraftingStopWithDistance = false, -- You need to set this false
Workbenches = {
{
coords = vector3(101.26113891602,6615.810546875,33.58126831054),
jobs = {},
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 = {},
blip = false,
recipes = {"bandage","medikit"}, -- examples medic table
radius = 3.0
}, ---- index = 2
{
coords = vector3(101.26113891602,6615.810546875,33.58126831054),
jobs = {},
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
In HRS_base_building
hrs_base_building\config.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}
}
},
["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}
}
},
Previous[QB] Adding qb-inventory crafting in Base BuildingNext[QB] Adding core_crafting crafting in Base Building
Last updated