1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.

UE2 - UT2kX Altering MessageTrigger to write Message to Log

Discussion in 'Programming' started by Superbabs84321, Aug 27, 2010.

  1. Superbabs84321

    Superbabs84321 New Member

    Joined:
    Oct 19, 2009
    Messages:
    24
    Likes Received:
    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: Aug 27, 2010
  2. brold9999

    brold9999 New Member

    Joined:
    Apr 5, 2009
    Messages:
    142
    Likes Received:
    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.
     
  3. Superbabs84321

    Superbabs84321 New Member

    Joined:
    Oct 19, 2009
    Messages:
    24
    Likes Received:
    0
    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.

    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.

    Thanks! That works!

    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.

    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...
     
  4. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,910
    Likes Received:
    35
    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.
     
  5. Superbabs84321

    Superbabs84321 New Member

    Joined:
    Oct 19, 2009
    Messages:
    24
    Likes Received:
    0
    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.
     

Share This Page