Page 1 of 2

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

Posted: Thu Aug 18, 2016 4:03 pm
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. :)

Re: How to Get AI to Land in Hangars?

Posted: Thu Aug 18, 2016 5:48 pm
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

Re: How to Get AI to Land in Hangars?

Posted: Thu Aug 18, 2016 10:14 pm
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).

Re: How to Get AI to Land in Hangars?

Posted: Thu Aug 18, 2016 11:31 pm
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.

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 19, 2016 1:38 am
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

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 19, 2016 1:24 pm
by Ascertes
Does this become it's own LUA script? or where do I put it in _Diet Dr. Pepper/_cmn?

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 19, 2016 2:58 pm
by Marth8880
You'd put it in ScriptPostLoad(), most likely at the end.

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 19, 2016 4:25 pm
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?

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 20, 2016 1:09 am
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.

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 20, 2016 1:44 am
by AnthonyBF2
Thanks for the code Marth! I assume there still has to be flyer paths that go in the hangar, correct?

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 20, 2016 2:42 am
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:

Re: How to Get AI to Land in Hangars?

Posted: Thu Aug 25, 2016 1:07 pm
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.

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 26, 2016 3:28 pm
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...

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 26, 2016 4:19 pm
by thelegend
Do not forget to enable flyer paths inside your lua:

EnableFlyerPath("your path name right after entitypath",1)

Re: How to Get AI to Land in Hangars?

Posted: Fri Aug 26, 2016 4:39 pm
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 :\

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 27, 2016 2:34 am
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

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 27, 2016 3:03 am
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.

Re: How to Get AI to Land in Hangars?

Posted: Sat Aug 27, 2016 1:09 pm
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.

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

Posted: Sat Nov 05, 2016 2:43 pm
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 :|

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

Posted: Sat Nov 05, 2016 3:12 pm
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.