vMenu Logging

I am still somewhat new to development, as well as have a little more than a basic knowledge of coding. But i was wondering the easiest way to log if a specific permission is toggled, then have that log output
to either discord or fivemanage. To be truthful we have some players/officers abusing the “Names above players” function and instead of scrapping it for everyone as it is useful at times, we just want a way to check if someone in abusing it, in real time. Any information is helpful thank you.

Heya!
Logging depends on what you know from the script itself.
For example if you know vMenu is calling this event “vMenu:shownames” you can easily capture that event and do something else with it like this

function sendToDiscord(color, name, message, footer)
  local embed = {
        {
            ["color"] = color,
            ["title"] = "**".. name .."**",
            ["description"] = message,
            ["footer"] = {
                ["text"] = footer,
            },
        }
    }

  PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end

AddEventHandler("vMenu:shownames", function() 
  local src = source
  print("event called by ", src)
  sendToDiscord(16753920, "System", "vMenu Names shown", "YourFooter")
end)

Discord Source from: [How-To] Send Discord Webhooks

However it is much harder to log a event from a script that is obfuscated.
The way you can do it in a simple way is to make an extra handler and block the other one

For example if we use vMenu:shownames again and if ur lucky its triggered server sided and you have access to the events source.
You could just remove the “RegisterNetEvent(…)” Part over the handler and create your own handler that handles the request like this

-- same discord function like the top here

RegisterNetEvent("whateveryouwantonamethis")
AddEventHandler("whateveryouwantonamethis", function() 
-- log the event with discord same as top
TriggerEvent("vMenu:shownames", args)
end)

This will work because you removed “RegisterNetEvent()” from the vMenus code so it wont be callable from clients anymore and will only be callable from server sided scripts. Remember this when looking at the code at the top.

There are a lot of ways to log events and its also a very big part of anticheat development for example if you want to make secured events.

Hope this helps. Feel free to ask any questions :smiley:

I fixed the above code by debugging it, just to learn that the footer being blank on the function outputs were causing part of the issue. But i am still needing the event trigger for the toggling of “Overhead Player Names” unless it is client side, I will post the corrected code below, with the debug functions disabled, due to the fact it will cause a lot of console printing even when successful, and I recommend only using it if the webhook fails to output in discord.

--================================--
--      B-vMenuLogs 1.0           --
--      by BreezyTheDev           --
--		GNU License v3.0		  --
--================================--

-- Webhook Configuration
webhookmsg = 'https://discord.com/api/webhooks/1212407301420486758/P3v8xl3ZfwovWcC4o1uDgrEf360VqvWL0HaXgiq8fvVl5ky61T_J8Y-Qdt5BBJ2JeakH' -- Webhook for the vMenu message logger.
webhookvmenu = 'https://discord.com/api/webhooks/1212234814590160946/aNzexPiEcuqyOVEoxI3IbNB664i45cCsiv-B6ps65AjlC6nCy2M40OcRYCklf1a_hvOe' -- Webhook for the following events: ClearArea, KillPlayer, & SummonPlayer.
whcolor = '44270' -- 44270 is the preset color.

-- Net Events

