🧾 Server Side (serverside.lua)

This script demonstrates the use of server-side functions from CodexCore, including currency handling, item usage, SQL access, and shared callbacks. Make sure the top of every server script using CodexCore includes the following setup:


local CodexCore = exports['codex_core']:getLibServer()
local Inventory = CodexCore.RequestInventoryAPI()
local Core = CodexCore.RequestCoreAPI()

-- πŸ“‘ Register a server callback
CodexCore.RegisterServerCallback('CodexCore-lib:fetchUserCharacterIdentifier', function(source, cb)
    cb(CodexCore.GetCharacterIdentifier(source))
end)

-- πŸ’Ό Get Player Info
RegisterCommand("getjob", function(source)
    local job = CodexCore.GetJob(source)
    local grade = CodexCore.GetJobGrade(source)
    print("πŸ‘€ Source:", source, "has job:", job, "grade:", grade)
end)

-- πŸ’Έ Get Currency
RegisterCommand("getmoney", function(source)
    local money = CodexCore.GetMoney(source)
    local gold = CodexCore.GetGold(source)
    local cents = CodexCore.GetCents(source)
    print("πŸ’° Cash:", money, "| πŸͺ™ Gold:", gold, "| 🟑 Cents:", cents)
end)

-- πŸ’° Add/Remove Money
RegisterCommand("addcash", function(source)
    CodexCore.AddAccountMoney(source, 0, 100) -- Add $100
    print("πŸ’΅ 100$ added to source", source)
end)

RegisterCommand("removecash", function(source)
    CodexCore.RemoveAccountMoney(source, 0, 50) -- Remove $50
    print("πŸ’΅ 50$ removed from source", source)
end)

-- πŸ“¦ Add/Remove Item
RegisterCommand("giveitem", function(source)
    CodexCore.AddItem(source, "bread", 2)
end)

RegisterCommand("removeitem", function(source)
    CodexCore.RemoveItem(source, "bread", 1)
end)

-- πŸ”Ž Check Item Count
RegisterCommand("itemcount", function(source)
    local count = CodexCore.GetItemCount(source, "bread")
    print("🍞 You have", count, "bread(s).")
end)

-- πŸ” Register Usable Item
CodexCore.RegisterUsableItem("whiskey", function(source)
    TriggerClientEvent("codex:notify", source, "πŸ₯ƒ You drank whiskey!", 5000)
end)

-- 🧠 SQL Usage
RegisterCommand("fetchusersql", function(source)
    local result = CodexCore.ExecuteSql("SELECT * FROM users WHERE identifier = @identifier", {
        ['@identifier'] = CodexCore.GetUserIdentifier(source)
    })
    print(json.encode(result))
end)

Last updated

Was this helpful?