Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   chat messages (http://forum.fulqrumpublishing.com/showthread.php?t=30364)

_79_dev 03-10-2012 12:10 PM

chat messages
 
Hi would anyone advise how to add chat messages:

- every 15min
- after player tok off

in this example from wildwillie:
Code:

//$reference IL2ClodCommanderStats.dll
// v.1_0. script by FG28_Kodiak, ZaltysZ, Oreva, Small_Bee, RAF238thWildWillie
using System;
using System.Diagnostics;
using System.Collections;
using maddox.GP;
using maddox.game;
using maddox.game.world;
using part;
using System.Collections.Generic;
using IL2ClodCommanderStats;


public class Mission : AMission
{
    #region Stats Initialization
    // For Connection to the IL2 Clod Commander Application
    // This allows you to store stats on players within Cliffs of Dover
    //  Change the following to meet your needs
    //
    private static string serverName = "";
    private static string serverIP = "127.0.0.1";
   
    // Password is not used currently
    private static string serverPassword = "password";
    private static Int32  serverPort = 27015;
    private StatsRecording stats = new StatsRecording(serverName, serverIP, serverPassword, serverPort);
    private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();
    private List<ServerCommand> newCmds = new List<ServerCommand>();
    private Stopwatch MissionTimer = new Stopwatch();
    #endregion

    int LastMissionLoaded = 0;

    double initTime;


    // loading sub-missions
    public override void OnTickGame()
    {
              #region Stats Timer
              if (MissionTimer.Elapsed.TotalSeconds >= 5) // 5 seconds
        {
            MissionTimer.Restart(); // stopwatch reset to 0 and restart
            if (stats != null )
            {
              newCmds = stats.getCommands();
              if (newCmds != null && newCmds.Count > 0)
                  ProcessCommands(newCmds);
            }
        }
        #endregion
    ///////////////////////

  ///////////////////////

    ////////////////////////////////////////////////////////////////////////////////////////////////////

 ////////////////////////////////////////////////////////////////////////////////////////////////////

// Base Scripts for Missions
  private bool isAiControlledPlane (AiAircraft aircraft)
  {
                if (aircraft == null)
        {
                        return false;
                }

                Player [] players = GamePlay.gpRemotePlayers ();
                foreach (Player p in players)
        {   
                        if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)
            {
                                return false;
                        }
                }

                return true;
        }

        private void destroyPlane (AiAircraft aircraft) {
                if (aircraft != null) {
                        aircraft.Destroy ();
                }
        }

        private void explodeFuelTank (AiAircraft aircraft)
  {
                if (aircraft != null)
        {
                        aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);
                }
        }

        private void destroyAiControlledPlane (AiAircraft aircraft) {
                if (isAiControlledPlane (aircraft)) {
                        destroyPlane (aircraft);
                }
        }

        private void damageAiControlledPlane (AiActor actor) {
                if (actor == null || !(actor is AiAircraft)) {
                        return;
                }

                AiAircraft aircraft = (actor as AiAircraft);

                if (!isAiControlledPlane (aircraft)) {
                        return;
                }

                if (aircraft == null) {
                        return;
                }

                aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);
                aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);
                aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);
                aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

        int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
        for (int i = 0; i < iNumOfEngines; i++)
        {
            aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
        }

        /***Timeout (240, () =>
                {explodeFuelTank (aircraft);}
            );
        * ***/

        Timeout (300, () =>
                                {destroyPlane (aircraft);}
                        );
        }

  public override void Init(maddox.game.ABattle battle, int missionNumber)
  {
        base.Init(battle, missionNumber);
        MissionNumberListener = -1; //Listen to events of every mission
  }

