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

-- Call the exported function to get the town supplies

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['codex_supplies']: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:

If there’s no data:

4. How to Trigger the Command:

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

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.

Last updated

Was this helpful?