-- (Credits: FreeStyle#0001 | https://github.com/FSSynthetic/Private-vMenu-Message-Logger)
RegisterNetEvent('vMenu:SendMessageToPlayer', function(target, message)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    local targetName = GetPlayerName(target)
    sendToDiscord(webhookmsg, whcolor, "vMenu Event: Private Message", "**From:**\n**ID: "..sourceID.."** | "..sourceName.."\n\n**To:**\n**ID: "..target.."** | "..targetName.."\n\n**Message:** `"..message.."`")  
end)

RegisterNetEvent('vMenu:ClearArea', function()
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Clear Area", "**ID: "..sourceID.."** | "..sourceName.." has cleared the area")
end)
--[[ This event is not functioning due to wrong event name - KP
RegisterNetEvent('vMenu:ToggleOverheadNames', function(result)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Overhead Names", "**ID: "..sourceID.."** | "..sourceName.." has toggled names to "..result)
end) ]]

RegisterNetEvent('vMenu:KillPlayer', function(target)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    local targetName = GetPlayerName(target)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Kill Player", "**ID: "..sourceID.."** | "..sourceName.. " has killed ".."**ID: "..target.."** | ".. targetName)
end)

RegisterNetEvent('vMenu:SummonPlayer', function(target)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    local targetName = GetPlayerName(target)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Summon Player", "**ID: "..sourceID.."** | "..sourceName.. " has summoned ".."**ID: "..target.."** | ".. targetName)
end)

RegisterNetEvent('vMenu:UpdateServerWeather', function(result)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Server Weather", "**ID: "..sourceID.."** | "..sourceName.." has updated the weather to: **"..result.."**")
end)

RegisterNetEvent('vMenu:UpdateServerTime', function(result)
    local sourceID = source
    local sourceName = GetPlayerName(sourceID)
    sendToDiscord(webhookvmenu, whcolor, "vMenu Event: Server Time", "**ID: "..sourceID.."** | "..sourceName.." has updated the time to: **"..result..":00**")
end)

-- Functions
function sendToDiscord(webhook, color, name, message, footer)
    local embed = {
        color = color,
        title = name,
        description = message,
        footer = {
            text = footer or "", -- Use an empty string if footer is nil
        }
    }

    local payload = {
        embeds = { embed }
    }
    
    -- This is the function that sends the embed above as a Discord webhook message.
    PerformHttpRequest(webhook, function(statusCode, responseText, headers)
        --[[if statusCode ~= 204 then
            print("Error sending message to Discord. Status code: " .. tostring(statusCode))
            print("Response text: " .. tostring(responseText))
            print("Headers: " .. json.encode(headers))
            print("Payload sent: " .. json.encode(payload))
        else
            print("Message sent successfully to Discord.")
        end]]
    end, 'POST', json.encode(payload), { ['Content-Type'] = 'application/json' })
end


-- VERSION CHECKER
expectedName = "B-vMenuLogs" -- This is the resource and is not suggested to be changed.
resource = GetCurrentResourceName()

-- check if resource is renamed
if resource ~= expectedName then
    print("^1[^4" .. expectedName .. "^1] WARNING^0")
    print("Change the resource name to ^4" .. expectedName .. " ^0or else it won't work!")
end


print("^0This resource was created by ^5Breezy#0001 ^0for support you can join his ^5discord: ^0https://discord.gg/zzUfkfRHzP")

-- check if resource version is up to date
PerformHttpRequest("https://raw.githubusercontent.com/BreezyTheDev/B-vMenuLogs/main/fxmanifest.lua", function(error, res, head)
    i, j = string.find(tostring(res), "version")
    res = string.sub(tostring(res), i, j + 6)
    res = string.gsub(res, "version ", "")

    res = string.gsub(res, '"', "")
    resp = tonumber(res)
    verFile = GetResourceMetadata(expectedName, "version", 0)
    if verFile then
        if tonumber(verFile) < resp then
            print("^1[^4" .. expectedName .. "^1] WARNING^0")
            print("^4" .. expectedName .. " ^0is outdated. Please update it from ^5https://github.com/BreezyTheDev/B-vMenuLogs^0| Current Version: ^1" .. verFile .. " ^0| New Version: ^2" .. resp .. " ^0|")
        elseif tonumber(verFile) > tonumber(resp) then
            print("^1[^4" .. expectedName .. "^1] WARNING^0")
            print("^4" .. expectedName .. "s ^0version number is higher than we expected. | Current Version: ^3" .. verFile .. " ^0| Expected Version: ^2" .. resp .. " ^0|")
        else
            print("^4" .. expectedName .. " ^0is up to date | Current Version: ^2" .. verFile .. " ^0|")
        end
    else
        print("^1[^4" .. expectedName .. "^1] WARNING^0")
        print("You may not have the latest version of ^4" .. expectedName .. "^0. A newer, improved version may be present at ^5https://github.com/BreezyTheDev/B-vMenuLogs")
    end
end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.