//////////////////////////////////////////
// Methods for Stats (You can add any code you may need after the Stats Region
//////////////////////////////////////////

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        #region Stats
          MissionTimer.Start(); // start the stopwatch
        #endregion
    }

    private void sendScreenMessageTo(int army, string msg, object[] parms)
    {
        List<Player> Players = new List<Player>();

        // on Dedi the server or for singleplayertesting
        if (GamePlay.gpPlayer() != null)
        {
            if (GamePlay.gpPlayer().Army() == army || army == -1)
                Players.Add(GamePlay.gpPlayer());
        }
        if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
        {
            foreach (Player p in GamePlay.gpRemotePlayers())
            {
                if (p.Army() == army || army == -1)
                    Players.Add(p);
            }
        }
        if (Players != null && Players.Count > 0)
            GamePlay.gpHUDLogCenter(Players.ToArray(), msg, parms);
    }

    private void ProcessCommands(List<ServerCommand> newCmds)
    {
        try
        {
            foreach (ServerCommand sc in newCmds)
            {
                if (sc.CommandType.Equals("HUDmsg"))
                {
                        if (sc.ToWho.Equals("All"))
                        GamePlay.gpHUDLogCenter(sc.Command);
                  else if (sc.ToWho.Equals("Red"))
                    {
                        sendScreenMessageTo(1, sc.Command, null);
                    }
                    else if (sc.ToWho.Equals("Blue"))
                    {
                        sendScreenMessageTo(2, sc.Command, null);
                    }
                    else
                    {
                        if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
                        {

                            foreach (Player p in GamePlay.gpRemotePlayers())
                            {
                                if (p.Name() == sc.ToWho)
                                    GamePlay.gpLogServer(new Player[] { p }, sc.Command, null);
                            }
                        }
                        // Message is for a specific player based on player name in string sc.ToWho
                    }
                }
            }
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.ProcessCommands - Exception: " + ex);
        }
    }
 
    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        #region stats
        base.OnActorCreated(missionNumber, shortName, actor);
        // Add actor to list of all Actors
        if (!allActors.ContainsKey(shortName))
          allActors.Add(shortName, actor);
        try
        {
            stats.newActor(shortName, actor);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnActorCreated - Exception: " + ex);
        }
        #endregion
    }


    public override void OnPersonHealth(maddox.game.world.AiPerson person, maddox.game.world.AiDamageInitiator initiator, float deltaHealth)
    {
        #region stats
        base.OnPersonHealth(person, initiator, deltaHealth);
        try
        {
            stats.playerHealth(person, initiator, deltaHealth);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPersonHealth - Exception: " + ex);
        }
        #endregion

    }

    public override void OnPersonParachuteFailed(maddox.game.world.AiPerson person)
    {
        #region stats
        base.OnPersonParachuteFailed(person);
        try
        {
            stats.personParachute("Failed", person);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPersonParachuteFailed - Exception: " + ex);
        }
        #endregion
    }

    public override void OnPersonParachuteLanded(maddox.game.world.AiPerson person)
    {
        #region stats
        base.OnPersonParachuteLanded(person);
        try
        {
            stats.personParachute("Landed", person);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPersonParachuteLanded - Exception: " + ex);
        }
        #endregion
    }

    public override void OnPlayerArmy(maddox.game.Player player, int army)
    {
        #region stats
        base.OnPlayerArmy(player, army);
        try
        {
            stats.playerArmy(player, army);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPlayerArmy - Exception: " + ex);
        }
        #endregion

    }

    public override void OnPlayerConnected(maddox.game.Player player)
    {
        #region stats
        base.OnPlayerConnected(player);
        try
        {
            stats.pilotInfo(player);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPlayerConnected - Exception: " + ex);
        }

        #endregion
        // Your code here
    }
    public override void OnPlayerDisconnected(maddox.game.Player player, string diagnostic)
    {
        #region stats
        base.OnPlayerDisconnected(player, diagnostic);
        try
        {
            stats.playerDisconnect(player, diagnostic);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPlayerDisconnected - Exception: " + ex);
        }

        #endregion
        // Your code here
    }
   
    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        #region stats
        base.OnPlaceEnter(player, actor, placeIndex);
        try
        {
            Point2d actorPos = new Point2d(actor.Pos().x, actor.Pos().y);
            String startingGrid = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();
            stats.sortieBegin(player, actor, placeIndex, actorPos, startingGrid);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPlaceEnter - Exception: " + ex);
        }
        #endregion
        //add your code here
    }


    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        #region stats
        base.OnPlaceLeave(player, actor, placeIndex);
        try
        {
            stats.sortieEnd(player, actor, placeIndex);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnPlaceLeave - Exception: " + ex);
        }

        #endregion
        //add your code here
        Timeout(1, () =>
                { damageAiControlledPlane(actor); }
            );
    }

        public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);
        try
        {
            Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);
            String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();
            stats.aircraftLanded("CrashLanded", shortName, aircraft, actorPos, gridRef);
            System.Console.WriteLine("Stats.OnAircraftCrashLanded - ("+shortName+")");
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftCrashLanded - Exception: " + ex);
        }
        #endregion
        //add your code here
                Timeout (300, () =>
            { destroyPlane(aircraft); }
                        );
          }

    public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftTookOff(missionNumber, shortName, aircraft);
        try
        {
            stats.aircraftTakeoff(shortName, aircraft);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);
        }
        #endregion
        //add your code here
    }
                 
    public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft)
    {
          #region stats
          base.OnAircraftLanded(missionNumber, shortName, aircraft);
                    try
                    {
                  Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);
            String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();
            stats.aircraftLanded("Landed", shortName, aircraft, actorPos, gridRef);
                    }
                    catch (Exception ex)
                    {
            System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);
                    }
          #endregion
          //add your code here

          Timeout(300, () =>
            { destroyPlane(aircraft); }
            );
    }

    public override void OnActorDamaged(int missionNumber, string shortName, AiActor actor, AiDamageInitiator initiator, NamedDamageTypes damageType)
    {
        #region stats
        base.OnActorDamaged(missionNumber, shortName, actor, initiator, damageType);
        try
        {
            stats.missionActorDamaged(shortName, actor, initiator, damageType);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnActorDamaged - Exception: " + ex);
        }
        #endregion
        //add your code here

    }

    public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)
    {
        #region stats
        base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);
        try
        {
            stats.missionAircraftDamaged(shortName, aircraft, initiator, damageType);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftDamaged - Exception: " + ex);
        }
        #endregion
        //add your code here

    }

    public override void OnAircraftCutLimb(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, LimbNames limbName)
    {
        #region stats
        base.OnAircraftCutLimb(missionNumber, shortName, aircraft, initiator, limbName);
        try
        {
            stats.missionAircraftCutLimb(shortName, aircraft, initiator, limbName);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftCutLimb - Exception: " + ex);
        }
        #endregion
        //add your code here
    }

    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        #region stats
        base.OnActorDead(missionNumber, shortName, actor, damages);
        try
        {
            stats.missionActorDead(shortName, actor, damages);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnActorDead - Exception: " + ex);
        }
        #endregion
        //add your code here

    }

    public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)
    {
        #region stats
        base.OnActorDestroyed(missionNumber, shortName, actor);
        try
        {
            stats.actorDestroyed(shortName, actor);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnActorDestroyed - Exception: " + ex);
        }
        #endregion
        //add your code here

    }
    public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftKilled(missionNumber, shortName, aircraft);
        try
        {
            stats.aircraftKilled(shortName, aircraft);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftKilled - Exception: " + ex);
        }
        #endregion
        //add your code here

    }

    public override void OnBattleStoped()
    {
        #region stats
        base.OnBattleStoped();
        try
        {
            stats.battleStopped();
            // Loop through list of AiActors and destroy them all
            List<string> keys = new List<string>(allActors.Keys);
            for (int i = 0; i < keys.Count; i++)
            {
                AiActor a = allActors[keys[i]];
                AiAircraft aircraft = a as AiAircraft;
                if (aircraft != null)
                {
                    aircraft.Destroy();
                }
                else
                {
                    AiGroundActor aiGroundActor = a as AiGroundActor;
                    if (aiGroundActor != null)
                    {
                        aiGroundActor.Destroy();
                    }
                    else
                    {
                        System.Console.WriteLine("Stats.OnBattleStoped - Unknown Actor (" + a.Name()+") ShortName ("+keys[i]+")");
                    }
                }
            }
          // stats.disconnectStats();
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnBattleStoped - Exception: " + ex);
        }
        #endregion
        //add your code here
    }
