API
๐ฅ๏ธ Server Exports
Exports allow other resources to interact with Koja-Crafting directly.
AddExp Export
Purpose: Add experience points to a player programmatically from another resource.
Syntax
exports['koja-crafting']:AddExp(data)
Parameters
data = {
identifier = 'steam:110000XXXXXXXX', -- Player identifier (optional if playerId provided)
playerId = 1, -- Server ID (optional if identifier provided)
exp = 100 -- Amount of XP to add
}
| Parameter | Type | Required | Description |
|---|---|---|---|
identifier | String | โญ Optional* | Player's identifier (steam, license, etc.) |
playerId | Number | โญ Optional* | Player's server ID |
exp | Number | โ Required | Experience points to add |
*One of identifier or playerId must be provided.
Examples
Example 1: Add XP by Player ID
-- From your custom resource
exports['koja-crafting']:AddExp({
playerId = 5,
exp = 100
})Example 2: Add XP by Identifier
-- From your custom resource
local playerIdentifier = 'license:6435325123456789'
exports['koja-crafting']:AddExp({
identifier = playerIdentifier,
exp = 250
})Example 3: Quest Reward
-- In your quest system
function CompleteQuest(playerId, questId)
-- Your quest completion logic
-- Reward crafting XP
if questId == 'master_crafter_quest' then
exports['koja-crafting']:AddExp({
playerId = playerId,
exp = 500
})
end
endExample 4: Job Payout Bonus
-- In your job script
RegisterServerEvent('myjob:completeMission')
AddEventHandler('myjob:completeMission', function()
local source = source
-- Normal job payout
GivePlayerMoney(source, 5000)
-- Bonus crafting XP
exports['koja-crafting']:AddExp({
playerId = source,
exp = 50
})
end)How It Works
- โ Validates player exists in database
- โ Adds XP to player's current total
- ๐ Automatically calculates level-ups
- ๐พ Saves to database
- ๐ข Notifies player if online
AddBlueprint Export
Purpose: Grant a blueprint to a player programmatically from another resource.
Syntax
exports['koja-crafting']:AddBlueprint(identifier, blueprintName)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
identifier | String | โ Yes | Player's identifier |
blueprintName | String | โ Yes | Blueprint item respname (not blueprintItem) |
โ ๏ธ Important: Use the item's respname, not the blueprintItem name!
Examples
Example 1: Basic Usage
-- From your custom resource
local playerIdentifier = 'license:64376347656789'
exports['koja-crafting']:AddBlueprint(playerIdentifier, 'parachute')Example 2: Event Reward
-- Event winner gets special blueprint
RegisterServerEvent('myevent:playerWon')
AddEventHandler('myevent:playerWon', function()
local source = source
local identifier = GetPlayerIdentifier(source, 0)
exports['koja-crafting']:AddBlueprint(identifier, 'legendary_item')
end)Example 3: Shop Purchase
-- In your shop script
function PurchaseBlueprint(playerId, blueprintName, price)
local identifier = GetPlayerIdentifier(playerId, 0)
if RemovePlayerMoney(playerId, price) then
exports['koja-crafting']:AddBlueprint(identifier, blueprintName)
TriggerClientEvent('chat:addMessage', playerId, {
args = { '[Shop]', 'Blueprint purchased!' }
})
end
endBlueprint Configuration Reference
In your Config.Craftings:
blueprints = {
{
respname = 'parachute', -- โ Use this in AddBlueprint()
name = 'Parachute',
blueprintItem = 'parachute_blueprint', -- โ NOT this
-- ...
}
}Place Crafting
Purpose: Enter placement mode for portable crafting station.
Direction: Server โ Client
When Triggered:
- Player uses portable crafting item
Usage
-- Server-side
TriggerClientEvent('koja-crafting:client:placeCrafting', playerId, craftingType)
Parameters
| Parameter | Type | Description |
|---|---|---|
playerId | Number | Player to trigger placement mode |
craftingType | String | Crafting station type/ID |
Using the export in inventory to place a station.
OX-INVENTORY
Item definition (ox_inventory/data/items.lua)
['weaponcrafting'] = {
label = 'Weapon Crafting',
weight = 10,
craftingType = 'weapon_crafting',
server = {
export = 'koja-crafting.place_crafting' -- see bridge below
}
},
ESX
In ESX, you register the item as usable:
-- server.lua
ESX.RegisterUsableItem('weaponcrafting', function(playerId)
local xPlayer = ESX.GetPlayerFromId(playerId)
if not xPlayer then return end
-- optional: remove item after use
xPlayer.removeInventoryItem('weaponcrafting', 1)
-- place crafting station
exports['koja-crafting']:place_crafting({
src = xPlayer.source,
type = 'weapon_crafting',
})
end)
QB-CORE
In QB, create a useable item:
-- server.lua
QBCore.Functions.CreateUseableItem('weaponcrafting', function(source, item)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
if not Player.Functions.GetItemByName(item.name) then return end
-- optional: remove item
Player.Functions.RemoveItem('weaponcrafting', 1)
-- place crafting station
exports['koja-crafting']:place_crafting({
src = source,
type = 'weapon_crafting',
})
end)
๐ Callbacks
Server callbacks for retrieving data.
koja-crafting:server
Purpose: Check player's inventory for blueprint items and automatically unlock them.
Direction: Client โ Server
Returns: Result data with success status and blueprints found.
Usage
-- Client-side
KojaLib.Client.TriggerServerCallback('koja-crafting:server:checkForBlueprints', {}, function(result)
if result.success then
print('Blueprints found: ' .. result.blueprintsFound)
print('Message: ' .. result.message)
end
end)
Response Structure
{
success = true, -- Boolean: Operation success
message = 'Found 2 new blueprints!', -- String: Result message
inventory = { ... }, -- Table: Updated inventory
blueprintsFound = 2 -- Number: Count of new blueprints
}
Example Integration
-- In your inventory script
RegisterCommand('checkblueprints', function()
KojaLib.Client.TriggerServerCallback('koja-crafting:server:checkForBlueprints', {}, function(result)
if result.success and result.blueprintsFound > 0 then
ShowNotification('You discovered ' .. result.blueprintsFound .. ' new blueprints!')
else
ShowNotification('No new blueprints found.')
end
end)
end)๐จ Integration Examples
Example 1: Quest System Integration
Scenario: Give crafting XP and blueprint as quest reward.
-- In your quest script (server-side)
RegisterServerEvent('myquest:complete')
AddEventHandler('myquest:complete', function(questId)
local source = source
local identifier = GetPlayerIdentifier(source, 0)
if questId == 'blacksmith_apprentice' then
-- Give crafting XP
exports['koja-crafting']:AddExp({
playerId = source,
exp = 250
})
-- Give weapon blueprint
exports['koja-crafting']:AddBlueprint(identifier, 'advanced_weapon')
-- Quest completion message
TriggerClientEvent('chat:addMessage', source, {
args = { '[Quest]', 'Crafting skills improved! Blueprint unlocked!' }
})
end
end)๐ Related Documentation
- For command usage, see Commands
- For player progression details, see Player Progression
- For blueprint configuration, see Crafting Stations
- For server setup, see Server Settings
๐ Getting Help with Integration
If you need help integrating Koja-Crafting with your scripts:
- Check examples above for similar use cases
- Enable debug mode to see what's happening
- Test with simple exports first before complex integration
- Visit Discord: https://discord.gg/kojascripts
- Read documentation: https://docs.kojascripts.eu
Happy integrating! ๐
Remember: Koja-Crafting is designed to be easily integrated with other resources. Use exports for direct control, and events for dynamic updates.
Related pages
- General Settings โ This page covers the basic configuration options for Koja-Crafting that control debug mode, language, and player behavior.
- Server Settings โ This page covers server-side configuration options including database management, crafting recovery, and shared table functionality.
- Images Settings โ This page explains how to configure item images, add custom graphics, and manage image paths in Koja-Crafting.
- Player Progression Settings โ This page covers the player progression system including levels, experience points, and how to configure the leveling system in Koja-Crafting.
- Admin Settings โ This page covers admin permission configuration and available admin commands for managing Koja-Crafting.
- Interaction Settings โ This page covers how players interact with crafting stations - either through key press or target system (ox_target,qb-target,).
- Configuration โ back to the section overview