So, I use server logs to log my players ([Release] Simple server side Logs)
The problem is that I can only use it well in server scripts. In server scripts it looks like this:
TriggerEvent("serverlog", "Player "..GetPlayerName(source).." used this function ")
According to the maker of the script, if you want to use it in client scripts you should use
TriggerServerEvent("serverlog", "text_to_log")
The problem is when I use this, my console says it’s not safe or something.
Does somebody know the problem and how to fix it?
Add this to your code:
RegisterServerEvent("serverlog")
In the same script file with AddEventHandler("serverlog", ...)
.
In Lua, you need to explicitly specify which even can be accessed from the network.
1 Like
Thx for responding.
So if i’m right, I have to make this
AddEventHandler('serverlog', function(text)
local currentDatetime = os.date("%d-%m-%Y %H:%M:%S")
local logFile,errorReason = io.open("serverLog.log","a")
if not logFile then return print(errorReason) end
local formattedLog = string.format("[%s] [Eindhoven Logs] %s",currentDatetime,text)
logFile:write(formattedLog.."\n")
logFile:close()
-- Print to console
print(formattedLog)
end)
To this:
RegisterServerEvent("serverlog")
AddEventHandler('serverlog', function(text)
local currentDatetime = os.date("%d-%m-%Y %H:%M:%S")
local logFile,errorReason = io.open("serverLog.log","a")
if not logFile then return print(errorReason) end
local formattedLog = string.format("[%s] [Eindhoven Logs] %s",currentDatetime,text)
logFile:write(formattedLog.."\n")
logFile:close()
-- Print to console
print(formattedLog)
end)
Yes, exactly that. You could’ve just tested it locally 
1 Like