[vRP] How to make discord log with names and registration number instead of user_id

So… i have spend all day tried to make a certen discord log - here are the ‘server.lua’ code

function getIdentity(_source)
	local user_id = vRP.getUserId({source})
    local _source = source
    local username = GetPlayerName(target)
    local target = vRP.getUserSource({targetID})
    vRP.getUserIdentity({targetID, function(identity)
     if identity then
       MySQL.Async.fetchAll("SELECT * FROM vrp_user_identities WHERE user_id = @user_id", {user_id = user_id}, function(cb, firstname, lastname, height)
        cb {
            --username = GetPlayerName(target),
            firstname = identity.firstname,
            lastname = identity.name,
            height = identity.registration
            }
        end)
     end
    end})
end

function discordlog(firstname, lastname, height)
    local d1name = "[Fangeflugt] Denne person mangler:"
    local d1message = "**Navn:** " .. tostring(firstname)..  " " .. tostring(lastname)..  " **CPR:** " .. tostring(height)..  ""
    PerformHttpRequest('https://discord.com/api/webhooks/8261851867921/S7jLX_-bpNz9Ec15SUp1NSJW-eH-Gr77XoBXJL0K8MYjZCy46clYN-11rMGIarspJQjG', function(err, text, headers) end, 'POST', json.encode({username = d1name, content = d1message}), { ['Content-Type'] = 'application/json' })
end

But when the log is printet, it’s says " Navn: nil nil CPR: nil "
And I ofc. know, thats becouse it’s not specificed right. And in my defence, this is my first time trying to make discord log with names instead of “user_id”.
I have looked everywhere for some code to eaither use some of, or all of it. but did’t find anything.

Hope there are someone with more experices than me.

Try this:

function discordLog(source)
    local user_id = vRP.getUserId({source})
    vRP.getUserIdentity({user_id, function(identity)
        if identity then
            local name = identity.name 
            local surname = identity.firstname
            local registration = identity.registration
            local d1name = "[Fangeflugt] Denne person mangler:"
            local d1message = "**Navn:** " .. tostring(name)..  " " .. tostring(surname)..  " **CPR:** " .. tostring(registration)..  ""
            PerformHttpRequest("<insert webhook here>", function(err, text, headers) end, 'POST', json.encode({username = d1name, content = d1message}), { ['Content-Type'] = 'application/json' })
        end
    end})
end

*if you use Dunko’s vRP
Also, I think it is better that you don’t post webhooks here.

won’t worry, it’s not real webhook. i changed it to something wierd

But I know what you mean and sure won’t do it in the furture.
I try it know

Nope. there are an error:

SCRIPT ERROR: @<folder name>/server.lua:23: attempt to call a nil value (global 'discordlog')

You didn’t use capital “L” for the call, use “discordLog”. Also, don’t forget to specify the source.

woaw. did’t see hahaha

But… got this now:

SCRIPT ERROR: @vrp/lib/utils.lua:43: attempt to call a nil value (upvalue 'callback')

But have never made an edit in those files…

Can you give me the snippet where you call the ‘discordLog’ function?

Server.lua:

function discordLog(source)
    local user_id = vRP.getUserId({source})
    vRP.getUserIdentity({user_id, function(identity)
        if identity then
            local name = identity.name 
            local surname = identity.firstname
            local registration = identity.registration
            local d1name = "[Fangeflugt] Denne person mangler:"
            local d1message = "**Navn:** " .. tostring(name)..  " " .. tostring(surname)..  " **CPR:** " .. tostring(registration)..  ""
            PerformHttpRequest("<insert webhook here>", function(err, text, headers) end, 'POST', json.encode({username = d1name, content = d1message}), { ['Content-Type'] = 'application/json' })
        end
    end})
end

RegisterServerEvent('EscapedLogs') -- And yes, there are no reason for me to do this.
AddEventHandler('EscapedLogs',function(source)
    discordLog()
end)

Client.lua

Citizen.CreateThread(function()
    while true do
      Citizen.Wait(0)
      local pos = GetEntityCoords(GetPlayerPed(-1), true)
        if(Vdist(pos.x, pos.y, pos.z, 1625.4057617188,2569.2751464844,45.564865112305+1) < 1.4)then
          DrawMarker(27, 1625.4057617188,2569.2751464844,44.564865112305 - 1.00, 0, 0, 0, 0, 0, 0, 2.0001, 2.0001, 1.5001, 0, 180, 249,165, false, false, 0,true)
          if GetDistanceBetweenCoords(1625.4057617188,2569.2751464844,45.564865112305, GetEntityCoords(GetPlayerPed(-1))) < 3 then
            DrawText3Ds(1625.4057617188,2569.2751464844,45.564865112305+1, "[~g~E~s~] Flygt fra fængslet [Pris: 1.000.000kr].")
            if IsControlJustPressed(1, 51) then -- E
              --if vRP.hasPermission({user_id, "ejer"}) then
              while not PrepareAlarm("PRISON_ALARMS") do
                Citizen.Wait(0)
              end
                TriggerServerEvent('EscapedLogs') -- Here
                StartAlarm("PRISON_ALARMS", 1)
                SetEntityHeading(PlayerPedId(), 356.957)
                SetEntityCoordsNoOffset(PlayerPedId(), 1643.7371826172,2585.1936035156,45.564861297607, 0)
                SendNotifcation('Stretch', 'Din kontakt!', 'Godt gået! Skynd dig væk, men smut forbi mig. Jeg kan hjælpe dig med den fodlænke du har på dig.')
                SetNewWaypoint(372.28405761719, -2041.1107177734)
            --end
            end
        end
      end
    end
  end)

Replace “discordLog(source)” with “discordLog()” and try again.

1 Like

Yes! it worked! thx!

You’re welcome. Glad it worked! Have a great day/night!

you too!