How to Get AI to Land in Hangars? [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

How to Get AI to Land in Hangars? [Solved]

Post by Ascertes »

Apologies if this has been asked before (I've just registered, and I didn't see anything about this using the search function,) but I'm wondering if its possible, or how, to get AI to land in hangars for space battles. I'm currently working on a space map (my first bf2 project) and I would like to have this as a feature. I've tried adding Land Hintnodes but they don't appear to work for the AI. Anyone know anything about this? Help is always appreciated. :)
Last edited by Ascertes on Tue Nov 01, 2016 8:22 pm, edited 1 time in total.
Samee3
First Lance Corporal
First Lance Corporal
Posts: 123
Joined: Sun Jul 05, 2015 5:07 pm
Projects :: BF2 Refresh Mod
Games I'm Playing :: Empire at War
xbox live or psn: VaporousFern310
Location: California, USA

Re: How to Get AI to Land in Hangars?

Post by Samee3 »

The short answer is: it's not possible.
However, there is a space mission in The Dark Times mod (can't remember which) where there are "flyers" that take off from a friendly hanger and land in an opposing hanger. The problem with this method is that they are not actual AI, but simply a model scripted to travel from point A to point B along a predefined path.

Also, it would not hurt to read up on the BF2 Limitations
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How to Get AI to Land in Hangars?

Post by Marth8880 »

There's a way to do it, but it requires some complicated-ish scripting. The core elements of it are OnEnterRegion() and EntityFlyerLand() (or EntityFlyerInitAsLanded(), forgot which).
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Samee3 wrote:The short answer is: it's not possible.
However, there is a space mission in The Dark Times mod (can't remember which) where there are "flyers" that take off from a friendly hanger and land in an opposing hanger. The problem with this method is that they are not actual AI, but simply a model scripted to travel from point A to point B along a predefined path.

Also, it would not hurt to read up on the BF2 Limitations
I see. that's unfortunate, but the thing you describe can pretty much accomplish what I'm gunning for, so long as the AI can spawn at said model once it lands. This wouldn't happen to make the map incompatible with online play, would it?
Marth8880 wrote:There's a way to do it, but it requires some complicated-ish scripting. The core elements of it are OnEnterRegion() and EntityFlyerLand() (or EntityFlyerInitAsLanded(), forgot which).
Oh that's cool. Do you have a link for where that's talked about by chance? I've done mod work for Swbf1 so I'm somewhat familiar with LUA.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How to Get AI to Land in Hangars?

Post by Marth8880 »

Ascertes wrote:Oh that's cool. Do you have a link for where that's talked about by chance? I've done mod work for Swbf1 so I'm somewhat familiar with LUA.
I don't think it's ever been talked about publicly. The only reason why I know it's possible is because I know Mav did it in one of his maps, and Firefang (as part of Frayed Wires Mod Team back when we were called that lol) reverse-engineered it years ago. We should have the code floating around somewhere, I'll go ahead and see if I can dig it up.

EDIT:

Ah-ha! Found it...

Code: Select all

ActivateRegion("landregion")
Land = OnEnterRegion(
	function(region, character)
		if GetEntityClass(GetCharacterVehicle(character)) == FindEntityClass("att_fly_vwing") then
				print("flyer found :D")
			ship = GetCharacterVehicle(character)
			EntityFlyerLand(ship)
				print("Houston, the Eagle has landed")
		end
		if not IsCharacerHuman(character) then
			ExitVehicle(ship)
		end
	end,
	"landregion"
)
I haven't personally tested it, but it should work. Go nuts. :P
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Does this become it's own LUA script? or where do I put it in _Diet Dr. Pepper/_cmn?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How to Get AI to Land in Hangars?

Post by Marth8880 »

You'd put it in ScriptPostLoad(), most likely at the end.
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Marth8880 wrote:You'd put it in ScriptPostLoad(), most likely at the end.
Alright, thanks :)

One final question, would adding this make my map incompatible with multiplayer?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How to Get AI to Land in Hangars?

Post by Marth8880 »

Ascertes wrote:One final question, would adding this make my map incompatible with multiplayer?
To be honest, it'd probably work fine, I see no reason why it wouldn't - of course you'd have to try it out for yourself and see.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How to Get AI to Land in Hangars?

Post by AnthonyBF2 »

Thanks for the code Marth! I assume there still has to be flyer paths that go in the hangar, correct?
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Marth8880 wrote:
Ascertes wrote:One final question, would adding this make my map incompatible with multiplayer?
To be honest, it'd probably work fine, I see no reason why it wouldn't - of course you'd have to try it out for yourself and see.
Thanks very much, I'm just concerned because my map is currently crashing in multiplayer and I have no idea why. I haven't done anything that's game-breaking, but whenever I add it to the map list, it starts to load, and when it finishes the game freezes; it doesn't even crash. I have to open Task Manager and close bf2 that way. For the life of me I can't figure out what's wrong... :faint:
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: How to Get AI to Land in Hangars?

Post by Maveritchell »

Samee3 wrote:The short answer is: it's not possible.
However, there is a space mission in The Dark Times mod (can't remember which) where there are "flyers" that take off from a friendly hanger and land in an opposing hanger. The problem with this method is that they are not actual AI, but simply a model scripted to travel from point A to point B along a predefined path.

Also, it would not hurt to read up on the BF2 Limitations
Late to the conversation, but there's no "flyers" about it. Those are regular vehicles. I have a special AI case set up (similar to Marth's description above) that tells the shuttles specifically to fly to enemy hangars and force-land once there. I've never been coy about this - I've described the method several times, which is just to use flyer splines to move a vehicle and then Lua code to force it to land.

And it works fine in multiplayer.
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Awesome! You wouldn't happen to have a link for where you've explained this in the past, would you? Don't want to make you have to repost it :)

EDIT: Nvm, it seems a tutorial is located in the shipped Mod Tools, who knew? XD

Also found a similar tut in the FAQ thread



EDIT2: I followed the instructions, but apparently the LandOnArrival property for the node I want to the AI to attempt the land at isn't working. Is this normal, or do I have to do something else? The node is well within a Landing Region, and it isn't at the last node in the path (the .txt told me not to put it at the last node.)



EDIT3
Okay, I've copied the script Marth posted into my LUA at the very end, and it looks like this:

Code: Select all

ScriptPostLoad()
ActivateRegion("rep-cp1con") --"rep-cp1con" is the name of my landing region.
Land = OnEnterRegion(
   function(region, character)
      if GetEntityClass(GetCharacterVehicle(character)) == FindEntityClass("cis_fly_droidgunship") then
            print("flyer found :D")
         ship = GetCharacterVehicle(character)
         EntityFlyerLand(ship)
            print("Houston, the Eagle has landed")
      end
      if not IsCharacerHuman(character) then
         ExitVehicle(ship)
      end
   end,
   "rep-cp1con" --Again, name of my landing region.
)
The AI still will not land. I'm assuming I have to edit other values in this script area, but I'm not sure which ones?

I feel like I'm very close! :)


EDIT4: Swapped out "cis_fly_droidgunship" for it's path follower class, "transport", still nothing...
thelegend
Sith
Sith
Posts: 1433
Joined: Thu Jan 23, 2014 6:01 am
Projects :: Star Wars - Battlefront III Legacy
Games I'm Playing :: Swbf GTA CoD LoL KH
xbox live or psn: El_Fabricio#
Location: Right behind you :)

