PDA

View Full Version : Getting player stats



Salmo
Apr-11-2014, 06:28
I'm using this code fragment to try to obtain player game statistics. Unfortunately it's throwing a "not marked as serialisable error". Ideas?



if (player is IPlayer)
{
IPlayerStat st = (player as IPlayer).GetBattleStat();
string stats = (String.Format("PlayerStat[{0}] bulletsFire={1}, landings={2}, kills={3}, fkills={4}, deaths={5}, bails={6}, ditches={7}, planeChanges={8}, planesWrittenOff={9}, netBattles={10}, singleBattles={11}, tccountry={12}, killsTypes=\"{13}\"",
player.Name(), st.bulletsFire, st.landings, st.kills, st.fkills, st.deaths, st.bails, st.ditches, st.planeChanges, st.planesWrittenOff, st.netBattles, st.singleBattles, st.tccountry, GetDictionary(st.killsTypes)));
ColoredConsoleWrite(ConsoleColor.DarkCyan, "Stats: " + stats);

}

ATAG_Lolsav
Apr-11-2014, 12:42
Sorry Salmo, i dont understand the statement "not marked as serialisable error". I was looking at the code and i only see "statement" and a db fill (think thats the idea).

But since you are on the subject i would like to throw another idea if you dont mind. Is there a game engine event "OnAirborne" or alike? The sorties would make sense if a plane gets airborne i think. The reason im suggesting this its because sometimes there are errors where a player trys to spawn and fails to get into the aircraft. The player has to spawn twice and that counts as a "sortie", which is annoying i think.

bolox
Apr-11-2014, 13:10
public virtual void OnAircraftTookOff(int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft)

never used it myself, but it's there.

ATAG_Lolsav
Apr-11-2014, 13:14
thank you bolox!

Nephilim
Apr-12-2014, 06:04
Hi Salmo. Sounds like You have a problem which I had. That issue come from Your "string stats " construction...

Te problem was coming from killsTypes=\"{13}\" since I remember, but to be honest I cant remember what I did to fix it....


Any way this is what I use at the moment:





public string WritePlayerStatsKills(Player player)
{
string Stats = "";

if (player is IPlayer)
{
IPlayerStat st = (player as IPlayer).GetBattleStat();


Stats = (String.Format("Plane Kill Types: \"{0}\"; Planes Flown Types: \"{1}\";",
st.kills, GetDictionary(st.killsTypes), GetDictionary(st.tTotalTypes)));



}

return Stats;
}

Nephilim
Apr-12-2014, 06:06
Ah yes I remember now...

st.killsTypes is in format of array or something....

It needs to be done by string builder:



public string GetDictionary<T>(Dictionary<string, T> ds)
{
StringBuilder sb = new StringBuilder();
foreach (string key in ds.Keys)
{
T d = ds[key];
if (sb.Length != 0)
{
sb.Append(", ");
}
sb.AppendFormat("[{0}]={1}", key, d);
}
return sb.ToString();
}