- 116
- 26
- Версия SA-MP
-
- 0.3.7 (R1)
- 0.3.7-R2
- 0.3.7-R3
I'm trying to create a Script error log, so that the errors are sent to a discord webhook URL, but I can't do it, I need it too much, it's something very useful for me and maybe for more people...
Code:
local nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(playerPed)))
local webhookURL = "url"
require('encoding').default = ('CP1251')
local u8 = require('encoding').UTF8
local url = require("socket.url")
local http = require("socket.http")
local ltn12 = require("ltn12")
function onSystemMessage(msg, type, scr)
if scr == thisScript() and type == 3 then
if msg == "Script died due to an error." then
return
else
sampShowDialog(252, 'Error', '{FFFFFF}An unexpected error occurred in the script {00BFFF}'..thisScript().filename..'{FFFFFF}.\nIf this error repeats, the script will send the error to the creator for correction.\nError code: \n'..msg, 'Close', _, 0)
local discordMessage = '{"username": "' .. nick .. '", "content": "Script error: '.. u8:encode(msg) ..'"}'
http.request{
url = webhookURL,
method = "POST",
headers = {
["Content-Type"] = "application/json",
["Content-Length"] = tostring(#discordMessage)
},
source = ltn12.source.string(discordMessage)
}
end
end
end