Welcome to the forum, Guest

To access forum content and all of our services, you must register or log in to the forum. Joining the forum and all content on the forum is completely free.

The world's largest FiveM Forum and GTA 5 Forum address

Hello dear member,
We work 24/7 to provide the most valuable content that will be of use to you,
you can share content and support the entire FiveM & GTA 5 community.

Guide Log Keeping Through Webhook

Meta

Super Moderator
Joined
Jul 4, 2021
Messages
188
Reaction score
297
Points
251
✌️Hello VAG Forum Family✌️

I will teach you to keep a log of the data you want of any plugin.

If you don't think your knowledge is enough, I recommend you to make a backup of the plugin.
The function I will share is not a plugin, it does not work with copy paste logic.
You need to adapt the log according to the data you want to keep.


Just paste this code at the bottom of any file on the server side of the plugin you want to log.
Code:
function dclog(xPlayer, text)
    local playerName = Sanitize(xPlayer.getName())

    local discord_webhook = "WEBHOOK"
    if discord_webhook == '' then
        return
    end
    local headers = {
        ['Content-Type'] = 'application/json'
    }
    local data = {
        ["username"] = "USERNAME",
        ["avatar_url"] = "AVATAR_URL",
        ["embeds"] = {{
            ["author"] = {
                ["name"] = playerName.. ' - ' ..xPlayer.identifier
            },
            ["color"] = 1942002,
            ["timestamp"] = os.date("!%Y-%m-%dT%H:%M:%SZ")
        }}
    }
    data['embeds'][1]['description'] = text
    PerformHttpRequest(discord_webhook, function(err, text, headers) end, 'POST', json.encode(data), headers)
end

function Sanitize(str)
    local replacements = {
        ['&'] = '&',
        ['<'] = '&lt;',
        ['>'] = '&gt;',
        ['\n'] = '<br/>'
    }

    return str
    :gsub('[&<>\n]', replacements)
    :gsub(' +', function(s)
        return ' '..('&nbsp;'):rep(#s-1)
    end)
end

Here is an example event of a plugin that I log for you to understand the logic.

Code:
RegisterServerEvent("esx_newDrugs:reward")
AddEventHandler("esx_newDrugs:reward",function(amount,typed)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer.canCarryItem(typed.."brick", math.ceil(amount)) then
        xPlayer.addInventoryItem(typed.."brick",math.ceil(amount))
        dclog(xPlayer, '**'..math.ceil(amount)..'x '..typed..'brick** elde etti.' )
    else
        TriggerClientEvent('mythic_notify:client:SendAlert', xPlayer.source, { type = 'error', text = 'Daha fazla taşıyamazsın!'})
    end
end)

There are two types of data that the function needs.
The player performing the action and the text to be logged.
You can edit the text however you want.

If there is a place that is stuck in your mind or you cannot do it, you can comment under the topic.​


GOOD FORUMS🖋️
 

Login or register to get more out of the forum!

Login or register to get more out of the forum!

Register

Creating an account on the forum is completely free.

Register now
Log in

If you have an account, please login

Log in

Theme editor

Theme customizations

Graphic Backgrounds

Granite Backgrounds