Notice: Failed to invoke Pygments: [Called from MediaWiki\SyntaxHighlight\SyntaxHighlight::highlightInner in /home/pi/www/gtac/wiki/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php at line 334] in /home/pi/www/gtac/wiki/wiki/includes/debug/MWDebug.php on line 507
Log Chat Messages to File - GTA Connected

Log Chat Messages to File

Revision as of 00:07, 8 February 2019 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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