Jump to content

Lua script: record player's a2a kills/deaths to HTML file


Jetfire

Recommended Posts

For Lock On V1.02 servers:

 

After a mission has finished, and the debrief screen comes up, this script will record all player's kills and deaths and add them to a HTML file containing all past player's kills/deaths. It will also record all IP connections. Sorry I couldn't host this in a zip file, I am currently having problems logging onto my webpage.

 

INSTRUCTIONS

 

First, backup Config\Export\Export.lua.

 

Then, in export.lua, you need to add this line near the top

g_startTime = os.date( "start: \t%I:%M %p<br>");

 

Then, scroll down in Export.lua and, in function LuaExportStop(), add these 2 lines ( make sure you add them after function LuaExportStop() and before the next end:

 

dofile( "Config/Export/logFlight.lua" );
LogFlight();

 

So, your LuaExportStop() might look like this:

function LuaExportStop()
-- Works once just after mission stop.

-- Close files and/or connections here.
-- For example:
-- 1) File
--	io.close()
-- 2) Socket
--if c then
	--s, e = c:send( "\t> quit\n" ) -- to close the listener socket
	--c:close()
--end

dofile( "Config/Export/logFlight.lua" );
LogFlight();

end

 

Now, make a file called logFlight.lua in your Config\Export\ Folder and paste this code into it:

 

dofile( "Config/Export/fileOps.lua" );

--------------------------------------------------------------------------------
function CalcScores()
 local currPlayer = "";
 local plane = "";
 local playerList = {};
 local playerCount = 0;
 local i = 1;
 local currPIndex = 0;
 local temp = io.input();
 local inFile = io.open( "./Temp/mp_log.txt", "r" );
 
 io.input( inFile );
if ( inFile ) then
  io.write( "<font color=\"#000000\"><br><b>Points</b><br>" );
  io.write( "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"80%\">" );
   io.write( "<tr><td width=\"16%\"><font face=\"Verdana\" size=\"2\">Plane</font></td> ");
   io.write( "  <td width=\"26%\"><font face=\"Verdana\" size=\"2\">Player</font></td> ");
   io.write( "  <td width=\"13%\"><font face=\"Verdana\" size=\"2\">Kills</font></td> ");
   io.write( "  <td width=\"14%\"><font face=\"Verdana\" size=\"2\">Deaths</font></td> ");
   io.write( "</tr> ");

  
   --io.write( "<font face=\"Courier New\" size=\"2\">" );
 	  
  data = io.read( "*line" );
	while ( data ~= NIL ) do
	  -- read the line and look for players
	  -- look for first player
	  strIndex, strIndex2 = string.find( data, "\"" );
	  if ( strIndex ~= NIL ) then
	    currPlayer = string.sub( data, strIndex + 1 );
	    strIndex = string.find( currPlayer, "\"" );
	    strIndex2 = string.find( currPlayer, ")" ) - 1;
	    plane = string.sub( currPlayer, strIndex + 2, strIndex2 );
	    currPlayer = string.sub( currPlayer, 0, strIndex - 1 );
	    
	    -- is the player already in the list?
	    i = 1;
	    while ( i < playerCount and currPlayer ~= playerList[ i ][ "name" ] ) do
	      i = i + 1;
	    end
	    
	    if ( i <= playerCount and currPlayer == playerList[ i ][ "name" ] ) then
 		    currPIndex = i;
 		  else
 		    -- add this player
 		    playerCount = playerCount + 1;
 		    playerList[ playerCount ] = {};
 		    playerList[ playerCount ][ "name" ] = currPlayer;
 		    playerList[ playerCount ][ "plane" ] = plane;
 		    playerList[ playerCount ][ "kills" ] = 0;
 		    playerList[ playerCount ][ "deaths" ] = 0;
 		    playerList[ playerCount ][ "ejected" ] = 0;
 		    currPIndex = playerCount;
 		  end  
 		  
 		  -- this is to catch an ejection and recovery before the plane crashed
 		  -- crash usually follows an eject
	    if ( string.find( data, "crash" ) == NIL and playerList[ currPIndex ][ "ejected" ] == 1 ) then
	      playerList[ currPIndex ][ "deaths" ] = playerList[ currPIndex ][ "deaths" ] + 1;
	      playerList[ currPIndex ][ "ejected" ] = 0;
	    end
 		    
 		  -- find if this is a kill or crash
 		  if ( string.find( data, "kill" ) ~= NIL ) then
	      playerList[ currPIndex ][ "kills" ] = playerList[ currPIndex ][ "kills" ] + 1;
	    elseif ( string.find( data, "eject" ) ~= NIL  ) then
	      playerList[ currPIndex ][ "ejected" ] = 1;
 		  elseif ( string.find( data, "crash" ) ~= NIL ) then  
 		    playerList[ currPIndex ][ "deaths" ] = playerList[ currPIndex ][ "deaths" ] + 1;
	      if ( playerList[ currPIndex ][ "ejected" ] == 1 ) then
	        playerList[ currPIndex ][ "ejected" ] = 0;
	      end
 		  end
 		end
 		
 		data = io.read( "*line" );
	
	end
	
	for i = 1, playerCount do
 	  io.write( "<tr><td width=\"16%\"><font face=\"Verdana\" color=\"#ff0000\" size=\"2\">" );
 	  io.write( "<img border=\"0\" src=\"img/" );
 	  io.write( playerList[ i ][ "plane" ] );
 	  io.write( ".jpg\"></td><td width=\"26%\"><font color=\"#0000ff\"><b>" );
 	  io.write( playerList[ i ][ "name" ] );
 	  io.write( "</b></td><td width=\"13%\"><font color=\"#ff0000\"><b>" );
     io.write( "<p align=\"center\"><b>" );
     io.write( playerList[ i ][ "kills" ] );
     io.write( "</b></td><td width=\"14%\"><p align=\"center\"><font color=\"#ff0000\"><b>" );
 	  io.write( playerList[ i ][ "deaths" ] );
 	  io.write( "</font></b></td></tr>" );
 	end
 	
 	io.write( "</table>" );
   io.write( "</center>" );
	  
