πŸ”¨Discord.lua

The discord.lua file manages logging and integration with Discord for the Collectibles Pickup Script. It allows you to track player activity, such as when collectables are picked up, and send detailed


Configuration Options

πŸ”§ sendToDiscord

This function handles sending logs when specific actions occur in the script. It can be extended to support additional events as needed.

Parameters:

  • source: The player’s server ID.

  • type: The type of event to log (e.g., 'collected').

  • args: A table containing event-specific details.


Supported Event Types

1. collected

Logs details when a player collects a collectable item.

Arguments in args:

Field

Type

Description

identifier

String

The player's license or unique identifier.

coords

Table

The coordinates where the collectable was picked up.

totalPickups

Integer

The total number of collectables collected by the player.

timestamp

String

The timestamp of when the collectable was picked up.

Log Format Example:

When a player collects a collectable, the log will appear as:

πŸ‘€ **Player:** JohnDoe (ID: 1)  
πŸ”‘ **License:** license:abcdef1234567890  
πŸ“ **Coords:** {"x":123.45,"y":678.90,"z":21.0}  
🎯 **Total collectables:** 5  
πŸ•’ **TimeStamp:** 2025-01-01 12:00:00

Default Behavior

The sendToDiscord function is preconfigured to use QBCore's logging system (qb-log). By default, it logs 'collected' events to a specific Discord channel.

Default Log Implementation:

TriggerEvent('qb-log:server:CreateLog', 
    'collectables', 
    'πŸ“¦ **Collectable Collected**', 
    'blue', 
    logMessage
)

Extending the Configuration

The sendToDiscord function is designed to be easily extended for additional events or frameworks. Here’s an example of how you can add a new event type:

Example: Adding a rewardClaimed Event

Modify the sendToDiscord function as follows:

if type == 'rewardClaimed' then
    local logMessage = string.format(
        "πŸ‘€ **Player:** %s (ID: %d)\n" ..
        "🎁 **Reward Claimed:** %s\n" ..
        "🎯 **Total Rewards:** %d\n" ..
        "πŸ•’ **TimeStamp:** %s",
        GetPlayerName(source), source, args.rewardName, args.totalRewards, args.timestamp
    )

    TriggerEvent('qb-log:server:CreateLog', 'rewards', '🎁 **Reward Claimed**', 'green', logMessage)
end

At a Glance

Option

Description

sendToDiscord

Sends logs to Discord or a logging system based on the event type (collected, etc.).

collected

Logs details about collected items, including player info, coordinates, and timestamps.


Tips and Recommendations

1. Adapting to Your Logging System

If your server does not use QBCore's logging, replace the qb-log call with your preferred Discord logging system, such as Discord Webhooks or another logging resource.

Example: Using Discord Webhooks

PerformHttpRequest('https://discord.com/api/webhooks/your_webhook_url', function(err, text, headers) end, 'POST', json.encode({
    username = 'Collectables Logger',
    embeds = {
        {
            title = "πŸ“¦ Collectable Collected",
            description = logMessage,
            color = 3447003 -- Blue color
        }
    }
}), {['Content-Type'] = 'application/json'})

2. Add More Event Types

Expand the sendToDiscord function to log additional events, such as reward claims, player joins, or admin actions.


Example Default Configuration

Here’s the default configuration provided in the script:

DiscordConfig = {
    sendToDiscord = function(source, type, args)
        if type == 'collected' then
            local logMessage = string.format(
                "πŸ‘€ **Player:** %s (ID: %d)\n" ..
                "πŸ”‘ **License:** %s\n" ..
                "πŸ“ **Coords:** %s\n" ..
                "🎯 **Total collectables:** %d\n" ..
                "πŸ•’ **TimeStamp:** %s",
                GetPlayerName(source), source, args.identifier, json.encode(args.coords), args.totalPickups,
                args.timestamp
            )

            TriggerEvent('qb-log:server:CreateLog', 'collectables', 'πŸ“¦ **Collectable Collected**', 'blue', logMessage)
        end
    end,
}

Last updated