Codex Studios
Visit our Tebex StoreOur Discord
  • ๐Ÿ‘‹Welcome to Codex Studios
  • Overview
    • ๐Ÿ’กAbout Us
    • โœจOur Features
  • ๐Ÿ’…RedM-Scripts
    • ๐ŸŒ[Codex Studios] : Core
      • Client Side
      • Server Side - CodexCore API
      • Config
      • ๐Ÿ“ Client Side (clientside.lua)
      • ๐Ÿงพ Server Side (serverside.lua)
      • ๐Ÿ›ก๏ธCodexCore Security Module
      • ๐Ÿ—’๏ธSecurity Detailed Explanation
      • ๐Ÿ”Client-Side: Securing Event Triggers
      • ๐Ÿ”’Server-Side: Securing Event Triggers
    • ๐Ÿ’ช[Codex Studios] : Trust Level
      • Client Side
      • Config
      • SQL
  • ๐Ÿ“ฆ[Codex Studios]: Supplies System
    • Client Side
    • Server-Side Town Supplies
    • Config
    • ๐Ÿช›Examples and Commands
    • Sql Updated
Powered by GitBook
On this page
  • ๐Ÿ“ข Client Event: codex-core:playerLoaded
  • ๐Ÿ“ข How to Use the Event?
  • Client Event: codex-core:playerDropped
  • ๐Ÿ“ข Client Event: codex-core:notification
  • โš™๏ธ CodexCore Functions Documentation

Was this helpful?

  1. RedM-Scripts
  2. [Codex Studios] : Core

Client Side

Previous[Codex Studios] : CoreNextServer Side - CodexCore API

Last updated 1 month ago

Was this helpful?



๐Ÿ“ข Client Event: codex-core:playerLoaded

What is the 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 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.

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 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


Summary of codex-core:playerLoaded client event

  • 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.


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:

  1. 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'.

  2. 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.

  3. For RSG Framework:

    • It uses a simpler notification, with only the message and duration passed as parameters.

  4. RSG Trigger

    -- Correct usage example
    TriggerEvent('codex-core:notification', 'Your quest has been completed!', 5, 'success')
  5. 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:

  1. message: The text displayed in the notification.

  2. duration: How long the notification will stay visible (in seconds).

  3. 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 vs Incorrect Event Usage

    • Correct 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()

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()

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()

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()

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()

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()

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()

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()

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, ...)

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)

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.

๐Ÿ’…
๐ŸŒ