Objective LUA Scripting

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
PvtParts
Jedi
Jedi
Posts: 1001
Joined: Mon Apr 03, 2006 9:12 pm
Projects :: No Mod project currently.
xbox live or psn: No gamertag set
Location: plundering yer booty

Objective LUA Scripting

Post by PvtParts »

Alright, so for the maps I'm making, every one, I want to include both a Conquest, and a Campaign mode.

Aside from reading up on lua, and comparing the games campaign luas to how they play out ingame, I haven't really much experience in this sort of scripting.

So, I figured I would throw up a thread, and with each objective, post my lua, or at least pertaining exerpts, and hopefully experienced lua-ers could walk me through it, and show me, along with the rest of the gametoast community, how its done.

Now, this may seem like an excuse to justify wanting specific help to this degree, but I think if people throw in and this thread keeps going, we could end up with a major, and I mean major, resource for any modder who wishes to try scripting their own campaign mode.

Now, for my first goal, I want the player to enter a given vehicle (in this case being an AAT), and firing at an enemy shield, one that will not break.

So basically, you'll enter a vehicle that is not available to other AI, shoot at a shield, and then after a certain amount of time, the objective ends and you are told to move down the hill and capture the farthest left of 3 cps.

Now, for the first goal, I'm totally lost. But for the second..heres what I've got:


Code: Select all

 --Objective 2
 	Objective2CP = CommandPost:New{name = "c_cp12"}
	Objective2 = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF, text = "level.nac.objectives.campaign.2", popupText = "level.nac.objectives.campaign.2_popup",  AIGoalWeight = 0}
	Objective2:AddCommandPost(Objective2CP)
	
	Objective2.OnStart = function(self)
		AllowAISpawn(REP, true)
		att_obj2_aigoal = AddAIGoal(ATT, "Deathmatch", 50)
		def_obj2_aigoal = AddAIGoal(DEF, "Deathmatch", 50)
		def_obj2_aigoal2 = AddAIGoal(DEF, "Defend", 50, "c_cp12")
		--BatchChangeTeams(5, ATT, 11)
		--SetUnitCount(1, 12)
		AddUnitClass(1, "drd_battledroid_td", 10)
		AddUnitClass(1, "drd_battledroid_cmd_td", 10)
		AddUnitClass(1, "drd_battledroid_pilot_td", 10)
		AddUnitClass(1, "drd_droideka_td", 10)
	end
		
	Objective2.OnComplete = function(self)
		ShowMessageText("game.objectives.complete", ATT)
		DeleteAIGoal(att_obj2_aigoal)
		DeleteAIGoal(def_obj2_aigoal)
		DeleteAIGoal(def_obj2_aigoal2)
		AICanCaptureCP("c_cp12", DEF, false)
		SetProperty("c_cp12", "Team", 1)
	end

Now, please take note that I'm totally new at this. The cp I want captured is c_cp12. The CIS is on the REP (ATT) team, and the Gungans are on CIS (DEF) team. I want the CIS's goals to be deathmatch, and I want the gungans to deathmatch, and defend. I want the gungans to be able to spawn all units, and I want the same for the CIS. Im not sure how to set up the AddUnitClass stuff, so please take a look at that.

Anyhow, I hope this doesn't fall through, and we can actually get a resource goin,

Parts
archer01

Post by archer01 »

That looks like it should accomplish what you're going for, a normal single-player conquest goal with only one CP. I'm not sure why you have the "SetProperty("c_cp12", "Team", 1)" bit since that CP has to be captured by team 1 to complete the objective in the first place, but it shouldn't cause any problems.

The AddUnitClass should also work fine. Assuming of course you want the units on team 1 (ie team ATT). Their names suggest droids, so I'm guessing you're playing as the CIS in your mission. Beware of one thing though... I've found that if you add units to the list after the match starts, the selection boxes do not resize. What this means is that, if you go over seven (7) selectable unit types for a single team 'after' the match starts, the selection boxes will run off the end of the screen.


For your first objective, I would strongly suggest you work from the geonosis campaign script (the training mission). There is a LOT of stuff done in that mission that is never done anywhere else in the game. I've found that script the most useful of any of them so far.

