View Single Post
  #6  
Old 02-27-2012, 12:35 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

The next block is triggers, this is a nasty area at the moment due to bugs in CLOD. Here though the focus is on Player activity not AI triggering AI. Some guides on scripting for AI has mostly being posted in other threads, in the script here I only use the AI and general trigger function as text to know what is happening and indirectly triggering player triggers.

The setup in this script is representing Radar ranges. In the mission I have a radar unit as the centre piece location and set the triggers as army pass through, 3 triggers same centre different ranges representing zones.

Static46 Stationary.Radar.EnglishRadar1 gb 12025.00 10315.00 50.00
Static44 Stationary.Radar.EnglishRadar1 de 30440.00 31260.00 45.00

[Trigger]
uk1 TPassThrough 5 2 12025 10315 15000
uk2 TPassThrough 5 2 12025 10315 10000
uk3 TPassThrough 5 2 12025 10315 5000
de1 TPassThrough 5 1 30440 31260 15000
de2 TPassThrough 5 1 30440 31260 10000
de3 TPassThrough 5 1 30440 31260 5000

in the script the 2D locations are set as the same centre point.

Point2d DEr1 = new Point2d(30440, 31260);// radar trigger(Red active)
Point2d UKr1 = new Point2d(12025, 10315);// radar trigger(Blue active)

Now the tricky bit,the triggers in the mission activate a list to take note of players within the mission where they are listed as Plebs, then I go through those Plebs and refernce against the 2D location and actual location of the Pleb(player). Then set true or false conditions for each zone range, outside all the zones all are false and nothing happens.

At the end of these checks is a call condition, if any of the above is true then call TrigMis(), this is the random mission selection trigger set up as a private void. The reason this is separate to the Ontrigger is that I also use the triggered loader for objectives aswell.(yes they are randomised aswell).

Before I leave the OnTrigger operation I have typical triggers for AI generating text to players, mainly for checks at this stage, however I do intend to have different missions loading for AI in addition to Player triggering the same zones.

