View Single Post
  #14  
Old 04-08-2012, 06:40 PM
_79_dev _79_dev is offline
Approved Member
 
Join Date: Sep 2010
Location: Dublin
Posts: 242
Default

i gave it a go : this is my script

PHP 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 = "5./JG27 SERVER";
    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;
    
    
    
////////////////setting chat messages
    
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);
    }
    
////////////////testing voice messages
    
     
public void sendMessagesToAirgroup(AiAirGroup from, double maxDistance)
    {

        
AiAirGroup[] EnemyAirgroups;
        
Point3d StartPos = new Point3d(from.Pos().x, from.Pos().y, 1.0);

        
EnemyAirgroups = GamePlay.gpAirGroups((from.Army() == 1) ? 2 : 1);

        
int i = 0;

        foreach (
AiAirGroup aag in EnemyAirgroups)
        {
            
Point3d enemyPosition = new Point3d(aag.Pos().x, aag.Pos().y, 1.0);

            if (
from.Pos().distance(ref enemyPosition) < maxDistance)
            {
                
                
string sectorName = GamePlay.gpSectorName(aag.Pos().x, aag.Pos().y);

                
string[] splittet = sectorName.Split(',');
                
string alpha = splittet[0];
                
string number = "n" + splittet[1];

                
AiAircraft LeaderPlane = (from.GetItems()[0] as AiAircraft);

                
Timeout(i, () =>
                {
                    (
LeaderPlane as AiAircraft).SayToGroup(from as AiAirGroup, "Enemy_planes");
                });


                
Timeout(i += 2, () =>
                {
                    
LeaderPlane.SayToGroup(from, "In_square");
                });

                
Timeout(i += 2, () =>
                {
                    
LeaderPlane.SayToGroup(from, alpha);
                });
                
Timeout(i += 2, () =>
                {
                    
LeaderPlane.SayToGroup(from, number);
                });

                
i += 2;
            }
        }
    }


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

        if (
Time.tickCounter() % 600 == 299)
        {
            foreach(
AiAirGroup aag in GamePlay.gpAirGroups(1))
                
sendMessagesToAirgroup(aag, 100000.0);
        
        }
    


    
// loading sub-missions
    
    
          #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
    ///////////////////////
    // server info every 5 min
    
     
if (Time.tickCounter() % 9000 == 1800)  
       
       {

       
sendChatMessage((-1), "PLEAS VISIT www.5jg27.net TO CHECK STATS");

        }
    
    
    
// load ground objects
       
if (Time.tickCounter() % 2592000 == 300)  
       {
           
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/kanalkampf/kanalkampf_ground.mis");
    
       }

// loads Mission1
       
if (Time.tickCounter() % 2592000 == 12600)  
       {
           
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/kanalkampf/kanalkampf_Air1Red1Blue1.mis");
                      
       }

// loads Rescue
       
if (Time.tickCounter() % 2592000 == 95000)  
       {
           
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/kanalkampf/kanalkampf_Airsearescue.mis");
                      
       }
    

// loads Mission2
       
if (Time.tickCounter() % 2592000 == 66600)  
       {
           
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/kanalkampf/kanalkampf_Air2Red2.mis");
           
           
       }

// loads Mission3
       
if (Time.tickCounter() % 2592000 == 144000)  
       {
           
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/kanalkampf/kanalkampf_Air3Blue2.mis");
          
           
       }
       


    }
 
////////////////////////////////////////////////////////////////////////////////////////////////////

//

// 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 OnAircraftLimbDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiLimbDamage limbDamage)
    {
        
#region stats
        
base.OnAircraftLimbDamaged(missionNumber, shortName, aircraft, limbDamage);
        try
        {
            
stats.aircraftLimbDamaged(shortName, aircraft, limbDamage);
        }
        catch (
Exception ex)
        {
            
System.Console.WriteLine("Stats.OnAircraftLimbDamaged - 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
    
}
//////////////////////////////////////////////////////////////////////////////////////////////////


 
} 
console gives that every 20-30sec

PHP Code:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at maddox.game.IBattle.OnTickGame()
at maddox.game.GameDef.tickGame()
at uRQMLX6vlhrpBgfbWjC.eBu9gE6TS67VJSjj97t.Hwe9ADXhn0AxpFMw7lv0(Object )
at uRQMLX6vlhrpBgfbWjC.eBu9gE6TS67VJSjj97t.8An9qLaqwNd()
at 93bAC3gAbOoH4F4mw53.Pljjc2gU48bdLjaViwW.Af3oASrUh27g1Z9hCmya(Object )
at 93bAC3gAbOoH4F4mw53.Pljjc2gU48bdLjaViwW.9B8JM8x755B(Boolean , Boolean )
=================================================
=================================================
System.NullReferenceException: Object reference not set to an instance of an object.
Server stack trace:
at Mission.sendMessagesToAirgroup(AiAirGroup from, Double maxDistance)
at Mission.OnTickGame()
at maddox.game.ABattle.OnTickGame()
at maddox.game.world.Strategy.OnTickGame()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at maddox.game.IBattle.OnTickGame()
at maddox.game.GameDef.tickGame()
at uRQMLX6vlhrpBgfbWjC.eBu9gE6TS67VJSjj97t.Hwe9ADXhn0AxpFMw7lv0(Object )
at uRQMLX6vlhrpBgfbWjC.eBu9gE6TS67VJSjj97t.8An9qLaqwNd()
at 93bAC3gAbOoH4F4mw53.Pljjc2gU48bdLjaViwW.Af3oASrUh27g1Z9hCmya(Object )
at 93bAC3gAbOoH4F4mw53.Pljjc2gU48bdLjaViwW.9B8JM8x755B(Boolean , Boolean )
================================================= 
is that because there is no airgroups loaded yet?
__________________

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