Another thing to keep in mind: Eventually you will have to use the "MultiObjectiveContainer" to link your objectives together. Keep in mind that the developers of the game only designed that script for singleplayer use, and only for players being on team 1 (team ATT). While it will still run, the container script will not work as expected in a normal multiplayer setup (not without some editing anyway).


Good luck with your continued scripting!
PvtParts
Jedi
Jedi
Posts: 1001
Joined: Mon Apr 03, 2006 9:12 pm
Projects :: No Mod project currently.
xbox live or psn: No gamertag set
Location: plundering yer booty

Post by PvtParts »

I have c_cp12 to team 1 because I dont want it to be recapturable to the other team.

Also, I want all those units to be available to the player at the start of the game. So how would I do that?

And for my first objective, I considered using the space kashyyk lua, because they have an objective involving getting in a vehicle. Where I'm most lost is how to set it so that you can fire a certain amount (or have it timed) and then it automatically moves to your next objective.

Anyhow, thanks for the help so far. Probably through this coming week, or possibly not until the weekend (schoool arg) I will get some more code up.

Thanks again,

Parts
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Post by [RDH]Zerted »

Not looking it up, I think [objective].Complete = 1 will end an objective.

Checkout the ObjectiveGoto code and see what it does when a unit enters the target regions.

Objective2.Complete = 1
archer01

Post by archer01 »

When captured the CP's team property is changed. If you want to stop a CP from being capturable, set it's "CaptureRegion" property to something that doesn't exist (like "NoRegionForYou"). It will generate a level 3 message in the error log, but it doesn't cause any problems (that I've seen anyway). This is how the developers sometimes stopped recaptures (check the campaign missions if you want proof).

To make the units available at the start, just put the AddUnitClass code right after the team setup code. Doing it this way will also avoid the selection box resize problem.

For the shield objective, just use the ObjectiveAssault object and set a time limit. The ObjectiveAssault script inherits from the Objective script (just like everything else) so setting a time limit on the objective (using the "timeLimit" argument) should work just fine. Since the target isn't destroyable, just make the player's team the winner for the "timeLimitWiningTeam" argument.
PvtParts
Jedi
Jedi
Posts: 1001
Joined: Mon Apr 03, 2006 9:12 pm
Projects :: No Mod project currently.
xbox live or psn: No gamertag set
Location: plundering yer booty

Post by PvtParts »

Oh sorry I haven't responded. I never got an email so I didnt check this thread.

I have been reaallllyyyyyy busy with the school, so I haven't gotten much scripting done. I do have a question, that I ask more out of laziness than for the fact that I'm unsure whether its possible.

How would I go about scripting an objective where the player simply must kill the enemies, and once the enemies reinfocements reach a certain number, they fall back to a command post. An alternative, and equally probable option, would be to have the enemy become friends with the players team. I know this is possible.

Just to explain why im trying to do this, I'm trying to recreate the battle of naboo. Now, the gungans retreaded in the movie. But, a large portion of them were detained, and the effect of a 'surrender' could be achieved by setting both teams to friends.


Thanks again, this is really a big help to me. And next time I have an unbusy day or weekend, I'll be sure to do my part in this by working on the code.

Parts
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Post by [RDH]Zerted »

Every time a character from the team dies, check the reinforcment count.

To make the AI 'fallback' you can set the AI goal to "Follow" and set the goal target to the CP (or something else) you want them to move to.

Setting teams as enemies or friends is easy. SetTeamAsEnemy([team number], [team number]) and SetTeamAsFriend(). Note, the releation ships are one way. SetTeamAsFirend(1,2) is not the same as SetTeamAsFriend(2,1).
PvtParts
Jedi
Jedi
Posts: 1001
Joined: Mon Apr 03, 2006 9:12 pm
Projects :: No Mod project currently.
xbox live or psn: No gamertag set
Location: plundering yer booty

Post by PvtParts »

Thanks Zerted. I dont have time right now, but tomorrow is sunday and I can try some of this stuff then.
Post Reply