"Choose Your Own" Galactic Conquest - scripting help [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

Post Reply
JediJack
Posts: 3
Joined: Sat Feb 06, 2021 7:07 pm
Projects :: No Mod project currently.
Games I'm Playing :: SWBF2
xbox live or psn: No gamertag set

"Choose Your Own" Galactic Conquest - scripting help [Solved]

Post by JediJack »

Last night, whilst working on my 'Absolute Battlefront' galactic conquest mod, my brain had the insane idea of creating a galactic conquest where you (the player) can CHOOSE what maps and planets you want to include. The idea could be massive, cover as many of the popular mod maps as possible, say like 50 planets and 150 maps, and then whichever maps you have in your addon at the time would be loaded into the galactic conquest.

Sounds cool, right? I thought so at least.

I thought the most complicated part would be making the paths between the planets, as I won't be able to tell what other planets the player would use. I came up with 2 solutions for that:
1: Have a series of stars running through the map, with all the planets connected to at least one of them, that way everything would be connected.
2: Use some of the game's standard planets as hubs instead of stars, though still allow people to switch them out with custom maps if they wish (for example have Pandemic's Coruscant, or one of the many Coruscant mod maps out there, or any mixture of the above).
In either case, each planet would also connect to one, two or three other planets, and if the player happened to also use that planet, a connection would be made to create a more interesting layout. I'd tell players there was a limit of say 20-25 planets at any one time to avoid hitting the (apparently) hardcoded 50 pathway limit.

