π§Ύ 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?