PDA

View Full Version : UE2 - UT2kX Altering MessageTrigger to write Message to Log


Superbabs84321
27th Aug 2010, 09:22 AM
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?

class MessageTrigger extends Triggers;

var() enum EMT_MessageType
{
EMT_Default,
EMT_CriticalEvent,
EMT_DeathMessage,
EMT_Say,
EMT_TeamSay,
EMT_WriteToLog
} 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;
case EMT_WriteToLog : MSGType = 'WriteToLog'; break;
default : MSGType = 'StringMessagePlus'; break;
}

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

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

brold9999
27th Aug 2010, 05:09 PM
Firstly, do not alter default packages. (http://wiki.beyondunreal.com/Legacy: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


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
30th Aug 2010, 06:02 AM
Firstly, do not alter default packages. (http://wiki.beyondunreal.com/Legacy: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


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
30th Aug 2010, 06:39 AM
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
30th Aug 2010, 06:48 AM
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.