I'd hoped it would simply require a bunch of IF statements in the lua code, and by a bunch I mean a very very large number, but nothing unreasonable as it would mostly be a lot of copy and pasting on my part. Here's an example for that including Dantooine might look like, where Dantooine would replace star09 (in reality I'd give Dantooine its own coordinates on the map, this is just because I was writing a quick example):

Code: Select all

this.cameraOffset = {
if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 then
["DAN"] = { 0, 1, 1 }, 	
end
}

if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 then
-- Make the Dantooine planet appear
CreateEntity(GetEntityClass("tat"), GetEntityMatrix("star09"), "DAN");
end
And so on throughout the rest of the freefrom_init and in the freeform_start files.

Unfortunately when I went to munge it to run a test, I was repeatedly getting this error message:
C:\BF2_ModTools\data_C14\_BUILD\Shell\..\..\..\ToolsFL\Bin\luac.exe: ..\..\shell\scripts\ifs_freeform_init_xxx.lua:26: unexpected symbol near `if'
ERROR[scriptmunge scripts\ifs_freeform_init_xxx.lua]:Could not read input file.ERROR[scriptmunge scripts\ifs_freeform_init_xxx.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings
I experimented with a few things, and while the 'if' code is happy to work for making the planet appear, it doesn't work anywhere else. It would appear that lua doesn't like using 'if' functions within a table, and the gc code is all about tables. Basically anywhere an if would appear within a { and a }, it would fail. It makes sense I guess, as otherwise the table doesn't know how long it's supposed to be.

One solution would be to have the if statements on the outside of the table, and within each option of the ifs, have different tables, like so:
(I've just used Coruscant - COR - and Geonosis - GEO - as examples here. If you were to really do this, the "NOT"s would need to be lower case, they're just upper case here for emphasis)

Code: Select all

if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1
and if ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1
then
this.cameraOffset = {
		["DAN"] = { 0, 1, 1 },
		["COR"] = { 0, 1, 1 },
		["GEO"] = { 0, 1, 1 }
	}
else 
if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["DAN"] = { 0, 1, 1 },
		["COR"] = { 0, 1, 1 },
	}
else 		
if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["DAN"] = { 0, 1, 1 },
		["GEO"] = { 0, 1, 1 },
	}
else 		
if NOT ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["COR"] = { 0, 1, 1 },
		["GEO"] = { 0, 1, 1 },
	}
else 	
if ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["DAN"] = { 0, 1, 1 },
	}
else 	
if NOT ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["COR"] = { 0, 1, 1 },
	}
else 	
if NOT ScriptCB_IsFileExist("..\\..\\addon\\DAN\\addme.lvl") == 1 
and if NOT ScriptCB_IsFileExist("..\\..\\addon\\COR\\addme.lvl") == 1	
and if ScriptCB_IsFileExist("..\\..\\addon\\GEO\\addme.lvl") == 1	
then 
this.cameraOffset = {
		["GEO"] = { 0, 1, 1 },
	}
end
end
end
end
end
end
end
As you can see, even with just 3 planets, it's 7 nested if statements. And it would grow exponentially larger the more planets you had:
planets = nested ifs
4=15
5=31
6=63
10 = 1023
And that's just for the one table, that would need to be repeated for all 5 tables needed for the GC scripts. And the work would double for the 'this.planetMission table every time you wanted to add another map option to a planet. You get the idea, doing it that way simply isn't practical. I suspect the game would crash long before you got to anything good.

I have no idea if this idea is even possible, but I really want it to be. The only reasonable way of it working is having the changing factors within the tables, and the way the code is written at the moment, I don't believe that it's possible. You'd probably need to rewrite the entire code to change the way the function works. Or maybe there's an easier function that I don't know about? I'm not a coder, I don't know lua, except the small amount I need to know to write basic scripts for the game mods. If you are a coder, for all I know you're laughing at me right now because the solution is so obvious. I'm not the one to say either way.

That's why I thought I'd just share the idea here. If you've got any solutions then I'd love to hear them. Or if you want to go ahead and make it yourself, feel free, or include me in on it (though if you do make it yourself with or without me, please credit me for the initial idea).
Last edited by JediJack on Sat May 15, 2021 10:48 am, edited 1 time in total.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: "Choose Your Own" Galactic Conquest - scripting help

Post by Anakin »

This is a awesome idea. Keep working on this :thumbs:

First you should take a look at remastered https://www.moddb.com/mods/star-wars-ba ... -interface it can help you to add the gc in a very easy way.

Next you should take a look at gc custom. There are already configurations such as faction, start money, costs, victory,... before the gc starts.

About the multiple maps/mods for one planet you could randomly choose one of a bunch of missions for one planet. I did this for my republic commando mod, too. Here is a example for Bespin

Code: Select all

this.planetMission['bes'] = { ["con"] = { "BCCr_con", "BPFr_con" }}
Not sure if this is already your intention, but i'd generate a predefined grid with stars and make the connections. Then you can change stars to planets depending on how many missions where choosed.

So the camera offset table can always look like this: no matter if the planet will be playable or not (rhen var and bespin are optional)

Code: Select all

this.cameraOffset = {
		["cor"] = { 0, 1, 1 },
		["dag"] = { 0, 1, 1 },
		["fel"] = { 0, 1, 1 },
		["geo"] = { 0, 1, 1 },
		["hot"] = { 0, 1, 1 },
		["kas"] = { 0, 1, 1 },
		["kam"] = { 0, 1, 1 },
		["mus"] = { 0, 1, 1 },
		["myg"] = { 0, 1, 1 },
		["nab"] = { 0, 1, 1 },
		["pol"] = { 0, 1, 1 },
		["tat"] = { 0, 1, 1 },
		["uta"] = { 0, 1, 1 },
		["yav"] = { 0, 1, 1 },
		["bes"] = { 0, 1, 1 },
		["rhn"] = { 0, 1, 1 },
	}
Setting up the coords for the new planets and remove unused stuff. Be aware that there is a limit in size of maximum planets/connections/entities. Not sure what they actually are. But i ran into this problem.

Code: Select all

		DeleteEntity("end")
		DeleteEntity("end_system")
		DeleteEntity("kam_star")
		DeleteEntity("geo_star")
		DeleteEntity("hot_star")
		DeleteEntity("tantive")
		DeleteEntity("star11")
		DeleteEntity("star14")
		
		-- Bespin
		CreateEntity(GetEntityClass("tat"), GetEntityMatrix("star01"), "bes");
		CreateEntity(GetEntityClass("tat_system"), GetEntityMatrix("star01_system"), "bes_system");
		CreateEntity(GetEntityClass("tat_camera"), GetEntityMatrix("star01_camera"), "bes_camera");
		CreateEntity(GetEntityClass("tat_fleet1"), GetEntityMatrix("star01_fleet1"), "bes_fleet1");
		CreateEntity(GetEntityClass("tat_fleet2"), GetEntityMatrix("star01_fleet2"), "bes_fleet2");
		
		--Rhen Var
		CreateEntity(GetEntityClass("hot"), GetEntityMatrix("star16"), "rhn");
		CreateEntity(GetEntityClass("hot_system"), GetEntityMatrix("star16_system"), "rhn_system");
		CreateEntity(GetEntityClass("hot_camera"), GetEntityMatrix("star16_camera"), "rhn_camera");
		CreateEntity(GetEntityClass("hot_fleet1"), GetEntityMatrix("star16_fleet1"), "rhn_fleet1");
		CreateEntity(GetEntityClass("hot_fleet2"), GetEntityMatrix("star16_fleet2"), "rhn_fleet2");
		
		DeleteEntity("star01")
		DeleteEntity("star16")
Setting up the planet values needs to be done variable. You can see here how to insert entries depending on the existence of a file.

Code: Select all

		this.planetValue = {
			["cor"] = { victory = 60, defeat = 20, turn = 3 },
			["dag"] = { victory = 50, defeat = 20, turn = 3 },
			["fel"] = { victory = 50, defeat = 20, turn = 3 },
			["geo"] = { victory = 100, defeat = 35, turn = 10 },
			["hot"] = { victory = 60, defeat = 20, turn = 3 },
			["kas"] = { victory = 50, defeat = 20, turn = 3 },
			["kam"] = { victory = 100, defeat = 35, turn = 10 },
			["mus"] = { victory = 60, defeat = 20, turn = 3 },
			["myg"] = { victory = 50, defeat = 20, turn = 3 },
			["nab"] = { victory = 60, defeat = 20, turn = 3 },
			["pol"] = { victory = 50, defeat = 20, turn = 3 },
			["tat"] = { victory = 50, defeat = 20, turn = 3 },
			["uta"] = { victory = 60, defeat = 20, turn = 3 },
			["yav"] = { victory = 50, defeat = 20, turn = 3 },
		}
		
		if ScriptCB_IsFileExist("..\\..\\addon\\BCC\\addme.script") == 1 or ScriptCB_IsFileExist("..\\..\\addon\\BPF\\addme.script") == 1 then
			this.planetValue["bes"] = { victory = 60, defeat = 20, turn = 3 }
		end
		
		if ScriptCB_IsFileExist("..\\..\\addon\\RVC\\addme.script") == 1 and ScriptCB_IsFileExist("..\\..\\addon\\RVH\\addme.script") == 1 then
			this.planetValue["rhn"] = { victory = 50, defeat = 20, turn = 3 }
		end
finally you can edit or add new missions like this:

Code: Select all

		if ScriptCB_IsFileExist("..\\..\\addon\\GNS\\addme.script") == 1 then
			print("    GNS detected - adding to gc..")
			this.planetMission['geo'] = { ["con"] = { "geo1r_con", "GNSr_con" } }
		else
			print("    GNS not found - skipping..")
		end

I hope those code examples can help you ;) If you have any questions, feel free to contact me on discord, too. i'm a way more active there
JediJack
Posts: 3
Joined: Sat Feb 06, 2021 7:07 pm
Projects :: No Mod project currently.
Games I'm Playing :: SWBF2
xbox live or psn: No gamertag set

Re: "Choose Your Own" Galactic Conquest - scripting help

Post by JediJack »

Hi Anakin, thank you for this. I'm familiar with most of it (I've been working on my GC series for the last year now) but that last point, reframing the planetMission table into that format, is a brilliant idea and looks promising. I'll give it a try now.
Post Reply