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)