Results 1 to 16 of 16

CoH Player Data retrieval for Outside consuming

  1. #1

    CoH Player Data retrieval for Outside consuming

    So, I am currently developing some tools for the Blitzkrieg mod. for those I need some data directly from the game, some of the I can pull out of the log files, but I have seen eliw00ds tutorial a few days ago and that method is way better for the task at hand.
    I am not experienced in lua or SCAR for that matter, nor do I have the time to learn those two languages to get what I need. So I am kindly asking a SCAR coder out there, if he can get me the script so we can include it in BK.

    The script should pull out the following data out of the game and store it in a text file (or xml, as long as i can consume it in a c# application (read with LINQ) without too much problem):
    Game Name (if that is possible, if not, then not)
    Players ingame (so if it is a 2, 4, 6 or 8 player game)
    The map played
    A list with each player with his name, faction and doctrine
    which team won
    the duration of the game

    An example two player match could look like this:
    Code:
    Game 2012.07.13-2337.txt
    Game_Name: Test Game
    Game_Player_Count: 2
    Game_Map: Angoville
    Player_0_Name: Player1
    Player_0_Race: axis_infantry_company
    Player_0_Doctrine: Terror
    Player_1_Name: Player2
    Player_1_Race: allied_rifle_company
    Player_1_Doctrine: infantry
    Game_Winner: Team1
    Game_Length: 56
    Can anyone code me this script?

    Thanks in advance.
    Ruhrpottpatriot
    N44 Coder
    N44 Bugtracker

  2. #2
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    I am not aware of any SCAR functions to get the current map name, so that might not be possible unless you edited every map to give you that information.

  3. Modding Senior Member Company of Heroes Senior Member  #3
    Celéstial by heart Celution's Avatar
    Join Date
    Apr 2008
    Location
    Sweden
    I am not completely sure, but Joint Operations made by Mannerheim and Henry666 a few years back had something simular, where you could submit your score you got on one of their scripted to their website, not sure how they did it though. But you can try sending a PM to Mannerheim, he's still around from time to time, or send an e-mail.

  4. #4
    Dive! Dive! Dive! Mannerheim's Avatar
    Join Date
    Sep 2006
    Location
    Finland
    Stats_GetScenarioName() gives you the filename which you can map to whatever name on the other end of the system

  5. #5
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    Nice. Missed that one.

  6. #6
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    First you'll have to add JointOpsMod.dll to your mod, which can be downloaded here

    How to add it to your mod:
    ( example snippet from correctly edited .module file )
    Code:
    ...
    Description = Company of Heroes
    DllName = JointOpsMod
    ModVersion = 1.0
    ScenarioPackFolder = WW2\Scenarios
    SpeechManagerCache = SpeechManagerCoH.cache
    ...
    You will also need lua-io.dll, which I can not upload right now as I havent asked permissions to do it / dont know where to get it.
    Place lua-io.dll into coh install folder.

    Because of most of the time coh is installed in program files, and CoH is not run with admin rights, lua cannot save text files to coh install directory.

    We have to use external file to set filepath for saving match info. This file could be edited with mod launcher.
    In my example this file is located in CheatMod\filepath.txt
    This can be edited in savematchinfo.scar at line 49.

    filepath.txt should have 1 line of text, containing full file path for match info file, for example
    Code:
    C:\Users\Profile\Desktop\matchinfo.txt
    Now the function that saves match info:
    Code:
    import("ScarUtil.scar")
    
    function SaveMatchInfo(winning_team, winmode)
    	_PLAYERS = {}
    	CommanderTrees = 
    	{
    		{UPG.COMMANDER_TREE.CW.CANADIAN_ARTILLERY, UPG.COMMANDER_TREE.CW.COMMANDOS, UPG.COMMANDER_TREE.CW.ENGINEERS},
    		{UPG.COMMANDER_TREE.ALLIES.AIRBORNE, UPG.COMMANDER_TREE.ALLIES.INFANTRY, UPG.COMMANDER_TREE.ALLIES.ARMOR},
    		{UPG.COMMANDER_TREE.AXIS.DEFENSE, UPG.COMMANDER_TREE.AXIS.PROPAGANDA, UPG.COMMANDER_TREE.AXIS.BLITZKRIEG},
    		{UPG.COMMANDER_TREE.ELITE.LUFTWAFFE, UPG.COMMANDER_TREE.ELITE.SCORCHED_EARTH, UPG.COMMANDER_TREE.ELITE.TANK_DESTROYER},
    	}
    	
    	Doctrines = 
    	{
    		{"Royal Canadian Artillery", "Commandos", "Royal Engineers"},
    		{"Airborne", "Infantry", "Armor"},
    		{"Defensive", "Terror", "Blitzkrieg"},
    		{"Luftwaffe", "Scorched earth", "Tank destroyer"}
    	}
    			
    	for j = 1, World_GetPlayerCount() do
    		_PLAYERS[j] = World_GetPlayerAt(j)
    	end
    	
    	playerinfo = ""
    
    	for a = 1, table.getn(_PLAYERS) do
    		_player = _PLAYERS[a]
    		_race = Player_GetRace(_player) + 1
    		_doctrine = "none"
    		for b = 1, 3 do
    			if Player_HasUpgrade(_player, CommanderTrees[_race][b]) then
    				_doctrine = Doctrines[_race][b]
    			end
    		end
    		
    		playerinfo = playerinfo.."\nPlayer_"..a.."_Name: "..Player_GetDisplayName(_player)[1].."\nPlayer_"..a.."_Race: "..Player_GetRaceName(_player).."\nPlayer_"..a.."_Doctrine: ".._doctrine
    		
    	end
    
    	line1 = "Game_Player_Count: "..World_GetPlayerCount()
    	line2 = "\nGame_Map: "..Stats_GetScenarioName()
    	line3 = "\nGame_Winner: ".."team"..winning_team + 1
    	line4 = playerinfo
    	line5 = "\nGame_Lenght: "..Stats_TotalDuration()
    	line6 ="\nVictory_Type: "..winmode
    	assert(loadfile("lua-io.dll", "luaopen_io"))()
    	
    	for line in io.lines("CheatMod/filepath.txt") do
    		filepath = line
    	end
    	io.close()
    	
    	io.output(io.open(filepath,"w"))
    	io.write(line1..line2..line3..line4..line5..line6)
    	io.close()
    end
    this file should be located in Mod folder\data\scar
    with filename savematchinfo.scar

    Now this file has to be imported to the game in scarutil.scar:
    Add
    Code:
    import("savematchinfo.scar")
    to the end of the list, before this text:
    Code:
    -- this must be loaded after the MissionPresets.scar file
    if Misc_IsCommandLineOptionSet("dev") then
    	import("SP_Cheatscript.scar")
    end
    Now we have to edit 2 files:
    data\scar\wcutil.scar
    data\scar\winconditions\vptickerwin-annihilate.scar


    So that function SaveMatchInfo(winning_team, winmode) will be called in when game is being ended.

    How to ( wcutl.scar ):
    Find function WC_CheckOneTeamLeft( win_condition ) in wcutil.scar :
    Add:
    Code:
    SaveMatchInfo(Player_GetTeam(player_alive), "Annihilate")
    before World_SetGameOver()
    and remove line 14
    Code:
    		local player_alive
    This will make local variable player_alive to global variable

    How to: ( in vptickerwin-annihilate.scar ):
    Find function VPTicker_GameOverLose( loseTeamId ) in vptickerwin-annihilate.scar, and add
    Code:
    SaveMatchInfo(Team_GetEnemyTeam( loseTeamId - 1), "Victorypoint controll")
    before World_SetGameOver( )

    Save all edited files. This should now be installed. Feel free to ask as this is rather complicated and I may have forgot something.
    If everything went well, a new text file should appear in directory that is set in filepath.txt when game ends, with text similar to this:
    Code:
    Game_Player_Count: 2
    Game_Map: 2p_beaux lowlands
    Game_Winner: team1
    Player_1_Name: ScirmishPractice
    Player_1_Race: allies_commonwealth
    Player_1_Doctrine: none
    Player_2_Name: CPU - Hard
    Player_2_Race: axis
    Player_2_Doctrine: Blitzkrieg
    Game_Lenght: 11
    Victory_Type: Annihilate
    Reload Attrib files ingame with SCAR

    Do you need help with SCAR?


  7. #7
    OK, first: Big, big thanks Jannev.

    I'll try to test the script as soon as I can. But Is there a possibility to get the selected resource system (if it is normal resources or high resources?) Or is that not possible, because you select it before the game is initialized?

  8. #8
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    You cant test it until you get lua-io.dll file from somewhere. I have no rights to upload it, but I got mine from modern combat mod.
    And yes, it would be possible. I dont think it is possible to get the setting directly, but you could take each player resource value in the beginning of the match and compare those values to standard resource values.

  9. #9
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    @Mannerheim
    Are there any other Stats functions that aren't in the SCARDOC?

  10. #10
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Code:
    Stats_ReportGameStats("_result", Game_CurrentSystemTime())
    This function saves a file with name given in first parameter, in this case _result.log to my games/company of heroes/logfiles
    The saved file looks like this:
    Code:
    realtime = "1:06",
    gametime = "0:00",
    speedup = 0.00,
    players = 
    {
    	{
    		playerid = 1000,
    		playername = ScirmishPractice,
    		result = playing,
    		infantryProduced = 0,
    		infantryLost = 0,
    		infantryLostFriendlyFire = 0,
    		soldiersKilled = 0,
    		soldiersReinforced = 0,
    		weaponsObtained = 0,
    		vehiclesProduced = 0,
    		vehiclesLost = 0,
    		vehiclesLostFriendlyFire = 0,
    		vehiclesKilled = 0,
    		SectorsCaptured = 0,
    		SectorsLost = 0,
    		SectorsSeized = 0,
    		ResGatheredManpower = 1.613500,
    		ResGatheredMunition = 0.000000,
    		ResGatheredFuel = 0.000000,
    		ResGatheredAction = 0.000000,
    		BuildingsBuilt = 0,
    		BuildingsLost = 0,
    		BuildingsKilled = 0,
    		AmbientBuildingsOccupied = 0,
    		OccupiedBuildingsSeized = 0,
    		OccupiedBuildingsLost = 0,
    		heroes = 
    		{
    		},
    	},
    	{
    		playerid = 1004,
    		playername = CPU - Normal,
    		result = playing,
    		infantryProduced = 0,
    		infantryLost = 0,
    		infantryLostFriendlyFire = 0,
    		soldiersKilled = 0,
    		soldiersReinforced = 0,
    		weaponsObtained = 0,
    		vehiclesProduced = 0,
    		vehiclesLost = 0,
    		vehiclesLostFriendlyFire = 0,
    		vehiclesKilled = 0,
    		SectorsCaptured = 0,
    		SectorsLost = 0,
    		SectorsSeized = 0,
    		ResGatheredManpower = 2.100000,
    		ResGatheredMunition = 0.000000,
    		ResGatheredFuel = 0.000000,
    		ResGatheredAction = 0.000000,
    		BuildingsBuilt = 0,
    		BuildingsLost = 0,
    		BuildingsKilled = 0,
    		AmbientBuildingsOccupied = 0,
    		OccupiedBuildingsSeized = 0,
    		OccupiedBuildingsLost = 0,
    		heroes = 
    		{
    		},
    	},
    	{
    		playerid = 1005,
    		playername = CPU - Normal,
    		result = playing,
    		infantryProduced = 0,
    		infantryLost = 0,
    		infantryLostFriendlyFire = 0,
    		soldiersKilled = 0,
    		soldiersReinforced = 0,
    		weaponsObtained = 0,
    		vehiclesProduced = 0,
    		vehiclesLost = 0,
    		vehiclesLostFriendlyFire = 0,
    		vehiclesKilled = 0,
    		SectorsCaptured = 0,
    		SectorsLost = 0,
    		SectorsSeized = 0,
    		ResGatheredManpower = 2.100000,
    		ResGatheredMunition = 0.000000,
    		ResGatheredFuel = 0.000000,
    		ResGatheredAction = 0.000000,
    		BuildingsBuilt = 0,
    		BuildingsLost = 0,
    		BuildingsKilled = 0,
    		AmbientBuildingsOccupied = 0,
    		OccupiedBuildingsSeized = 0,
    		OccupiedBuildingsLost = 0,
    		heroes = 
    		{
    		},
    	},
    	{
    		playerid = 1006,
    		playername = CPU - Normal,
    		result = playing,
    		infantryProduced = 0,
    		infantryLost = 0,
    		infantryLostFriendlyFire = 0,
    		soldiersKilled = 0,
    		soldiersReinforced = 0,
    		weaponsObtained = 0,
    		vehiclesProduced = 0,
    		vehiclesLost = 0,
    		vehiclesLostFriendlyFire = 0,
    		vehiclesKilled = 0,
    		SectorsCaptured = 0,
    		SectorsLost = 0,
    		SectorsSeized = 0,
    		ResGatheredManpower = 2.100000,
    		ResGatheredMunition = 0.000000,
    		ResGatheredFuel = 0.000000,
    		ResGatheredAction = 0.000000,
    		BuildingsBuilt = 0,
    		BuildingsLost = 0,
    		BuildingsKilled = 0,
    		AmbientBuildingsOccupied = 0,
    		OccupiedBuildingsSeized = 0,
    		OccupiedBuildingsLost = 0,
    		heroes = 
    		{
    		},
    	},
    	{
    		playerid = 1007,
    		playername = CPU - Normal,
    		result = playing,
    		infantryProduced = 0,
    		infantryLost = 0,
    		infantryLostFriendlyFire = 0,
    		soldiersKilled = 0,
    		soldiersReinforced = 0,
    		weaponsObtained = 0,
    		vehiclesProduced = 0,
    		vehiclesLost = 0,
    		vehiclesLostFriendlyFire = 0,
    		vehiclesKilled = 0,
    		SectorsCaptured = 0,
    		SectorsLost = 0,
    		SectorsSeized = 0,
    		ResGatheredManpower = 2.100000,
    		ResGatheredMunition = 0.000000,
    		ResGatheredFuel = 0.000000,
    		ResGatheredAction = 0.000000,
    		BuildingsBuilt = 0,
    		BuildingsLost = 0,
    		BuildingsKilled = 0,
    		AmbientBuildingsOccupied = 0,
    		OccupiedBuildingsSeized = 0,
    		OccupiedBuildingsLost = 0,
    		heroes = 
    		{
    		},
    	},
    }
    There is also 1 other function in data\scar\balancetool.scar, but I dont know what is does.
    Line 261: local cost_req = Stats_ActiveArmyCost( player, RT_Requisition )
    Line 262: local cost_pow = Stats_ActiveArmyCost( player, RT_Power )

  11. #11
    You cant test it until you get lua-io.dll file from somewhere. I have no rights to upload it, but I got mine from modern combat mod.
    Completely forgot that. Maybe because I was fiddling around with improving the DL-Manager for BK patches... I'll ask the MC team directly.

    Line 261: local cost_req = Stats_ActiveArmyCost( player, RT_Requisition )
    Line 262: local cost_pow = Stats_ActiveArmyCost( player, RT_Power )
    Those two seem to be functions which return the current upkeep of your army and both seem to be a leftover from DoW, where you had requisition and power as resources.

  12. #12
    Dive! Dive! Dive! Mannerheim's Avatar
    Join Date
    Sep 2006
    Location
    Finland
    Quote Originally Posted by eliw00d View Post
    @Mannerheim
    Are there any other Stats functions that aren't in the SCARDOC?
    I don't remember which scardoc had but probably yes. You could find all possible ones by checking what function were bind to lua/scar runtime or check all .dll and .exe doing lua function binds

  13. #13
    Moderator Darkbladecr's Avatar
    Join Date
    Nov 2005
    Location
    CoH:Modern Combat
    I have a question, does anyone know where to get the cURL .dll files? That can then be used to send the retrieved game data outwards to something more useful

  14. #14
    Member Janne252's Avatar
    Join Date
    Aug 2009
    Location
    Finland
    Someone posted here a link where to get lua related .dll files a week ago, but since forums got rolled back by few days, the post is gone.

  15. #15
    Moderator Darkbladecr's Avatar
    Join Date
    Nov 2005
    Location
    CoH:Modern Combat
    Well the tutorial is here: http://forums.relicnews.com/showthre...RL-IO-and-more!
    But the .dll files were never put up, it would be great if someone could post a link and then I could update the how-to as well

  16. #16
    Member eliw00d's Avatar
    Join Date
    Jul 2008
    Location
    USA
    I can upload them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •