View Single Post
  #54  
Old 02-03-2012, 05:00 PM
Gromic's Avatar
Gromic Gromic is offline
Approved Member
 
Join Date: Aug 2010
Posts: 77
Default

Evening Chaps,

got a strange problem using a TTime trigger that isn't firing while being called though a submission that is loaded via the GamePlay.gpPostMissionLoad function.

If I load the mission by itself then the TTime trigger works fine. Apparently there's something within the main mission that seems to void a TTime trigger within a submission.

I've read through the entire thread but since I'm a noob at coding, I haven't found anything that adresses the issue specifically.

I'm sure most here will recognise the basic script. The Bold portion in the script below loads the submission:

Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;

public class Mission : AMission
{
 

 AiAircraft PlayerPlane;

// destroys aircraft abandoned by a player.
    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 OnPlaceLeave (Player player, AiActor actor, int placeIndex) 
    {
		base.OnPlaceLeave (player, actor, placeIndex);
		Timeout (1, () =>
				{damageAiControlledPlane (actor);}
			);
	}

	public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
		base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);
		Timeout (300, () =>
            { destroyPlane(aircraft); }
			);
	}
    public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);
        Timeout(300, () =>
            { destroyPlane(aircraft); }
            );
    }

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

//////////////////////////////////////////////////////////////////////////////
// Loads random submissions

        public override void OnTrigger(int missionNumber, string shortName, bool active) 
        {
            if ("trigger01".Equals(shortName)  && active) 
            { 
                DoDamage();
            }
            GamePlay.gpGetTrigger(shortName).Enable = false;
        }
    
    
        private void DoDamage()
        {
            PlayerPlane = (AiAircraft)GamePlay.gpPlayer().Place();              
            // Initial Mission - can be any type    
            Random RandomIncident = new Random();
            
        	switch (RandomIncident.Next(1, 13))
			{
			    case 1:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB1.mis");        
			        break;
			    case 2:	
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB2.mis");       
			        break;
			    case 3:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB3.mis");
			        break;
			    case 4:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB4.mis");
			        break;
			    case 5:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB5.mis");
			        break;
			    case 6:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB6.mis");
			        break;
			    case 7:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB7.mis");
			        break;
			    case 8:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB8.mis");
			        break;
			    case 9:
			        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB9.mis");
            	                break;
            	            case 10:
            	                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB10.mis");
            	                break;
                            case 11:
            	                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB11.mis");
            	                break;
            	            case 12:
            	                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB12.mis");
            	                break;
			}        	
        	
        }
        public override void OnTickGame()
        {


		    // loads the 1st sub-mission in 5 min and repeates it every 10 min.
            if (Time.tickCounter() % 18000 == 9000) // 18000 = 10 min repeat. 9000 = 5 min delay. 
            // the 1st figure above must be always larger than 2nd!
            {
                Random RandomIncident = new Random();
		        // Fighter mission generation
                switch (RandomIncident.Next(1, 7))
                {
                    case 1:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB1.mis");
                        break;
                    case 2:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB3.mis");
                        break;
                    case 3:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB4.mis");
                        break;
                    case 4:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB9.mis");
                        break;
                    case 5:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB11.mis");
                        break;
                    case 6:
                        GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB12.mis");
                        break;

                }

            }

	    // Loads Missions consecutively

		if (Time.tickCounter() % 756000 == 1800) // 756000 = 420 (7 Hours) min repeat. 1800 = 1 min delay. 
  		{
      		GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB7.mis");
            	{
                	GamePlay.gpHUDLogCenter("Monday, August 12 1940 08:01 am");
            	}
		}
        /* if (Time.tickCounter() % 108000 == 1800) // 108000 = 60 min repeat. 18000 = 10 min delay. 
        {
            GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB6.mis");
            {
                GamePlay.gpHUDLogCenter("Monday, August 12 1940 08:00 am");
            }
        }
        if (Time.tickCounter() % 108000 == 1800) // 108000 = 60 min repeat. 18000 = 10 min delay. 
        {
            GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB6.mis");
            {
                GamePlay.gpHUDLogCenter("Monday, August 12 1940 08:00 am");
            }
        }
        if (Time.tickCounter() % 108000 == 1800) // 108000 = 60 min repeat. 18000 = 10 min delay. 
        {
            GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB6.mis");
            {
                GamePlay.gpHUDLogCenter("Monday, August 12 1940 08:00 am");
            }
        }
        if (Time.tickCounter() % 108000 == 1800) // 108000 = 60 min repeat. 18000 = 10 min delay. 
        {
            GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/GHSCRIPTED/SUB6.mis");
            {
                GamePlay.gpHUDLogCenter("Monday, August 12 1940 08:00 am");
            }
        } */
    }

}
And here is the script that is loaded with the submission itself. The bolded portions call the trigger itself.

Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
using maddox.GP;

