Security HUD
System Watchdog
×
Threads Scanned
-- / --
SYS. LOAD --%
AI SHIELD ACTIVE
DMCA Policy
×

📋 DMCA Compliance

This platform and community fully complies with the Digital Millennium Copyright Act (DMCA) and international copyright laws. We take all copyright protection seriously.

🛡️ Copyright Protection

If you believe a posted item belongs to you or violates your copyright, you may file a DMCA takedown request through our official channels. Upon receiving a valid claim, the infringing content will be removed within 24 hours.

What's new
×
Fiveguard

Guide Log Keeping Through Webhook

Ares

VAG
Admin
Joined
May 6, 2021
Messages
547
Reaction score
97,400
Points
411
Location
root
Website
vag.gg
Hello

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