Log Chat Messages to File

From GTA Connected
Jump to navigation Jump to search

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();
}