HOW TO: Make AI Land in Capital Ships

Started by Ascertes, November 03, 2016, 01:57:33 PM

Previous topic - Next topic
November 03, 2016, 01:57:33 PM Last Edit: November 09, 2018, 11:41:21 AM by Ascertes
This method is not mine! It was developed by Maveritchell! I'm just making the tutorial. Some code contributions by AQT!

Hello fellow SWBF2 Modders! If you've ever played a space battle before, you know that you can land inside enemy hangars with a ship and make your enemies' lives miserable. Harassing the enemy inside their own ship is a quick way to destroy their internal systems without the hassle of having to knock out enemy shields.

...Except the AI don't do it. In singleplayer, it's a complete waste of time to put yourself on defense in the hangar, because you don't have to worry about sabotage or enemy infiltration. Of course, for those who like a bit more of a challenge, this is a let down. Today, I'm going to tell you how to make those foolish AI land in hangars.

Step by Step Guide
The first thing you'll want to do is read up on the FlyerSplineFollowing.txt file. This is located in C:/BF2_ModTools/documentation. If you don't have the mod tools...you shouldn't be reading this.

The text file itself is pretty long and overwhelming, so I'll only give information that's important in the guide:
1. Create a path, just like you would for a CP spawn. The AI fighter units will follow this line.

2. Name the path EntityPath XYZ, for example. EntityPath is important though. That needs to stay.

3. Now see that box in the lower left that let's you set properties? Go there next.

NOTE: Before I continue, here's some important information. Every flying vehicle has a PathFollowerClass variable in its ODF file. Go to the ODF you want the AI to be able to land with, and find its PathFollowerClass. For example, the Droid Gunship's variable is "transport".

4. In the property box, type Class. If you want more than 1 type of vehicle to follow this path, name them Class1, Class2, etc.

5. For the value, add the PathFollowerClass. In this case, transport. Hit Add Property, and it will apply what you've done to the spline, or path.

6. Next, set the path nodes so they start in the middle of space, and end inside the enemy hangar.

7. As a safety precaution, go back to the property boxes and add Direction for the property, and 1.0 for the value. This will ensure the AI will follow the path from node 0 to the end. Otherwise they may try to start from the other end, with disastrous results!

8. Now make a new region and put it inside the hangar. I recommend NOT using the hangar control region for this as if you have it covering the entire hangar, the AI will land the ship half inside and half outside the hangar. Name the region whatever you want. Set the property/type of the region to the same thing as the name. Make sure the path you placed goes inside the new region.

9. Alright, we're done with ZE for now. SAVE FIRST, then close. Open up your ABC_cmn.

10. Add the commented out line:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
-- SPAX - Clone Wars Template  Common File
-- Common script that shares all setup information
--

ScriptCB_DoFile("setup_teams")
--EnableFlyerPath("Land1",1)

The last line is what you need to add. Make sure to uncomment it. Replace Land1 with the name of the path you placed. Don't include the EntityPath part of the name. You'll need to do this step for every EntityPath you place in ZE, otherwise they won't work.

SIDE NOTE: If you want to save yourself a little hassle,  when you're making the path properties add Name to the property box, and give it a name. So you could have 2 paths both with the name value of XYZ. When you go into your LUA, you will only need to do the last line of the above code once. The Name property overwrites the name in the path list of ZE.

11. Here's the fun part. Save your ABC_cmn LUA and exit. Now go to your ABC_ass, ctf, whatever. Find this section:
function ScriptPostLoad()
    SetupObjectives()
   
    SetupShields()
    SetupDestroyables()
    SetupTurrets()

    AddAIGoal(REP, "Deathmatch", 100)
    AddAIGoal(CIS, "Deathmatch", 100)

DisableSmallMapMiniMap()
end


12. Once you've found it, copy the following code:
ActivateRegion("rep-cp1con")
Land = OnEnterRegion(
   function(region, character)
      if GetEntityClass(GetCharacterVehicle(character)) == FindEntityClass("cis_fly_droidgunship") then
            print("flyer found :D")
         ship = GetCharacterVehicle(character)
         EntityFlyerLand(ship)
         SetProperty(ship, "DisableTime", 1e+37)
         SetProperty(ship, "DisableTime", 0)
            print("Houston, the Eagle has landed")
      end
      if not IsCharacterHuman(character) then
         ExitVehicle(character)
      end
   end,
   "rep-cp1con"


13. Now, paste it so your LUA looks like this:
function ScriptPostLoad()
    SetupObjectives()
   
    SetupShields()
    SetupDestroyables()
    SetupTurrets()

    AddAIGoal(REP, "Deathmatch", 100)
    AddAIGoal(CIS, "Deathmatch", 100)

  DisableSmallMapMiniMap()
ActivateRegion("rep-cp1con")
Land = OnEnterRegion(
   function(region, character)
      if GetEntityClass(GetCharacterVehicle(character)) == FindEntityClass("cis_fly_droidgunship") then
            print("flyer found :D")
         ship = GetCharacterVehicle(character)
         EntityFlyerLand(ship)
         SetProperty(ship, "DisableTime", 1e+37)
         SetProperty(ship, "DisableTime", 0)
            print("Houston, the Eagle has landed")
      end
      if not IsCharacterHuman(character) then
         ExitVehicle(character)
      end
   end,
   "rep-cp1con"
)
end


14. Good? Good. Now you need to edit some variables. In the code, anywhere you see "rep-cp1con", replace it with the name of the region you created in step 8. Secondly, see where it says "cis_fly_droidgunship"? Replace that with the ODF name of the flier you want to land.

15. Save. Close. Munge. Boom. Done. Well, almost...

16. More than likely you'll want the AI to land in more than one hangar. If this is the case, copy the code in step 12 and paste it below the close parenthesis at the end of the code in step 13. Adjust the variables as you need to. Remember, you'll need to create whole new paths and regions for additional landing zones.


Whew! That was lengthy tutorial, but guess what? You're done! Enjoy :)

CREDITS:
1. Maveritchell
2. Marth8880
3. thelegend
4. AnthonyBF2
5. AQT
"Birth, pain, fear, death; the cycle of existence." -Dread Master Calphayus.

SWBF1 Maps: Tatooine: Mos Anek, Kashyyyk: Village, Naboo: Province, Tatooine: Gulch.

SWBF2 Maps: Space Carida.

This is very cool.However i still think if someone just make a simple conquest test map with 1 example in there it will be much more easier for some people :)

Quote from: Ginev on November 03, 2016, 05:03:34 PM
This is very cool.However i still think if someone just make a simple conquest test map with 1 example in there it will be much more easier for some people :)

Probably, but for people who want a space map without other work, this will get them there! Better to give people options imo.
"Birth, pain, fear, death; the cycle of existence." -Dread Master Calphayus.

SWBF1 Maps: Tatooine: Mos Anek, Kashyyyk: Village, Naboo: Province, Tatooine: Gulch.

SWBF2 Maps: Space Carida.