Skip to content

Commit b582247

Browse files
committed
v1.2 Big update
-Discord webhook active message -Discord webhook now has players icon (steam api key required) -Discord webhook now has color -Discord webhook System icon (default icon is FiveM)
1 parent 071b978 commit b582247

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Server Logging
2+
A FiveM Plugin
3+
4+
# Installation
5+
1. Download `Serverlogging`!
6+
2. Install it into `/resources/`.
7+
3. Enter your webhook url in `server.lua`
8+
4. Make a Steam API Key in https://steamcommunity.com/dev/apikey and paste the key in `server.lua`
9+
5. Start the plugin
10+
6. Have fun!
11+
12+
For more information goto:
13+
https://forum.fivem.net/t/server-log-discord-webhook/482062

Serverlogging/server.lua

+44-12
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,72 @@
22

33
local DISCORD_WEBHOOK = ""
44
local 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

1312
AddEventHandler('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
1524
end)
1625

1726
AddEventHandler('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' })
1928
end)
2029

2130
AddEventHandler('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' })
2332
end)
2433

2534
RegisterServerEvent('playerDied')
2635
AddEventHandler('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

Comments
 (0)