UE2 - UT2kX Altering MessageTrigger to write Message to Log

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Superbabs84321

New Member
Oct 19, 2009
24
0
0
To get some statistics (for a single player level) I'd like to alter my MessageTrigger to write the Messages to a Log File (.txt) instead of dumping them on the screen. I slightly altered the MessageTrigger code, but I can't get my trigger to open a log file. Most probably I can't seem to figure to which class the logfile should be appointed to. Here is my code. I have highlighted my changes. Anyone got any advice?

Code:
class MessageTrigger extends Triggers;

var()	enum EMT_MessageType
{
	EMT_Default,
	EMT_CriticalEvent,
	EMT_DeathMessage,
	EMT_Say,
	EMT_TeamSay,
	[COLOR="red"]EMT_WriteToLog[/COLOR]
} MessageType;

var() localized string	Message;

var() byte		Team;


event Trigger( Actor Other, Pawn EventInstigator )
{
	local name		MSGType;
	local Controller	C;
	local PlayerController	P;

	switch ( MessageType )
	{
		case EMT_CriticalEvent	: MSGType = 'CriticalEvent';		break;
		case EMT_DeathMessage	: MSGType = 'xDeathMessage';		break;
		case EMT_Say		: MSGType = 'SayMessagePlus';		break;
		case EMT_TeamSay	: MSGType = 'TeamSayMessagePlus';	break;
[COLOR="red"]		case EMT_WriteToLog	: MSGType = 'WriteToLog';			break;[/COLOR]
		default			: MSGType = 'StringMessagePlus';	break;
	}

	for ( C=Level.ControllerList; C!=None; C=C.NextController )
	{
		P = PlayerController(C);
		if ( P != None && CheckTeam(P) )
		{
			[COLOR="Red"]if (MSGType == 'WriteToLog')
			{
				OpenLog('test');
				Logf(Message);
				CloseLog();
			}    
			else[/COLOR]
			{
				P.TeamMessage(C.PlayerReplicationInfo, Message, MSGType);
			}
		}
	}
}

Here is the FileLog from wiki:
http://wiki.beyondunreal.com/UE2:FileLog_(UT2004)
 
Last edited:

brold9999

New Member
Apr 5, 2009
142
0
0
Firstly, do not alter default packages. Create a new subclass instead of editing the existing MessageTrigger.

Secondly, you have to spawn a FileLog, and call the OpenLog, Logf, and CloseLog on it; the functions aren't visible from the MessageTrigger class.

eg

Code:
local FileLog logObject;

logObject = spawn(class'FileLog');
logObject.openLog(filename);
logObject.logf(message);
logObject.closeLog();
logObject.destroy();

Depending on your purposes, you may want to keep the FileLog around for future writes instead of closing and destroying it immediately.

Also, you may want to move the code that does it outside the loop, else it will write to the log once for each person on the player's team.
 

Superbabs84321

New Member
Oct 19, 2009
24
0
0
Firstly, do not alter default packages. Create a new subclass instead of editing the existing MessageTrigger.

Yes, I know it's kinda sloppy but this level is for a research project so it's not supposed to be distributed or something.

Secondly, you have to spawn a FileLog, and call the OpenLog, Logf, and CloseLog on it; the functions aren't visible from the MessageTrigger class.

Yes, I was already expecting that I had to construct some entity like that but I didn't know how (I only got some experience with Java) and I didn't know which class to call.

eg

Code:
local FileLog logObject;

logObject = spawn(class'FileLog');
logObject.openLog(filename);
logObject.logf(message);
logObject.closeLog();
logObject.destroy();

Thanks! That works!

Depending on your purposes, you may want to keep the FileLog around for future writes instead of closing and destroying it immediately.

You are very right. That would be quite a bit more elegant, but I am not looking for elegant or robust code. I just want it to work with the least amount of effort.

Also, you may want to move the code that does it outside the loop, else it will write to the log once for each person on the player's team.

THe level is only singleplayer but did so nonetheless.

Thank you very much for your help so far. The code works!

PS

I'd like to print also the levelname and the current time (either the gametime, the runtime, or the systemtime will do) together with the message, but I am not sure yet how I access these (wiki says they should be in the LevelInfo). If you got a suggestion...
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Yes, I know it's kinda sloppy but this level is for a research project so it's not supposed to be distributed or something.

The "do not alter default packages" thing affects the game itself, not individual levels. Just by saving a stock package (even without actual modifications) you basically render your entire game useless for online play.
 

Superbabs84321

New Member
Oct 19, 2009
24
0
0
The "do not alter default packages" thing affects the game itself, not individual levels. Just by saving a stock package (even without actual modifications) you basically render your entire game useless for online play.

Perhaps I should have made myself more clear: Not only is the level only for research purposes, but the whole game installation. The computer isn't even connected to the internet.