View Single Post
  #23  
Old 12-22-2013, 01:05 AM
_79_dev _79_dev is offline
Approved Member
 
Join Date: Sep 2010
Location: Dublin
Posts: 242
Default Chat <stas, <tl, ....Interface

I found very useful lately IPlayer interface with all its goodies....


Here is example script to execute chat info in good old style

check available commands:

<stats , <guns, <kills, <stats<all, <tl, <te...etc

That is just simple examples but You can convert lot of things from game to it....

If Any one is interested to give it a go on servers let me know if You experience any troubles with it... There is some delay on data read and some things are not working or are just not activated maybe

Enjoy...

Code:
//$reference parts/core/Strategy.dll
//$reference parts/core/MySql.Data.dll
//$reference parts/core/System.Data.dll

//$reference parts/core/gamePlay.dll


    #region timer


    long Tick_Mission_Time { get; set; }// Sets the Mission Clock for Time Remaining in Mission.

    Random random = new Random();//Function for Randomising events

    Stopwatch stopWatch = new Stopwatch();

    public string GetTimeElapsed()
    {
        string StringToReturn = "";
        StringToReturn = "";

        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value. 
        string elapsedTime = String.Format("{0:00}h:{1:00}m:{2:00}s", ts.Hours, ts.Minutes, ts.Seconds);


        StringToReturn = StringToReturn + elapsedTime;
        return StringToReturn;

    }



    #endregion



    #region Iplayer stats

    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.AppnedFormat("[{0}]={1}", key, d);
            sb.AppendFormat("[{0}]={1}", key, d);
        }
        return sb.ToString();
    }

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

        if (player is IPlayer)
        {
            IPlayerStat st = (player as IPlayer).GetBattleStat();
            Stats = (String.Format("Take Offs: [{0}]; " + "Landings:  [{1}];  " + "Deaths:  [{2}]; " + "Bails:  [{3}]; ",
                                       st.takeoffs, st.landings, st.deaths, st.bails));



        }

        return Stats;
    }

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

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



            if (st.bulletsFire != 0)
            {
                double accuracy = ((st.bulletsHit) / (st.bulletsFire)) * 100;

                Stats = (String.Format("Accuracy:  " + accuracy + " %;" + " Bullets Fired: [{0}]; " + "Bullets Hits: [{1}];  " + "Bullets Air Hits: [{2}];  ",
                                            st.bulletsFire, st.bulletsHit, st.bulletsHitAir));

            }

        }

        return Stats;
    }

    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;
    }

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

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


            Stats = (String.Format("Bombs Fired : [{0}]; " + "Bombs Hit : [{1}];  " + "Bombs Weight : [{2}]; " + "g kills: {3}; ",
                                    st.bombsFire, st.bombsHit, st.bombsWeight, st.gkills[0]));



        }

        return Stats;
    }

    #endregion

    #region Time Left

    public string WriteTime_Remaining(Player player)
    {
        string Time_Remaining = "";

        Tick_Mission_Time = ((32 * 60) * 240) - Time.tickCounter();
        var Mission_Time = Tick_Mission_Time / 2000;
        TimeSpan Convert_Ticks = TimeSpan.FromMinutes(Mission_Time);
        Time_Remaining = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", Convert_Ticks.Hours, Convert_Ticks.Minutes, Convert_Ticks.Seconds);




        return Time_Remaining;
    }

    public string WriteTime_Elapsed(Player player)
    {
        string Time_Remaining = GetTimeElapsed();

        return Time_Remaining;
    }


    #endregion

    #region objectives

    public string WriteRedObjectives(Player player)
    {
        string Objectives = Objective_Total_Red; ;




        return Objectives;
    }

    public string WriteBlueObjectives(Player player)
    {
        string Objectives = Objective_Total_Blue;


        return Objectives;
    }

    #endregion


    #region chat


    public void Chat(string line, Player player)
    {
        if (GamePlay is GameDef)
        {
            (GamePlay as GameDef).gameInterface.CmdExec("chat " + line + " TO " + player.Name());
        }
    }


    void Mission_EventChat(IPlayer from, string msg)
    {



        if (msg.StartsWith("<obj"))
        {

            Chat("Red Triggers: " + WriteRedObjectives(from as Player), from);
            //GamePlay.gpHUDLogCenter(new Player[] { from as Player }, "Time Elapsed is " + WriteObjectives(from as Player));


            Chat("Blue Triggers: " + WriteBlueObjectives(from as Player), from);
            //GamePlay.gpHUDLogCenter(new Player[] { from as Player }, "Time Elapsed is " + WriteObjectives(from as Player));

        }
        if (msg.StartsWith("<te"))
        {

            //Chat(Time_Elapsed(from as Player), from);
            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, "Time Elapsed is " + WriteTime_Elapsed(from as Player));

        }

        if (msg.StartsWith("<tl"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, "Time Remaining is " + WriteTime_Remaining(from as Player));

        }
        if (msg.StartsWith("<timeleft"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, "Time Remaining is " + WriteTime_Remaining(from as Player));

        }
        if (msg.StartsWith("<stats"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatBase(from as Player));

        }
        if (msg.StartsWith("<guns"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsGunnery(from as Player));

        }

        if (msg.StartsWith("<kills"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsKills(from as Player));

        }

        if (msg.StartsWith("<bombs"))
        {

            GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsBombs(from as Player));

        }

        if (msg.StartsWith("<stats<all"))
        {
            Timeout(1, () =>
            { GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatBase(from as Player)); }
       );
            Timeout(6, () =>
            { GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsGunnery(from as Player)); }
        );
            Timeout(10, () =>
            { GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsKills(from as Player)); }
       );
            Timeout(15, () =>
            { GamePlay.gpHUDLogCenter(new Player[] { from as Player }, WritePlayerStatsBombs(from as Player)); }
      );


        }
    }




    #endregion
__________________

Asus P6T V2 Deluxe, I7 930, 3x2 GB RAM XMS3 Corsair1333 Mhz, Nvidia Leadtek GTX 470, Acer 1260p screen projector, Track IR 4 OS ver5, Saitek Pro Flight Rudder, Saitek X52, Win 7 x64 ultimate
Reply With Quote