//////////////////////////////////////////////////////////////////////////////////////////////////


 
}


salmo 03-10-2012 12:22 PM

Chat when aircraft takes off
Code:

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
    sendChatMessageTo(aircraft.Army(), "The aircraft took off", null);
    }

    private void sendChatMessageTo(int army, string msg, object[] parms)
    {  // send a chat message to all players in specified army (1=red; 2=blue)
        List<Player> Players = new List<Player>();
        // on Dedi the server:
        if (GamePlay.gpPlayer() != null)
        {
            if (GamePlay.gpPlayer().Army() == army || army == -1)
                Players.Add(GamePlay.gpPlayer());
        } //rest of the crowd
        if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
        {
            foreach (Player p in GamePlay.gpRemotePlayers())
            {
                if (p.Army() == army || army == -1)
                    Players.Add(p);
            }
        }
        if (Players != null && Players.Count > 0)
            GamePlay.gpLogServer(Players.ToArray(), msg, parms);
    }

Chat every 15 minutes
Code:

public class Mission : AMission
{
Stopwatch missionTimer = new Stopwatch();

public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        missionTimer.Start();
    }

public override void OnTickGame()
    {
        base.OnTickGame();

        if (missionTimer.Elapsed.Minutes >= 15)
        {
            missionTimer.Restart();
            sendChatMessageTo(-1, "Chat every 15 min", null);  // chat to all players
        }
    }

}


_79_dev 03-11-2012 09:58 PM

no use of Your code salmo, it has errors, unless i am wrong and dont know where to add it exacly...anyone else?

Smokeynz 03-11-2012 11:39 PM

Btw, please use code # holder when you post code, easier to handle.

just rebuilt the code layout in visual studio, already contains the code screen messages to players. plus on take off.

If you find the on take off lines in code, see how I added the on take off message in the following example.

note: Salmos examples for message cycles will actually conflict with timers in current code, they are only examples. Quite often you need to modify to use.

Code:

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftTookOff(missionNumber, shortName, aircraft);
        try
        {
            stats.aircraftTakeoff(shortName, aircraft);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);
        }
        #endregion

        sendChatMessageTo(aircraft.Army(), " 79 Dev says The aircraft took off", null);

        //add your code here
    }