end

io.input():close();        -- close current file
 io.input( temp );        
 


end

--------------------------------------------------------------------------------

function LogFlight()
 local inFileBuf;
 local inFileBuf2;
 local data;
 local strIndex = 0;
 local strIndex2 = 0;
 local clientCount = 0;
 local inFile = io.open( "./Temp/AsyncNet.log", "r" );
 local outFile;
   
 local temp1 = io.input()   -- save current file
 local temp2 = io.output()   -- save current file
   
 io.input( inFile );
  
if ( inFile ) then
  outFile = io.open( "./Temp/lastFlight.html", "w" )
  io.output( outFile );
  
  --io.write( "<html><head><title>Lock On: Modern Air Combat Stats</title></head><body>" );
   io.write( "<br><hr><p align=\"right\"><font face=\"Verdana\" size=\"2\" color=\"#000000\">" );
   io.write( os.date( "date:  \t%a, %b %d %Y  <br>" ) );
   if ( g_startTime ~= NIL ) then
     io.write( g_startTime );
   end
   io.write( os.date( "end:   \t%I:%M %p<br>") );
   io.write( "</p>" );
 
    
  data = io.read( "*line" );
	while ( data ~= NIL ) do
	  -- read the line and look for connection
	  strIndex, strIndex2 = string.find( data, "accepting connection from " );
	  if ( strIndex ~= NIL ) then
	    io.write( string.format( "%s<br>", string.sub( data, strIndex2 + 1, 100 ) ) );
	    if ( clientCount == 0 ) then
	      io.write( "<br><b>IP Connections<font color=\"#0000FF\"></b><br>" );
 	    end
	    clientCount = clientCount + 1;
	  end
	  
	  data = io.read( "*line" );
	
	end
end

io.input():close()        -- close current file
io.input( temp1 ); 

-- no clients so let's get out
if ( clientCount == 0 ) then
  io.output():close();        -- close current file
   io.output( temp2 );
  return;
end       
 
CalcScores();

 temp1 = io.input();
 inFile = io.open( "./Temp/mp_log.txt", "r" );
 io.input( inFile );
if ( inFile ) then
  io.write( "<font color=\"#000000\"><br><b>Debrief</b><br>" );
   io.write( "<font face=\"Courier New\" size=\"2\">" );
 	  
  data = io.read( "*line" );
	while ( data ~= NIL ) do
	  -- read the line and look for connection
	  --strIndex, strIndex2 = string.find( data, "accepting connection from " );
	  --if ( strIndex ~= NIL ) then
	  --  io.write( string.format( "%s\n", string.sub( data, strIndex2 + 1, 100 ) ) );
	  --end
	  io.write( string.format( "\t %s<br>", data ) );
	  
	  data = io.read( "*line" );
	
	end
end
io.write( "<br>" );
	  

io.input():close();        -- close current file
 io.input( temp1 ); 
io.output():close();        -- close current file
 io.output( temp2 );
 
 inFileBuf = OpenFile( "./Temp/lastFlight.html" );
 inFileBuf2 = OpenFile( "./Temp/logFile.html" );
 WriteToFile( "./Temp/logFile.html", inFileBuf );
 AppendToFile( "./Temp/logFile.html", inFileBuf2 );
end



 

And! That's not it... make another file in the same folder called fileOps.lua and paste this code into the file:

 


-- reads in a file, storing each line in an array
-- buffer[ 1 ] is always reserved for line count
function OpenFile( fileName )
 local buffer = {};
 local i = 2;  
 local temp = io.input();
 local inFile = io.open( fileName, "r" );
 
  io.input( inFile );
if ( inFile ) then
  buffer[ 1 ] = 2;
  buffer[ i ]= io.read( "*line" );
	while ( buffer[ i ] ~= NIL ) do
    i = i + 1;
    buffer[ i ] = io.read( "*line" );
  end
