Client Side

📢 Client Event: codex-core:playerLoaded
codex-core:playerLoaded
What is the codex-core:playerLoaded
Event?
codex-core:playerLoaded
Event?The event codex-core:playerLoaded
is a client-side event triggered when a player has successfully loaded into the server. This event is part of Codex Core and is used to execute certain actions when a player enters the game or after a successful resource load.
When should you use this event?
Use this event to trigger actions or scripts that should run after a player is fully loaded into the game.
It's useful for initializing client-side functionality, like setting up player data, loading UI elements, or triggering animations.
📢 How to Use the Event?
You must register the event on the client-side and define what actions to perform when the event is triggered. This event can be triggered from the server-side once the player has loaded into the game.
Here's the basic syntax for using the event:
RegisterNetEvent('codex-core:playerLoaded')
AddEventHandler('codex-core:playerLoaded', function()
-- Actions you want to trigger when the player is loaded
end)
Explanation:
RegisterNetEvent('codex-core:playerLoaded')
: This line registers the event on the client-side. It listens for thecodex-core:playerLoaded
event being triggered.AddEventHandler('codex-core:playerLoaded', function() ... end)
: This is the event handler that executes the code inside the function whenever the event is triggered.GetInvokingResource()
: This function returns the name of the resource that triggered the event. In this case, it will show which resource is calling thecodex-core:playerLoaded
event.
Correct Usage Example
Here’s how to correctly call and handle this event on the client-side:
-- Registering the event when the player is loaded into the game
RegisterNetEvent('codex-core:playerLoaded')
AddEventHandler('codex-core:playerLoaded', function()
-- Your custom logic goes here
-- For example, initializing some client data or UI
-- Example: Show a welcome message on player load
TriggerEvent('chat:addMessage', {
args = { "Welcome to the server!" }
})
end)
What happens here?
The
playerLoaded
event is listened to.When the event is triggered, it prints the message and shows a welcome message in the chat.
Incorrect Usage Examples
Here are wrong ways to use the event:
-- Wrong: Incorrect function signature
RegisterNetEvent('codex-core:playerLoaded')
AddEventHandler('codex-core:playerLoaded', function(player)
print('Player loaded: ', player)
end)
Why is this incorrect?
The event
codex-core:playerLoaded
doesn’t pass aplayer
argument, so trying to use it will cause an error or incorrect behavior.player
is not passed to the event by default. You should modify the function to handle the event properly, or check for any arguments being passed
Summary of codex-core:playerLoaded client event
Correct: Always register the event using
RegisterNetEvent
before adding the event handler withAddEventHandler
.Event Name: Use the exact event name (
codex-core:playerLoaded
), and don’t change it.Function Signature: Ensure the function signature matches the expected arguments for the event.
Client Event: codex-core:playerDropped
What is this event?
The codex-core:playerDropped
event is triggered when a player disconnects or drops from the server. This is a crucial event for managing player-related activities when they leave the server. For instance, you may want to clean up any resources associated with the player, save their data, or trigger other actions as part of the player's drop-out process.
By listening to this event in the client-side script, you can react when players disconnect or drop, and perform necessary tasks such as logging, updating server states, or clearing memory.
Here’s a simple example of how to handle it:
-- Correct usage example
RegisterNetEvent('codex-core:playerDropped')
AddEventHandler('codex-core:playerDropped', function()
-- This is where you can add logic for when the player drops
print('^3codex-core:playerDropped^0 triggered on resource ^3'..GetInvokingResource()..'^0.')
end)
Detailed Explanation of the Code
RegisterNetEvent: This function registers the event
codex-core:playerDropped
so that it can be listened to and triggered when the player drops.AddEventHandler: This function attaches a handler that will be executed when the event is triggered. In this case, the handler prints a message to the console that shows which resource triggered the event.
GetInvokingResource: This function fetches the name of the resource that called the event.
📢 Client Event: codex-core:notification
What is this event?
The codex-core:notification
event is used to display notifications to the player. It supports two different notification systems based on the framework being used: Vorp or RSG. The event takes in three parameters:
message
: The message to be displayed in the notification.duration
: How long the notification should be visible on the screen (in seconds).type
: The type of notification (e.g.,inform
,success
,error
), which determines the notification’s style and color.
The event determines which framework is being used and shows the notification accordingly.
Key Elements of the Code:
Core Framework Check:
The event checks which core framework is being used by looking at the
CodexCore_CFG.Core
variable.It supports two frameworks:
'vorp'
and'rsg'
.
For Vorp Framework:
It uses the
lib.notify
function to display a notification with advanced options such as a custom title, message description, notification type, and animation.The
position
specifies where the notification should appear on the screen, and theiconAnimation
defines the visual effect used in the notification.
For RSG Framework:
It uses a simpler notification, with only the message and duration passed as parameters.
RSG Trigger
-- Correct usage example TriggerEvent('codex-core:notification', 'Your quest has been completed!', 5, 'success')
Vorp Core Trigger
-- Correct usage example TriggerEvent('codex-core:notification', 'Your quest has been completed!', 5, 'success')
Summary
The codex-core:notification
event is a powerful way to show notifications based on the framework you're using (Vorp or RSG). Make sure to provide the correct parameters when triggering the event for it to function as expected:
message
: The text displayed in the notification.duration
: How long the notification will stay visible (in seconds).type
: The type of notification (inform
,success
,error
, etc.).
Ensure that all the parameters are correctly formatted to avoid errors
What went wrong in the incorrect example?
Wrong event name printed: The message incorrectly mentions the event
codex-core:playerLoaded
, which is completely unrelated to theplayerDropped
event. This can cause confusion, as the player drop event (codex-core:playerDropped
) was supposed to be triggered, notplayerLoaded
.Potential issue with logic: The incorrect print message could mislead developers, causing them to troubleshoot an issue where the wrong event is referenced. It’s important that the message in the print statement corresponds to the actual event being triggered.
Correct vs Incorrect Event UsageCorrect Event:
Incorrect Event :
-- Incorrect print message for player drop event RegisterNetEvent('codex-core:playerDropped') AddEventHandler('codex-core:playerDropped', function() -- Incorrect event printed for the player drop end)
⚙️ CodexCore Functions Documentation
🧠 CodexCore.RequestCoreAPI()
CodexCore.RequestCoreAPI()
What does it do? Returns the core object from either the Vorp or RSG framework, based on the current config.
✅ Correct Example
local core = CodexCore.RequestCoreAPI()
-- Use 'core' for further interaction
❌ Wrong Example
local core = CodexCore.RequestCoreAPI()
CoreFunction() -- ⚠️ 'CoreFunction' is not defined
🎮 CodexCore.IsLoaded()
CodexCore.IsLoaded()
What does it do?
Checks if the player is loaded into a session. Returns true
or false
.
✅ Correct Example
if CodexCore.IsLoaded() then
print("✅ Player is in session")
end
❌ Wrong Example
if CodexCore.IsLoaded() == false then -- ❌ Use `if not CodexCore.IsLoaded() then`
end
🆔 CodexCore.GetCharacterIdentifier()
CodexCore.GetCharacterIdentifier()
What does it do?
Returns the player's character ID (CharId
for Vorp, cid
for RSG).
✅ Correct Example
local charId = CodexCore.GetCharacterIdentifier()
print("Character ID: " .. charId)
❌ Wrong Example
local charId = CodexCore.GetCharacterIdentifier()
print(charId.name) -- ❌ It's a string, not a table
👷 CodexCore.GetJob()
CodexCore.GetJob()
What does it do? Returns the player's job name.
✅ Correct Example
local job = CodexCore.GetJob()
print("Job: " .. job)
❌ Wrong Example
local job = CodexCore.GetJob()
print(job.name) -- ❌ 'job' is already a string
🎖️ CodexCore.GetJobGrade()
CodexCore.GetJobGrade()
What does it do?
Returns the player's job grade. RSG always returns 0
.
✅ Correct Example
local grade = CodexCore.GetJobGrade()
print("Job grade: " .. grade)
❌ Wrong Example
local grade = CodexCore.GetJobGrade()
print(grade.rank) -- ❌ It's a number, not a table
💵 CodexCore.GetMoney()
CodexCore.GetMoney()
What does it do?
Returns the player's money balance (Money
for Vorp, cash
for RSG).
✅ Correct Example
local money = CodexCore.GetMoney()
print("Money: " .. money)
❌ Wrong Example
local money = CodexCore.GetMoney()
print(money.amount) -- ❌ It's a number, not a table
🪙 CodexCore.GetGold()
CodexCore.GetGold()
What does it do? Returns the player's gold balance.
✅ Correct Example
local gold = CodexCore.GetGold()
print("Gold: " .. gold)
❌ Wrong Example
local gold = CodexCore.GetGold()
print(gold.value) -- ❌ It's a number, not a table
🧑🤝🧑 CodexCore.GetGroup()
CodexCore.GetGroup()
What does it do?
Returns the player's group. RSG always returns 'user'
.
✅ Correct Example
local group = CodexCore.GetGroup()
print("Group: " .. group)
❌ Wrong Example
local group = CodexCore.GetGroup()
print(group.name) -- ❌ It's already a string
📡 CodexCore.TriggerServerCallback(name, callback, ...)
CodexCore.TriggerServerCallback(name, callback, ...)
What does it do? Triggers a server-side callback with parameters and receives the response via a callback function.
✅ Correct Example
CodexCore.TriggerServerCallback('my:server:callback', function(result)
print("Result: " .. result)
end, 'param1')
❌ Wrong Example
CodexCore.TriggerServerCallback('callbackName') -- ❌ Missing callback function
🗺️ CodexCore.AddBlipForCoords(x, y, z, sprite, name, color)
CodexCore.AddBlipForCoords(x, y, z, sprite, name, color)
What does it do? Adds a map blip at the specified location with customization.
✅ Correct Example
local blip = CodexCore.AddBlipForCoords(123.4, 567.8, 30.0, 1, "My Blip", 2)
❌ Wrong Example
CodexCore.AddBlipForCoords(123, 456, 789) -- ❌ Missing sprite/name/color
These examples show how you can integrate your existing server-side events and exports with client-side functionality to interact with the town supplies system, perform actions like resupplying or refreshing, and handle the received data.
Last updated
Was this helpful?