public class Mission : AMission
{
    private const int All = -1;
    private const int Allies = 1;
    private const int Axis = 2;

    public override void OnMissionLoaded(int missionNumber)
    {
        base.OnMissionLoaded(missionNumber);
    }


    public override void OnTrigger(int missionNumber, string shortName, bool active)
    {
       base.OnTrigger(missionNumber, shortName, active);

        //Triggers for RAF actions
        //Report Examples
        //SendScreenMessageTo(Allies, "Message to Red");
        //SendScreenMessageTo(Axis, "Message to Blue");
        if ((shortName == "LW_Spawn_7A") && active)
        {
            AiAction action = GamePlay.gpGetAction("LW_Spawn_7A"); //TriggerName
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "LW_Spawn_7B") && active)
        {
            AiAction action = GamePlay.gpGetAction("LW_Spawn_7B"); //TriggerName
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "LW_Spawn_7C") && active)
        {
            AiAction action = GamePlay.gpGetAction("LW_Spawn_7C"); //TriggerName
            if (action != null)
            {
                action.Do();
            }

        }

        if ((shortName == "ALL_Radio_7A") && active)
        {
            AiAction action = GamePlay.gpGetAction("ALL_Radio_7A"); //TriggerName
            SendScreenMessageTo(Allies, "CH reports heavy buildup rallying at AX-16 flying low. We're loosing contact.");
            SendScreenMessageTo(Axis, "Bodo reports EG210 massing at AX-16.  Low level Jabo to attack radar at AP-17 and AR-18.");
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "LW_Radio_7A") && active)
        {
            AiAction action = GamePlay.gpGetAction("LW_Radio_7A"); //TriggerName
            SendScreenMessageTo(Axis, "Bodo reports EG210 now AR-16. Attacking AP-17 and AR-18 radar in 5 minutes.");
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "GB_Radio_7A") && active)
        {
            AiAction action = GamePlay.gpGetAction("GB_Radio_7A"); //TriggerName
            SendScreenMessageTo(Allies, "SC reporting: Chain home station AP-17 Eastbourne is under attack!");
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "GB_Radio_7B") && active)
        {
            AiAction action = GamePlay.gpGetAction("GB_Radio_7B"); //TriggerName
            SendScreenMessageTo(Allies, "SC reporting: Chain home station AR-18 Rye is under attack!");
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "GB_Radio_7C") && active)
        {
            AiAction action = GamePlay.gpGetAction("GB_Radio_7C"); //TriggerName
            SendScreenMessageTo(Allies, "SC reporting: Chain home station AV-21 Dover is under attack!");
            if (action != null)
            {
                action.Do();
            }

        }
        if ((shortName == "GB_Radio_7D") && active)
        {
            AiAction action = GamePlay.gpGetAction("GB_Radio_7C"); //TriggerName
            SendScreenMessageTo(Allies, "SC reporting: Chain home station AS-22 Dunkirk is under attack!");
            if (action != null)
            {
                action.Do();
            }

        }
        GamePlay.gpGetTrigger(shortName).Enable = false;
    }
    private void SendScreenMessageTo(int army, string message)
    {
        if (army == All)
        {
            GamePlay.gpHUDLogCenter(message);
        }
        else
        {
            //Singleplayer (for Testing)
            if (GamePlay.gpRemotePlayers() == null ||
                GamePlay.gpRemotePlayers().Length <= 0)
            {
                if (GamePlay.gpPlayer() != null &&
                    GamePlay.gpPlayer().Army() == army)
                {
                    GamePlay.gpHUDLogCenter(message);
                }
            }
            else // Multiplayer
            {
                var playersInArmy = new List<Player>();

                foreach (var player in GamePlay.gpRemotePlayers())
                {
                    if (player.Army() == army)
                    {
                        playersInArmy.Add(player);
                    }
                }

                GamePlay.gpHUDLogCenter(playersInArmy.ToArray(), message);
            }
        }
    }
}
The triggers themselves are also properly defined within the .mis file of the submission, so that shouldn't be a problem. As stated, everything works fine when I load the mission by itself.

I'd appreciate any help or suggestions.

Danke schön

Gromic
__________________
I5-750 @ 3,8GHz / MSI P55-GD65 / MSI GTX570 Twin Frozr II / 4x2GB G.Skill 1600MHz / Corsair TX650 PSU / RAID 0 2x640GB WD Black
W7 Pro x64 SP1 / MS FFB2 +Saitek X45 / Freetrack + NP Clip Pro + PS3 Eye / Samsung BX2450 24" HDMI LED

Last edited by Gromic; 02-03-2012 at 07:03 PM. Reason: Format Edit
Reply With Quote