_79_dev 03-12-2012 07:45 AM

ok thanks for help...

_79_dev 03-12-2012 07:56 AM

ok, if I use this code:

Code:

 
 public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftTookOff(missionNumber, shortName, aircraft);
        try
        {
            stats.aircraftTakeoff(shortName, aircraft);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);
        }

      #endregion

        sendChatMessageTo(aircraft.Army(), " _79_dev has a problem", null);

            //add your code here
    }

console gives me error anyway????

System.Exception: c:\Users\John\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\Kanalkampf\kanalkamp f_spawns.cs(446,9): error CS0103: The name 'sendChatMessageTo' does not exist in the current context
c:\Users\John\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\Kanalkampf\kanalkamp f_spawns.cs(446,27): error CS1501: No overload for method 'Army' takes 1 arguments
at LB33FuQ4EXuxyJPZ68D.GrT31TQ99wLitevXpuS.ATy34ceFvF k(String , Boolean , Boolean )
at LB33FuQ4EXuxyJPZ68D.GrT31TQ99wLitevXpuS.3LP34ebVrC U(String )
at LB33FuQ4EXuxyJPZ68D.GrT31TQ99wLitevXpuS.gMaqT2fu7O VhvSHaMehN(Object )
at LB33FuQ4EXuxyJPZ68D.GrT31TQ99wLitevXpuS.Xi734IyswC Q(String , Int32 )
=================================================
=================================================
System.Exception: c:\Users\John\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\Kanalkampf\kanalkamp f_spawns.cs(446,9): error CS0103: The name 'sendChatMessageTo' does not exist in the current context
c:\Users\John\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\Kanalkampf\kanalkamp f_spawns.cs(446,27): error CS1501: No overload for method 'Army' takes 1 arguments
at LB33FuQ4EXuxyJPZ68D.GrT31TQ99wLitevXpuS.Xi734IyswC Q(String , Int32 )
at 4YQguDGg7WLABsU9pm3.T8Lw4SGw95gwTxUSs13.ySFG6YYvRQ bIruAHfae(Object , Int32 )
at 4YQguDGg7WLABsU9pm3.T8Lw4SGw95gwTxUSs13.sWbmrit6GT (dL3MgPdYLnmRhd1hBIK )
=================================================

Smokeynz 03-12-2012 08:48 AM

ahh thats because it is actually...it isnt Chat..slap myself

sendScreenMessageTo

FG28_Kodiak 03-12-2012 08:56 AM

@_79_dev

Code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{


    private void sendChatMessage(string msg, params object[] args)
    {
        GamePlay.gpLogServer(null, msg, args);
    }


    private void sendChatMessage(Player player, string msg, params object[] args)
    {
        if (player != null)
            GamePlay.gpLogServer(new Player[] { player }, msg, args);
    }


    private void sendChatMessage(int army, string msg, params object[] args)
    {
        List<Player> Consignees = new List<Player>();

        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpLogServer(null, msg, args);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpLogServer(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
    }


    private void sendScreenMessage(string msg, params object[] args)
    {
        GamePlay.gpHUDLogCenter(null, msg, args);
    }


    private void sendScreenMessage(Player player, string msg, params object[] args)
    {
        if (player != null)
            GamePlay.gpHUDLogCenter(new Player[] { player }, msg, args);
    }


    private void sendScreenMessage(int army, string msg, params object[] args)
    {
        List<Player> Consignees = new List<Player>();

        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpHUDLogCenter(null, msg, args);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpHUDLogCenter(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
    }


 public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
        #region stats
        base.OnAircraftTookOff(missionNumber, shortName, aircraft);
        try
        {
            stats.aircraftTakeoff(shortName, aircraft);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);
        }

      #endregion

        sendChatMessage(aircraft.Army(), " _79_dev has a problem");

            //add your code here
    }

}


Smokeynz 03-12-2012 08:35 PM

@ kodiak, been noticing that with lists they tend to grow ever larger, in this case Consigness grows larger every time a sendChatMessage is called. A player name is added many times, old players who have left stay in the list.

So added in "Consignees.Clear();" , do you think this effective addition, and in the right place?


Code:


private void sendChatMessage(int army, string msg, params object[] args)
    {
        Consignees.Clear();
        List<Player> Consignees = new List<Player>();
        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpLogServer(null, msg, args);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpLogServer(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
    }


FG28_Kodiak 03-12-2012 09:01 PM

The List is not global nor unmanaged nor static, it's exist only in this method (local) and is deleted after the method is leaved (the destructor of the class is automaticaly called), so no Clear is needed.
And if Clear would needed it should be in this case on end of method.

(In your parser-problem the List is global and only deleted after the mission is ended. Thats the difference ;))


All times are GMT. The time now is 10:09 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.