Lobby scripting help please?

Discussion regarding mapping and missions in here - we are talking FMB chaps. Perhaps you are building a mission for the server or for campaign? Talk to the experts - we always need people willing to muck in so don't be shy!

Moderators: Board of Directors, Command

Harmer
Posts: 25
Joined: Tue Apr 19, 2016 12:47 am
Location: Sydney, Australia.

Lobby scripting help please?

Post by Harmer » Mon Jul 18, 2016 10:27 pm

Hi guys.
Any chance of a bit of help here?
I've been running a Lobby for around three months now and have been slowly learning the beast that is known as FMB and some simple scripting that I've obtained from 1C.
I recently put a script in place to remove 'abandoned' player aircraft which is this:

Code: Select all

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

public class Mission : AMission
{
    public void _DespawnEmptyPlane(AiActor actor)
    {
        if (actor == null)
        { return; }

        Player[] Players = GamePlay.gpRemotePlayers();

        bool PlaneIsEmpty = true;

        foreach (Player i in Players)
        {
            if ((i.Place() as AiAircraft) == (actor as AiAircraft))
            {
                PlaneIsEmpty = false;
                break;
            }
        }

        if (PlaneIsEmpty)
        { (actor as AiAircraft).Destroy(); }
    }

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);
        Timeout(1, () =>
        {
            _DespawnEmptyPlane(actor);
        });
    }
}
This works really well except that it prevents mission AI from spawning in.
So next I added the following to it (inserted before the last bracket):

Code: Select all

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

    AiAction action = GamePlay.gpGetAction(ActorName.Full(missionNumber, shortName));
    if (action != null)
    {
        action.Do();
    }

}
This brought the AI back to life but prevented empty player aircraft from de-spawning.
Any help, ideas, please??
Last edited by Pitti on Wed Jul 20, 2016 7:52 pm, edited 1 time in total.
Reason: formatted the code snippets
Image

User avatar
Dickie
Group Captain
Group Captain
ACG Board
contributor
Posts: 13837
Joined: Sat Jul 14, 2012 12:15 pm
Location: Gloucestershire, England
Contact:

Re: Lobby scripting help please?

Post by Dickie » Tue Jul 19, 2016 4:23 pm

Harmer we can give you an object to include which does all of this shit if you want.

Or at least a copy of the code we use for this particular action. Pitti has it.

Harmer
Posts: 25
Joined: Tue Apr 19, 2016 12:47 am
Location: Sydney, Australia.

Re: Lobby scripting help please?

Post by Harmer » Tue Jul 19, 2016 9:31 pm

That would be a great help. Thanks.
Image

Pitti
Posts: 2255
Joined: Tue Jul 17, 2012 9:51 am
Location: Hannover, Germany

Re: Lobby scripting help please?

Post by Pitti » Wed Jul 20, 2016 8:21 pm

Hi Harmer

The faulty bit of your code is the foreach loop in the _DespawnEmptyPlane function. Since it only loops through the players. This causes the AI planes to be removed since they don't contain a player.
Harmer wrote:

Code: Select all

    public void _DespawnEmptyPlane(AiActor actor)
    {
        if (actor == null)
        { return; }

        Player[] Players = GamePlay.gpRemotePlayers();

        bool PlaneIsEmpty = true;

        foreach (Player i in Players)
        {
            if ((i.Place() as AiAircraft) == (actor as AiAircraft))
            {
                PlaneIsEmpty = false;
                break;
            }
        }

        if (PlaneIsEmpty)
        { (actor as AiAircraft).Destroy(); }
    }
    
Here's a script which should do the job:

Code: Select all

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

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

        // Destroys the aircraft if the player has left the not airborne aircraft
        if (actor != null && (actor is AiAircraft))
        {
            AiAircraft aircraft = (actor as AiAircraft);

            if ( !aircraft.IsAirborne() && IsActorDestroyable(actor))
                (actor as AiAircraft).Destroy();
        }
    }

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

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }

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

        // Destroys any landed aircaft after 1 second
        Timeout(1, () =>
        {
            aircraft.Destroy();
        });
    }

    // Removes GroundActors after their Task is completed
    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
            if (IsActorDestroyable(actor))
                (actor as AiGroundActor).Destroy();
    }
   
    // Checks if Actor is destroyable
    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;
    }
}
Hope that helps. :)

