22
33local DISCORD_WEBHOOK = " "
44local DISCORD_NAME = " System"
5- -- local DISCORD_IMAGE = "" !coming soon!
5+ local STEAM_KEY = " "
6+ local DISCORD_IMAGE = " https://pbs.twimg.com/profile_images/847824193899167744/J1Teh4Di_400x400.jpg" -- default is FiveM logo
67
78-- DON'T EDIT BELOW THIS
89
9-
10- -- PerformHttpRequest(DISCORD_WEBHOOK, function(err, text, headers) end, 'POST', json.encode({username = DISCORD_NAME, content = "**Serverlogging is ONLINE**"}), { ['Content-Type'] = 'application/json' })
11-
10+ PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = " **Discord Webhook is ONLINE**" }), { [' Content-Type' ] = ' application/json' })
1211
1312AddEventHandler (' chatMessage' , function (source , name , message )
14- PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = name .. " [" .. source .. " ]" , content = message }), { [' Content-Type' ] = ' application/json' })
13+ -- print(tonumber(GetIDFromSource('steam', source), 16)) -- DEBUGGING
14+ -- print('https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .. STEAM_KEY .. '&steamids=' .. tonumber(GetIDFromSource('steam', source), 16))
15+ if STEAM_KEY == ' ' or STEAM_KEY == nil then
16+ PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = name .. " [" .. source .. " ]" , content = message }), { [' Content-Type' ] = ' application/json' })
17+ else
18+ PerformHttpRequest (' https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .. STEAM_KEY .. ' &steamids=' .. tonumber (GetIDFromSource (' steam' , source ), 16 ), function (err , text , headers )
19+ local image = string.match (text , ' "avatarfull":"(.-)","' )
20+ -- print(image) -- DEBUGGING
21+ return PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = name .. " [" .. source .. " ]" , content = message , avatar_url = image , tts = false }), { [' Content-Type' ] = ' application/json' })
22+ end )
23+ end
1524end )
1625
1726AddEventHandler (' playerConnecting' , function ()
18- PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = " ```" .. GetPlayerName (source ) .. " connecting ```" }), { [' Content-Type' ] = ' application/json' })
27+ PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = " ```CSS \n " .. GetPlayerName (source ) .. " connecting\n ```" , avatar_url = DISCORD_IMAGE }), { [' Content-Type' ] = ' application/json' })
1928end )
2029
2130AddEventHandler (' playerDropped' , function (reason )
22- PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = " ```" .. GetPlayerName (source ) .. " left ( " .. reason .. " )```" }), { [' Content-Type' ] = ' application/json' })
31+ PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = " ```fix \n " .. GetPlayerName (source ) .. " left ( " .. reason .. " )\n ```" , avatar_url = DISCORD_IMAGE }), { [' Content-Type' ] = ' application/json' })
2332end )
2433
2534RegisterServerEvent (' playerDied' )
2635AddEventHandler (' playerDied' ,function (killer ,reason )
27- if killer == " **Invalid**" then -- Can't figure out what's generating invalid, it's late. If you figure it out, let me know. I just handle it as a string for now.
36+ if killer == " **Invalid**" then
2837 reason = 2
2938 end
3039 if reason == 0 then
31- -- TriggerClientEvent('showNotification', -1,"~o~".. GetPlayerName(source).."~w~ committed suicide. ")
3240 PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = GetPlayerName (source ) .. " committed suicide" }), { [' Content-Type' ] = ' application/json' })
3341 elseif reason == 1 then
34- -- TriggerClientEvent('showNotification', -1,"~o~".. killer .. "~w~ killed ~o~"..GetPlayerName(source).."~w~.")
3542 PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = GetPlayerName (source ) .. " was killed by: " .. killer }), { [' Content-Type' ] = ' application/json' })
3643 else
37- -- TriggerClientEvent('showNotification', -1,"~o~".. GetPlayerName(source).."~w~ died.")
3844 PerformHttpRequest (DISCORD_WEBHOOK , function (err , text , headers ) end , ' POST' , json .encode ({username = DISCORD_NAME , content = GetPlayerName (source ) .. " died" }), { [' Content-Type' ] = ' application/json' })
3945
4046 end
41- end )
47+ end )
48+
49+ function GetIDFromSource (Type , ID ) -- (Thanks To WolfKnight [forum.FiveM.net])
50+ local IDs = GetPlayerIdentifiers (ID )
51+ for k , CurrentID in pairs (IDs ) do
52+ local ID = stringsplit (CurrentID , ' :' )
53+ if (ID [1 ]:lower () == string.lower (Type )) then
54+ return ID [2 ]:lower ()
55+ end
56+ end
57+ return nil
58+ end
59+
60+ function stringsplit (input , seperator )
61+ if seperator == nil then
62+ seperator = ' %s'
63+ end
64+
65+ local t = {} ; i = 1
66+
67+ for str in string.gmatch (input , ' ([^' .. seperator .. ' ]+)' ) do
68+ t [i ] = str
69+ i = i + 1
70+ end
71+
72+ return t
73+ end
0 commit comments