end	
 io.input():close();        -- close current file
 io.input( temp );
 return buffer;
end

--------------------------------------------------------------------------------

-- reads the next line from the buffer
function ReadLine( buffer )
 if ( buffer[ buffer[ 1 ] + 1 ] ~= NIL ) then
   buffer[ 1 ] = buffer[ 1 ] + 1;
   return buffer[ buffer[ 1 ] - 1 ];
 else
   return NIL
 end
end

--------------------------------------------------------------------------------
-- writes a previously made buffer to a file
-- openParam is "w" for write, "a" for append
function WriteBufferToFile( fileName, buffer, openParam )
 local i = 2;
 local temp = io.output();
 local outFile = io.open( fileName, openParam );
 
 io.output( outFile );
if ( outFile ) then
  while ( buffer[ i ] ~= NIL ) do
    io.write( buffer[ i ] );
    io.write( "\n" );
    i = i + 1;
  end
end	
 io.output():close();        -- close current file
 io.output( temp ); 
end

--------------------------------------------------------------------------------
function AppendToFile( fileName, buffer )
 WriteBufferToFile( fileName, buffer, "a" );
end

--------------------------------------------------------------------------------
function WriteToFile( fileName, buffer )
 WriteBufferToFile( fileName, buffer, "w" );
end

--------------------------------------------------------------------------------

 

You're done! In terms of performance, this shouldn't cause any fps loss for the first mission hosted, because it will only run after the first debrief.

 

The logfile will be \Temp\LogFile.html.

  • Like 1
sig36aa.jpg
Link to comment
Share on other sites

Good work JetFire!

This script based on parsing ""./Temp/AsyncNet.log" file, so is it official way to get MP results? I mean - have you talk with developers about how stable this file format will be in next patches? I wonder may be they will going to expand LUA command set to provide a direct functions to get a mission results?

"There are five dangerous faults which may affect a general: recklessness, which leads to destruction; cowardice, which leads to capture; a hasty temper, which can be provoked by insults; a delicacy of honor which is sensitive to shame; over-solicitude for his men, which exposes him to worry and trouble." Sun Tzu

[sigpic]http://forums.eagle.ru/signaturepics/sigpic2354_5.gif[/sigpic]

Link to comment
Share on other sites

Dmut, I haven't spoken to the devs about this. I was talking to GGTharos and about his request to fix the log file so it shows all debrief data, then I thought I'd post this since it's a start towards processing game stats. But yeah, you're right, it would be alot easier if Lock On gave us the score rather than parsing it.

 

Ice, next time you run a mission then a debrief, could you post your Error.log file (not errors.log)? This will show any Lua errors.

sig36aa.jpg
Link to comment
Share on other sites

Good Stuff Jetfire! Maybe iafter 1.1 I'll help you out with doing some moreinteresting projects as well now that a lot more stuff is being exported.

[sIGPIC][/sIGPIC]

Reminder: SAM = Speed Bump :D

I used to play flight sims like you, but then I took a slammer to the knee - Yoda

Link to comment
Share on other sites

  • 2 weeks later...

Hi Jetfire,

 

Wow, thanks for your work ;) :D

 

I just installed your application, but it doesn't work correctly.

In my Temp Folder a "lastFlight.html" is generated with following content:

 

<br><hr><p align="right"><font face="Verdana" size="2" color="#000000">date:  	Sa, Nov 27 2004  <br>start: 	05:46 <br>end:   	06:12 <br></p>

 

But the playerstats and the LogFile.html are missing. :(

 

Could you help me? :D

Kind regards,

JaBoG32_Chrissi

Link to comment
Share on other sites

  • 1 month later...
  • 3 years later...

I found this interesting old thread and I would like to bump it with a question regarding its usage on FC. I was not able to make it work, apart from that comment by JaBoG32_Chrissi.

 

Can someone with LUA knowledge please take a look at the Jetfire's code? (I've sent PM to Jetfire, but no reply so far)

 

This could be a good alternative for Pilot Logbook.

 

Thanks in advance

I'm selling MiG-21 activation key.

Also selling Suncom F-15E Talon HOTAS with MIDI connectors, several sets.

Contact via PM.

Link to comment
Share on other sites

  • 1 year later...

Hi, I found this old thread very interesting.

 

Are these scripts still working with FC2.0 or did someone worked on exporting data from the game with all the Kill/Death etc. informations to make multiplayer stats and debriefing ?

Proud to be a [sIGPIC][/sIGPIC] :joystick::pilotfly::book:

Link to comment
Share on other sites

Hi, I found this old thread very interesting.

 

Are these scripts still working with FC2.0 or did someone worked on exporting data from the game with all the Kill/Death etc. informations to make multiplayer stats and debriefing ?

The possibilities is there for ServMan - we've just not decided wether we should do it yet, but it would certainly be a nice feature.

The mind is like a parachute. It only works when it's open | The important thing is not to stop questioning

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...