[Tutorial] Gunship Drop-Off and Leave [CODE]

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

Post Reply
GAMEDOGSHIPMENT
Recruit Womprat Killer
Posts: 13
Joined: Sat Jun 24, 2017 12:27 am
Projects :: No Mod project currently.
Games I'm Playing :: SWBF2
xbox live or psn: No gamertag set

[Tutorial] Gunship Drop-Off and Leave [CODE]

Post by GAMEDOGSHIPMENT »

Alo, after looking at some of the flyer tutorials none seem to cover variations or play around with new stuff. Great tutorial by Ascertes shows how to make ai land in hangars. But lets expand upon this find. In this tutorial, I will combine the use of timers and show how to make flyers land anywhere and then take off just like in the movies when they are dropping off troops.

First things first is to follow the hanger tutorial by Ascertes up to the lua section. This can be done on ground maps and you do need need to be in a space map.
As quoted...
Ascertes wrote: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. Make sure the Region Property is the same as the region name. So if you named your region Land1, the property must also be Land1. 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(or _com/ctf).
After following these steps in you Lua file add line (code below) before the function ScriptPostLoad() like so...

Code: Select all

ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")
EnableFlyerPath("gunship2",1) --RIGHT HERE instead of gunship2 write the name of the path
	
	--  REP Attacking (attacker is always #1)
    REP = 1;
    CIS = 2;
    --  These variables do not change
    ATT = REP;
    DEF = CIS;


function ScriptPostLoad()
Then at the end of your function ScriptPostLoad() place this code, some lines have comments describing what they do.
Hidden/Spoiler:
[code]ActivateRegion("land") --name of region you created for landing here
Land = OnEnterRegion( --When you enter region command...
function(region, character) --We use 2 entities a region and character, regions are for regions, and character is for ai and player
ship = GetCharacterVehicle(character) -- This line assigns ship with the given command

if GetEntityClass(ship) == FindEntityClass("rep_fly_gunship_sc_test_2") then --change name to your ships name
EntityFlyerLand(ship)
end

if not IsCharacterHuman(character) then --Checks if the character is player or ai
--ExitVehicle(character) --This makes everyone jump out so if you tried to enable this the ship will most likely explode when trying to take off
end

CreateTimer("timerhere")
SetTimerValue("timerhere", (6)) --in seconds
StartTimer("timerhere")

OnTimerElapse(
function(timer)
DeactivateRegion("land") --deactivates the land region so when going up the ship wont land again
EntityFlyerTakeOff(ship)
DestroyTimer(timer)
end,
"timerhere"
)
CreateTimer("timerhere2")
SetTimerValue("timerhere2", (12)) --in seconds
StartTimer("timerhere2")

OnTimerElapse(
function(timer)
ActivateRegion("land") --reactivate the region
DestroyTimer(timer)
end,
"timerhere2"
)
end,
"land"
)[/code]
In the end your ScriptPostLoad() should look similar to below...
Hidden/Spoiler:
[code]function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}



--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)

conquest:Start()

EnableSPHeroRules()
SetUberMode(1)

ActivateRegion("land") --name of region here
Land = OnEnterRegion(
function(region, character)
ship = GetCharacterVehicle(character)

if GetEntityClass(ship) == FindEntityClass("rep_fly_gunship_sc_test_2") then --change name to your ships name
EntityFlyerLand(ship)
end

if not IsCharacterHuman(character) then
--ExitVehicle(character) --This makes everyone jump out so if you tried to enable this the ship will most likely explode when trying to take off
end

CreateTimer("timerhere")
SetTimerValue("timerhere", (6)) --in seconds
StartTimer("timerhere")

OnTimerElapse(
function(timer)
DeactivateRegion("land")
EntityFlyerTakeOff(ship)
DestroyTimer(timer)
end,
"timerhere"
)
CreateTimer("timerhere2")
SetTimerValue("timerhere2", (12)) --in seconds
StartTimer("timerhere2")

OnTimerElapse(
function(timer)
ActivateRegion("land")
DestroyTimer(timer)
end,
"timerhere2"
)
end,
"land"
)

end[/code]
Thats all enjoy your flyers landing and taking off have fun.

Future Plans:

Currently, I have a finished video sitting here waiting for upload until I get back from vacation that goes over this and a few extra code varitiations so stick around till that comes out (0.0)_b

Resource and Credits:


Discussion Threads About Gunships:

1) = http://www.gametoast.com/viewtopic.php? ... al#p410478
2) = http://www.gametoast.com/viewtopic.php? ... al#p365279

Ai Hangar Land Tutorial:

Tutorial: viewtopic.php?f=27&t=32640
Discussion: http://www.gametoast.com/viewtopic.php? ... al#p526550

Timer Tutorial:

Tutorial: http://www.gametoast.com/viewtopic.php?f=27&t=21511

Credits:
1. Maveritchell
2. Marth8880
3. thelegend
4. AnthonyBF2
5. AQT
6. Ascertes
7. YaNkFaN (Timer)
Post Reply