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

Was this helpful?

  1. [Codex Studios]: Supplies System

Examples and Commands

-- Add supplies to a specific town

RegisterCommand('addSupplies', function(source, args, rawCommand)
    local town = args[1]  -- The town name passed as the first argument
    local suppliesAmount = tonumber(args[2])  -- The amount of supplies to add

    if town and suppliesAmount then
        TriggerServerEvent('codex-studios-supplies:city_resupplies', town, suppliesAmount)
    else
        CodexCore.Notification("Invalid parameters. Usage: /addSupplies [town] [amount]", 2000)
    end
end, false)

-- Remove supplies from a specific town

-- Remove supplies from a specific town
RegisterCommand('removeSupplies', function(source, args, rawCommand)
    local town = args[1]  -- The town name passed as the first argument
    local suppliesAmount = tonumber(args[2])  -- The amount of supplies to remove

    if town and suppliesAmount then
        TriggerServerEvent('codex-studios-supplies:city_removesupplies', town, suppliesAmount)
    else
        CodexCore.Notification("Invalid parameters. Usage: /removeSupplies [town] [amount]", 2000)
    end
end, false)

-- Refetch the supplies data for all towns

RegisterCommand('refetchSupplies', function()
    TriggerServerEvent('codex-studios-supplies:city_supplies_refetch')
end, false)

-- Call the exported function to get the town supplies

RegisterCommand("townsupplies", function(source, args, rawCommand)
    -- Call the exported function to get the town supplies
    local townSupplies = exports['codex_supplies']:CodexStudiosGetTownSupplies()

    -- If town supplies are found, send them to the player in chat
    if #townSupplies > 0 then
        local message = "Town Supplies:\n"

        -- Iterate through the townSupplies table and format the message
        for _, townData in ipairs(townSupplies) do
            message = message .. townData.town .. ": " .. townData.supplies .. " supplies\n"
        end

        -- Send the formatted message to the player
        TriggerClientEvent('chat:addMessage', source, {
            args = { "^2[Town Supplies]^0", message }
        })
    else
        -- If no supplies data is found, notify the player
        TriggerClientEvent('chat:addMessage', source, {
            args = { "^1[Error]^0", "No town supplies data available." }
        })
    end
end, false)  -- The "false" makes the command not restricted to admins only

How it works:

  • Command registration: The RegisterCommand function registers a command (/townsupplies) that players can type in the game.

  • Fetching the supplies: When the command is triggered, it calls the exported function CodexStudiosGetTownSupplies from the resource using exports['your_resource_name']:CodexStudiosGetTownSupplies().

  • Message formatting: If the town supplies are available, it formats a message displaying the supplies for each town and sends that message back to the player using TriggerClientEvent('chat:addMessage', source, { args = {...} }).

  • Error handling: If no supplies data is found, it sends an error message back to the player.

3. Client-side Message Display:

The player will see a formatted chat message like this when they use the /townsupplies command:

[Town Supplies] 
TownName1: 50 supplies
TownName2: 120 supplies
TownName3: 30 supplies

If there’s no data:

[Error] No town supplies data available.

4. How to Trigger the Command:

In-game, players can simply type the following in the chat box to use the command:

/townsupplies

Explanation of Commands:

  • /addSupplies [town] [amount]: Adds supplies to the specified town. It triggers the server event codex-studios-supplies:city_resupplies.

  • /removeSupplies [town] [amount]: Removes supplies from the specified town. It triggers the server event codex-studios-supplies:city_removesupplies.

  • /refetchSupplies: Refetches the supplies data from the server. It triggers the server event codex-studios-supplies:city_supplies_refetch.

  • /exportSupplies: Exports the supplies data for all towns from the server. This fetches the supplies data and can be used to interact with it client-side.

PreviousConfigNextSql Updated

Last updated 1 month ago

Was this helpful?

πŸ“¦
πŸͺ›