Other resources can add locations, spots, categories and recipes from their server scripts, in the same format as the config:
local crafting = exports["tr-crafting"]
-- a recipe at an existing location (the category is created if needed)
crafting:addRecipe("carpenter", "Furniture", "chair", {
output = { { item = "chair" } },
cost = { { item = "plank", quantity = 4 }, { item = "nails", quantity = 8 } },
})
-- a whole location
crafting:addLocation("blacksmith", {
label = "Blacksmith",
jobs = { { name = "blacksmith" } },
locations = { valentine = vector4(-367.0, 787.0, 116.2, 90.0) },
categories = {
Metal = { recipes = { nails = { output = { { item = "nails", quantity = 10 } }, cost = { { item = "iron" } } } } },
},
})
-- another spot for an existing location
crafting:addPoint("carpenter", "rhodes", vector3(1340.2, -1300.5, 77.0))
-- add to (or create) a category
crafting:addCategory("carpenter", "Furniture", { jobs = { { name = "carpenter", minGrade = 2 } } })
-- remove a recipe, a category, or a whole location
crafting:remove("carpenter", "Furniture", "chair")
crafting:remove("carpenter", "Furniture")
crafting:remove("blacksmith")
Adding something that already exists replaces it. Each export returns true, or false with a warning in the server console.
When the resource that added something stops, its additions are removed, and anything it replaced is put back.
Registering on start¶
Restarting tr-crafting reloads its config, so anything added by other scripts is lost. Add yours again whenever tr-crafting starts:
local function register()
exports["tr-crafting"]:addRecipe("carpenter", "Furniture", "chair", { ... })
end
AddEventHandler("onResourceStart", function(resource)
if resource == "tr-crafting" then
register()
end
end)
if GetResourceState("tr-crafting") == "started" then
register()
end
Opening a menu¶
On the client, exports["tr-crafting"]:openCrafting(key) opens a location's menu where the player is. It returns false if the location doesn't exist, the player doesn't have its job, or a menu is already open.