Cheers :salute:
Image

Harmer
Posts: 25
Joined: Tue Apr 19, 2016 12:47 am
Location: Sydney, Australia.

Re: Lobby scripting help please?

Post by Harmer » Thu Jul 21, 2016 1:51 am

Thanks for your time and help, I copied the script exactly as posted but unfortunately it didn't work correctly for me.

Firstly, I just want check that my lobby realism settings are not causing a conflict:
http://imgur.com/a/2IxAH
Secondly, the de-spawn worked fine. However I couldn't get the mission AI to spawn in.
Image

User avatar
Dickie
Group Captain
Group Captain
ACG Board
contributor
Posts: 13837
Joined: Sat Jul 14, 2012 12:15 pm
Location: Gloucestershire, England
Contact:

Re: Lobby scripting help please?

Post by Dickie » Thu Jul 21, 2016 3:46 pm

Are you spawning them in from a sub-script or at the start? More info needed. If you are just spawning them in at the start of a mission then you don't need a script. If not, if using a trigger, then some triggers are problematic and don't work properly, and in any case they are bugged in that you need both script and trigger properties in the .mis file.

Harmer
Posts: 25
Joined: Tue Apr 19, 2016 12:47 am
Location: Sydney, Australia.

Re: Lobby scripting help please?

Post by Harmer » Fri Jul 22, 2016 1:33 am

I don't use any scripting for missions (i.e. no .cs files created). My missions are PvE. I create a mission with two parts to fill the Ops night, so we land after the first fight and then re-spawn to 're-arm/repair' for the second part of the mission.
I generally set an enemy AI spawn for the first part by using the TTime routine (usually to spawn in around 15mins after the start of the mission - to give us chance to take off and form up). For the second part I generally use the Target Pass Through (that in itself is problematic since it often generates the AI twice - once for trigger entry and once for trigger exit), I use this because I've never been able to get the TGroup Destroyed routine to work properly. The only reason why I'm attempting to use a script is that sometimes the players may have problems (keybindings, wrong aircraft model, etc. etc.) and when they change 'planes the original one will get taken over by AI (and so their discarded aircraft remain in the game) and I just wanted to eradicate this minor niggle. It seems that if a player aircraft is landed successfully with no ammunition, then a re-spawn will erase that 'plane.
With only a dozen missions I've done for the group, this is about the limit of my 'expertise' in FMB, I'm afraid and I'm still not sure whether I've provided you with the info you need.
Image

User avatar
Dickie
Group Captain
Group Captain
ACG Board
contributor
Posts: 13837
Joined: Sat Jul 14, 2012 12:15 pm
Location: Gloucestershire, England
Contact:

Re: Lobby scripting help please?

Post by Dickie » Fri Jul 22, 2016 8:58 am

You have. Trigger passthrough is tough because iirc if you keep passing through it it keeps spawning more in. TTime is reliable though. Spawning is generally a bit buggy which is why we have our own software to manage it, although it's not used in anger atm. In fact this is a prompt for me to have a chat with our chap about it - he's a crazy developer who just doesn't stop writing COD interface software for us, and recently he wrote a tool called Spawnstar which is effectively a seperate tool which will manually spawn in AI, and despawn it, on command. I'd need to chat to him though.

User avatar
Donkey
Pilot Officer
Pilot Officer
Adjutant
Staff
Posts: 2829
Joined: Thu Jul 03, 2014 9:21 am
Location: Luxembourg

Re: Lobby scripting help please?

Post by Donkey » Fri Jul 22, 2016 11:05 am

Oi! Less of the crazy!
Image

User avatar
Dickie
Group Captain
Group Captain
ACG Board
contributor
Posts: 13837
Joined: Sat Jul 14, 2012 12:15 pm
Location: Gloucestershire, England
Contact:

Re: Lobby scripting help please?

Post by Dickie » Fri Jul 22, 2016 12:26 pm

Down boy! :D

Post Reply