ScriptingExamples/LogChatMessagesToFile: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 00:07, 8 February 2019
Description
This code adds a line of text to ChatLog.txt, (in the resource folder), when any player types a chat message.
Code
JavaScript, Server-Side:
addEventHandler('onPlayerChat', function(event,client,message)
{
addToLog(client.name+': '+message);
});
function addToLog(text)
{
var file2 = openFile('ChatLog.txt', false);
if(!file2)
return;
var filePreviousData = file2.readBytes(file2.length);
file2.close();
var file = openFile('ChatLog.txt', true);
if(!file)
return;
file.writeBytes(filePreviousData+text+"\r\n");
file.close();
}