Re: How to Get AI to Land in Hangars?

Post by thelegend »

Do not forget to enable flyer paths inside your lua:

EnableFlyerPath("your path name right after entitypath",1)
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

thelegend wrote:Do not forget to enable flyer paths inside your lua:

EnableFlyerPath("your path name right after entitypath",1)
Flyer path is enabled. The Gunship will follow the spline as it is supposed to but doesn't seem to register the script I loaded into the LUA or the LandOnArrival property I assigned to the nodes along the spline :\
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How to Get AI to Land in Hangars?

Post by Marth8880 »

When you created your region "rep-cp1con", did you make sure to also set the region's class properties to "rep-cp1con" like so?

Image
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars?

Post by Ascertes »

Marth8880 wrote:When you created your region "rep-cp1con", did you make sure to also set the region's class properties to "rep-cp1con" like so?

Image
It looks exactly like that, yeah.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: How to Get AI to Land in Hangars?

Post by Maveritchell »

To really test your issue, you're going to have to break it down into pieces and see where your script is failing. Make comments at various pieces and see what comments show up in your log and which ones don't.

For what it's worth, your ExitVehicle command won't work when you get to that (it needs to reference the player entity and not the vehicle), but your bigger issue right away is not seeing your vehicle in the region.
Ascertes
Private Second Class
Posts: 65
Joined: Thu Aug 18, 2016 3:42 pm
Projects :: Space Carida
xbox live or psn: No gamertag set

Re: How to Get AI to Land in Hangars? [Solved]

Post by Ascertes »

Maveritchell wrote:To really test your issue, you're going to have to break it down into pieces and see where your script is failing. Make comments at various pieces and see what comments show up in your log and which ones don't.

For what it's worth, your ExitVehicle command won't work when you get to that (it needs to reference the player entity and not the vehicle), but your bigger issue right away is not seeing your vehicle in the region.
I think I understand what you're saying, but perhaps you could show what the code is supposed to look like?

As far as the log is concerned, I'm not getting any issues regarding my LUA, whether it be in the munge log or the BF2Log. As a matter of fact, both look exactly same with or without or the new code.

EDIT: Hm, now I'm getting an error that reads:

Code: Select all

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\EntityPath.cpp(895)
EnableFlyerPath() couldn't find a path with that name
(none):0: attempt to call global `ScriptPostLoad' (a nil value)
EDIT
Sorry if this is grave bumping...BUT I GOT IT TO WORK!

Here's the copy of my LUA code in ABC_Diet Dr. Pepper:

Code: Select all

function ScriptPostLoad()
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)
            print("Houston, the Eagle has landed")
      end
      if not IsCharacerHuman(character) then
         ExitVehicle(character)
      end
   end,
   "rep-cp1con"
)
end
What a breakthrough!

EDIT
One final question though if anybody knows:

Say the vehicle is like a droid gunship, with a lot of seats for people. How would I make it so the code expels all of the AI in the ship? Because otherwise right now just the pilot and maybe 1-2 other AI are getting out, but the rest stay and the ship takes off then crashes :|
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How to Get AI to Land in Hangars? [Solved]

Post by AnthonyBF2 »

Ascertes wrote:One final question though if anybody knows:

Say the vehicle is like a droid gunship, with a lot of seats for people. How would I make it so the code expels all of the AI in the ship? Because otherwise right now just the pilot and maybe 1-2 other AI are getting out, but the rest stay and the ship takes off then crashes :|
I think you need the function ForceAIOutOfVehicles() but I am not sure how to use it completely.
Post Reply