Client Side
Last updated
Was this helpful?
Last updated
Was this helpful?
codex-core:playerLoaded
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.
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')
: This line registers the event on the client-side. It listens for the codex-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 the codex-core:playerLoaded
event.
Hereโs how to correctly call and handle this event on the client-side:
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.
Here are wrong ways to use the event:
Why is this incorrect?
The event codex-core:playerLoaded
doesnโt pass a player
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
Correct: Always register the event using RegisterNetEvent
before adding the event handler with AddEventHandler
.
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.
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:
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.
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 the iconAnimation
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
Vorp Core Trigger
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 the playerDropped
event. This can cause confusion, as the player drop event (codex-core:playerDropped
) was supposed to be triggered, not playerLoaded
.
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 Event:
Incorrect Event :
CodexCore.RequestCoreAPI()
What does it do? Returns the core object from either the Vorp or RSG framework, based on the current config.
โ Correct Example
โ Wrong Example
CodexCore.IsLoaded()
What does it do?
Checks if the player is loaded into a session. Returns true
or false
.
โ Correct Example
โ Wrong Example
CodexCore.GetCharacterIdentifier()
What does it do?
Returns the player's character ID (CharId
for Vorp, cid
for RSG).
โ Correct Example
โ Wrong Example
CodexCore.GetJob()
What does it do? Returns the player's job name.
โ Correct Example
โ Wrong Example
CodexCore.GetJobGrade()
What does it do?
Returns the player's job grade. RSG always returns 0
.
โ Correct Example
โ Wrong Example
CodexCore.GetMoney()
What does it do?
Returns the player's money balance (Money
for Vorp, cash
for RSG).
โ Correct Example
โ Wrong Example
CodexCore.GetGold()
What does it do? Returns the player's gold balance.
โ Correct Example
โ Wrong Example
CodexCore.GetGroup()
What does it do?
Returns the player's group. RSG always returns 'user'
.
โ Correct Example
โ Wrong Example
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
โ Wrong Example
CodexCore.AddBlipForCoords(x, y, z, sprite, name, color)
What does it do? Adds a map blip at the specified location with customization.
โ Correct Example
โ Wrong Example
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.