Official 1C Company forum

Official 1C Company forum (http://forum.1cpublishing.eu/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.1cpublishing.eu/forumdisplay.php?f=203)
-   -   Help - SpawnScript/Triggers (http://forum.1cpublishing.eu/showthread.php?t=31460)

Bluesman 04-24-2012 03:26 PM

Help - SpawnScript/Triggers
 
Hi,

I'm not a "script expert". I'm trying to learn basics and do simple things...
First, wanted to create a mission for dogfight training in our squadron. I need delay spawn for a group of enemies and after them get destroyed they respawn again, in a infinite loop.

Tried using Triggers and Actions, but TGroupDestroy doesn't work. Delay is OK.
So moved to script solution... I read a lot of texts about script, but again, only delay spawn worked...

Could someone post a simple script or solution for that?
Its simple: spawn group after XX seconds and respawn if destroyed.

Thanks very much!

=AN=Bluesman

FG28_Kodiak 04-25-2012 05:31 PM

1 Attachment(s)
A training mission i create for my squad.

In the script i don't use triggers. Only actions to create new Airgroups.
I store enemy planes in a list, and remove a plane if it is destroyed or killed (killed is earlier for example you kill the pilot, the plane is killed, destroyed is after crashing to ground). If the list count is on a low number i create a new Airgroup.

Code:

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


public class Mission : AMission
{

    List<AiAircraft> enemyAircraftsInGame = new List<AiAircraft>();
    const int EnemyArmy = 1; // reds are enemy change to 2 for blues
    const int MinNumberEnemyPlanesAlive = 1; // number of enemy planes left before creating new airgroup
 
    private Queue<string> ActionQueue = new Queue<string>(new string[] { "createAnsons", "createBlenheims", "createMosquitos" });
                                   
 
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();

        MissionNumberListener = -1;
    }


    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        if (actor is AiAircraft && actor.Army() == EnemyArmy)
            enemyAircraftsInGame.Add(actor as AiAircraft);
    }


    public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftKilled(missionNumber, shortName, aircraft);
       
        enemyAircraftsInGame.RemoveAll(item => item == aircraft);

        if (enemyAircraftsInGame.Count == MinNumberEnemyPlanesAlive)
        {
            string actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);
 
            AiAction action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();
        }
    }


    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        base.OnActorDead(missionNumber, shortName, actor, damages);


        if (actor is AiAircraft)
        {
            enemyAircraftsInGame.RemoveAll(item => item == actor as AiAircraft);

            if (enemyAircraftsInGame.Count == MinNumberEnemyPlanesAlive)
            {
                string actionName = ActionQueue.Dequeue();
                ActionQueue.Enqueue(actionName);

                AiAction action = GamePlay.gpGetAction(actionName);
                if (action != null) action.Do();
            }
        }
    }
   

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        if (IsActorDestroyable(actor))
            if(actor is AiCart)
            (actor as AiCart).Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }
}

Added a multiplayer mission for blue there is a Spawn-Area (Airstart 3500m) the red tragets fly around the island.

Bluesman 04-25-2012 08:40 PM

Ty very much!

I'll test your mission tonight!

S!

=AN=Bluesman

melasuda 04-26-2012 10:54 AM

Hi Kodiak

First thanks for this scrip.

Second, i have a cuestion.

If i need to create 2 group at same time, how can i edit this scrip?

Exmple: 4 bomber and 2 scolt.

FG28_Kodiak 04-26-2012 11:19 AM

for example:
Code:

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


public class Mission : AMission
{

    List<AiAircraft> enemyAircraftsInGame = new List<AiAircraft>();
    const int EnemyArmy = 1; // reds are enemy change to 2 for blues
    const int MinNumberEnemyPlanesAlive = 1; // number of enemy planes left before creating new airgroup

    private Queue<string> ActionQueue = new Queue<string>(new string[] { "createAnsons", "createSpits1", "createBlenheims", "createSpits2", "createMosquitos", "createSpits3"});


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

        MissionNumberListener = -1;
    }


    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        if (actor is AiAircraft && actor.Army() == EnemyArmy)
            enemyAircraftsInGame.Add(actor as AiAircraft);
    }


    public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftKilled(missionNumber, shortName, aircraft);

        enemyAircraftsInGame.RemoveAll(item => item == aircraft);

        if (enemyAircraftsInGame.Count <= MinNumberEnemyPlanesAlive)
        {
            string actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);

            AiAction action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();


            actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);

            action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();


        }
    }


    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        base.OnActorDead(missionNumber, shortName, actor, damages);


        if (actor is AiAircraft)
        {
            enemyAircraftsInGame.RemoveAll(item => item == actor as AiAircraft);

            if (enemyAircraftsInGame.Count <= MinNumberEnemyPlanesAlive)
            {
                string actionName = ActionQueue.Dequeue();
                ActionQueue.Enqueue(actionName);

                AiAction action = GamePlay.gpGetAction(actionName);
                if (action != null) action.Do();


                actionName = ActionQueue.Dequeue();
                ActionQueue.Enqueue(actionName);

                action = GamePlay.gpGetAction(actionName);
                if (action != null) action.Do();


            }
        }
    }


    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        if (IsActorDestroyable(actor))
            if (actor is AiCart)
                (actor as AiCart).Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

}

added the Action Names for Fighter spawn to the Queue.
First is Bomber, second is fighter.

then i modify the
Code:

if (enemyAircraftsInGame.Count <= MinNumberEnemyPlanesAlive)
        {
            string actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);

            AiAction action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();


            actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);

            action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();


        }

so it reads the action two times from the Queue. First creates the bombers the second the fighters or vice versa, depens on the actions you created. ;)

melasuda 04-26-2012 11:38 AM

thanks

aus3620 08-27-2012 05:14 AM

Shooting Range
 
Hello,

I downloaded shootingrange.zip and extracted the files into the 1C SoftClub folder. I can see the spawn point on the map in FMB. The Actions and Script have loaded in Scipt.

But when I run the mission I do not see the spawn point or am able to fly the blue plane I selected (e3b). Is there something else I need to do?

thx

FG28_Kodiak 08-27-2012 07:31 AM

You must host in multiplayer as a server. Then start the battle, choose the blue side (click the german/italian flag), then you see the spawnplace, select it ...


All times are GMT. The time now is 02:12 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2007 1C Company. All rights reserved.