Code:
 /*=========================================*/
    
    #region Mission triggers

    internal double getDistanceFromTo(Point2d startPoint, Point2d endPoint)
    {
        return startPoint.distance(ref endPoint);
    }
          
    public override void OnTrigger(int missionNumber, string shortName, bool active)
    {
        base.OnTrigger(missionNumber, shortName, active);        
            
        List<Player> plebs = new List<Player>();
        if (GamePlay.gpPlayer() != null)            
            plebs.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)            
            plebs.AddRange(GamePlay.gpRemotePlayers());

        plebs.ForEach(item =>
        {
            if (item.Place() != null)
            {
                Point2d ActorPos = new Point2d(item.Place().Pos().x, item.Place().Pos().y);
                //radar circles
                if (item.Army() == 1)
                {
                    if (getDistanceFromTo(ActorPos, DEr1) > 15000.1)
                    {
                        pDE1 = false;
                        pDE2 = false;
                        pDE3 = false;
                    }

                    if (getDistanceFromTo(ActorPos, DEr1) < 15000)
                        if (getDistanceFromTo(ActorPos, DEr1) > 10000.1)
                        {
                            pDE1 = true;
                            pDE2 = false;
                            pDE3 = false;
                        }

                    if (getDistanceFromTo(ActorPos, DEr1) < 10000)
                        if (getDistanceFromTo(ActorPos, DEr1) > 5000.1)
                        {
                            pDE1 = false;
                            pDE2 = true;
                            pDE3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, DEr1) < 5000)
                    {
                        pDE1 = false;
                        pDE2 = false;
                        pDE3 = true;
                    }                    
                }
                                                                                
                if (item.Army() == 2)
                {
                    if (getDistanceFromTo(ActorPos, UKr1) > 15000.1)
                    {
                        pUK1 = false;
                        pUK2 = false;
                        pUK3 = false;
                    }
                    if (getDistanceFromTo(ActorPos, UKr1) < 15000)
                        if (getDistanceFromTo(ActorPos, UKr1) > 10000.1)
                        {
                            pUK1 = true;
                            pUK2 = false;
                            pUK3 = false;

                        }
                    if (getDistanceFromTo(ActorPos, UKr1) < 10000)
                        if (getDistanceFromTo(ActorPos, UKr1) > 5000.1)
                        {
                            pUK1 = false;
                            pUK2 = true;
                            pUK3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, UKr1) < 5000)
                    {
                        pUK1 = false;
                        pUK2 = false;
                        pUK3 = true;
                    }
                }               
            }
        });

        if ((pDE1 | pDE2 | pDE3 | pUK1 | pUK2 | pUK3) == true)
            TrigMis();
                
          
        // ai as triggers (AI can be treated separately here)
        if (shortName.Equals("de1") && active)        
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        if (shortName.Equals("de2") && active)
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        if (shortName.Equals("de3") && active)
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        //if (shortName.Equals("de4") && active)
        //{
            //STxA(-1, shortName + " ai trigger check(blue bomber)");// rem out once checks complete 
        //}
        if (shortName.Equals("uk1") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        if (shortName.Equals("uk2") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        if (shortName.Equals("uk3") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        //if (shortName.Equals("uk4") && active)
        //{
            //STxA(-1, shortName + " ai trigger check(red bomber)");// rem out once checks complete 
        //}

        if (shortName.Equals("killkubel") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + " YOU KILLED BILL"); });
            ukS4 = 1;
        }
        if (shortName.Equals("safekubel") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + "BILL IS SAFE"); });            
        }

        if (shortName.Equals("killbob") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + " YOU KILLED BOB"); });
            deS4 = 1;
        }
        if (shortName.Equals("safebob") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + "BOB IS SAFE"); });            

        }
    }


    private void TrigMis()
    {
        /*===================de triggered mis=====================*/
        if (pDE1 == true)
        {
            switch (deS1)
            {
                case 1:
                    deS1 = 2;//on off switch for trigger operation
                    Timeout(rsdeS1.Next(100, 901), () => { deS1 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de1 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE1 = false;
        }

        if (pDE2 == true)
        {
            switch (deS2)
            {
                case 1:
                    deS2 = 2;//on off switch for trigger operation
                    Timeout(rsdeS2.Next(100, 901), () => { deS2 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de2 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE2 = false;
        }

        if (pDE3 == true)
        {
            switch (deS3)
            {
                case 1:
                    deS3 = 2;//on off switch for trigger operation
                    Timeout(rsdeS3.Next(100, 901), () => { deS3 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de3 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE3 = false;
        }
                
        /*===================uk triggered mis======================*/

        if (pUK1 == true)
        {
            switch (ukS1)
            {
                case 1:
                    ukS1 = 2;//on off switch for trigger operation
                    Timeout(rsukS1.Next(100, 901), () => { ukS1 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk1 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK1 = false;
        }

        if (pUK2 == true)
        {
            switch (ukS2)
            {
                case 1:
                    ukS2 = 2;//on off switch for trigger operation
                    Timeout(rsukS2.Next(100, 901), () => { ukS2 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk2 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK2 = false;
        }

        if (pUK3 == true)
        {
            switch (ukS3)
            {
                case 1:
                    ukS3 = 2;//on off switch for trigger operation
                    Timeout(rsukS3.Next(100, 901), () => { ukS3 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk3 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK3 = false;
        }

        /*===================de objective mis======================*/

        if (pDE4 == true)
        {
            switch (deS4)
            {
                case 1:
                    deS4 = 2;//on off switch for trigger operation
                    Timeout(rsdeS4, () => { deS4 = 1; });//timer reset function
                    //int bm = 0;
                    if (TM250s.Count > 0)
                        bm = rand.Next(0, TM250s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM250s[bm].TN);
                    Timeout(4.0, () => { STxA(-1, TM250s[bm].TM); });
                    Timeout(6.0, () => { STxA(1, TM250s[bm].TMR); STxA(2, TM250s[bm].TMB); });
                    break;
                case 2:
                    //Timeout(6.0, () => { STxA(-1, "Objective trigger already in action"); });// rem out once checks complete
                    Timeout(6.0, () => { STxA(1, TM250s[bm].TMR); STxA(2, TM250s[bm].TMB); });// repeat mission objective tx
                    break;
            }
            pDE4 = false;
        }

        /*===================uk objective mis======================*/

        if (pUK4 == true)
        {
            switch (ukS4)
            {
                case 1:
                    ukS4 = 2;//on off switch for trigger operation
                    Timeout(rsukS4, () => { ukS4 = 1; });// timer reset function
                    //int rm = 0;
                    if (TM150s.Count > 0)
                        rm = rand.Next(0, TM150s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM150s[rm].TN);
                    Timeout(4.0, () => { STxA(-1, TM150s[rm].TM); });
                    Timeout(6.0, () => { STxA(1, TM150s[rm].TMR); STxA(2, TM150s[rm].TMB); });
                    break;
                case 2:
                    //Timeout(6.0, () => { STxA(-1, "Objective trigger already in action"); });// rem out once checks complete
                    Timeout(6.0, () => { STxA(1, TM150s[rm].TMR); STxA(2, TM150s[rm].TMB); });// repeat mission objective tx
                    break;
            }
            pUK4 = false;
        }
    }

    #endregion

    /*=========================================*/

Ok now the second part to trigger operation, the loading of missions. These as you may of guessed are randomly selected as per sub missions, the lists are different for the triggered armies, ie Blue planes spawn for red triggering the radar ranges and visa versa. What spawns though is selected randomly exactly the same way as the core engine. The difference however,is there is a reset function timer. This is so that the trigger zones don’t load a whole pile of missions with every player crossing the line.

I should explain the reset funtion a little for those new to C#, here I am using a “Switch” which is a case selection tool, ie in the case of a number being 2 “case 2” is selected and all code within it is run. I simply have a number switching between 1 and 2, when it is 1 the loading sequence is active and when it is 2 the loader is inactive. Actived I set the case select number to 2 then a timer runs which sets a timer in motion for the random generated period to reset the case to 1 again. Hence switch operation.
The timer reset period though is randomised between 100 and 900 seconds where each zone can be in operation at different times depending how deep the player enters the radar region. For testing I have messages telling players that the zone is already activated, the intension is that players won’t normally get a message.

Last edited by Smokeynz; 03-01-2012 at 07:53 PM.
Reply With Quote