Koja Scripts
NEW

API

This page covers the API exports, events, and triggers that allow you to integrate Koja-Crafting with other scripts and resources.

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
}
ParameterTypeRequiredDescription
identifierStringโญ• Optional*Player's identifier (steam, license, etc.)
playerIdNumberโญ• Optional*Player's server ID
expNumberโœ… RequiredExperience points to add

*One of identifier or playerId must be provided.

Examples

Example 1: Add XP by Player ID

example.lua
-- From your custom resource
exports['koja-crafting']:AddExp({
    playerId = 5,
    exp = 100
})

Example 2: Add XP by Identifier

example.lua
-- From your custom resource
local playerIdentifier = 'license:6435325123456789'
exports['koja-crafting']:AddExp({
    identifier = playerIdentifier,
    exp = 250
})

Example 3: Quest Reward

quest.lua
-- 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
end

Example 4: Job Payout Bonus

job.lua
-- 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

  1. โœ… Validates player exists in database
  2. โž• Adds XP to player's current total
  3. ๐Ÿ“ˆ Automatically calculates level-ups
  4. ๐Ÿ’พ Saves to database
  5. ๐Ÿ“ข 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

ParameterTypeRequiredDescription
identifierStringโœ… YesPlayer's identifier
blueprintNameStringโœ… YesBlueprint item respname (not blueprintItem)

โš ๏ธ Important: Use the item's respname, not the blueprintItem name!

Examples

Example 1: Basic Usage

example.lua
-- From your custom resource
local playerIdentifier = 'license:64376347656789'
exports['koja-crafting']:AddBlueprint(playerIdentifier, 'parachute')

Example 2: Event Reward

example.lua
-- 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

shop.lua
-- 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
end

Blueprint Configuration Reference

In your Config.Craftings:

config.lua
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

ParameterTypeDescription
playerIdNumberPlayer to trigger placement mode
craftingTypeStringCrafting 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

inventory.lua
-- 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.

quest_integration.lua
-- 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)


๐Ÿ†˜ Getting Help with Integration

If you need help integrating Koja-Crafting with your scripts:

  1. Check examples above for similar use cases
  2. Enable debug mode to see what's happening
  3. Test with simple exports first before complex integration
  4. Visit Discord: https://discord.gg/kojascripts
  5. 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.

  • 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