Custom Galactic Conquest troubles [UNSOLVED]

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
MileHighGuy
Jedi
Jedi
Posts: 1145
Joined: Fri Dec 19, 2008 7:58 pm

Custom Galactic Conquest troubles [UNSOLVED]

Post by MileHighGuy »

Hi guys,

So I can get a basic custom galactic conquest going fine, if I only override the scripts:

custom_gc_11.lua
ifs_freeform_init_cw.lua
ifs_freeform_start_cw.lua

The game goes to a black screen if I use my own ifs_freeform_main.lua. Pointing to the stock one is fine.

I eventually want to override all the GC scripts.
I didn't really edit any of them beyond pointing to the new ones except in custom_gc_11.lua script.

Here is my custom_gc_11.lua
Hidden/Spoiler:
[code]--This is the main setup script for a custom Galactic Conquest
print("custom_gc_11: Entered")

-------------------------------------------------------------------------------
-- Those 7 steps are in this section
-------------------------------------------------------------------------------
--Modders, for basic custom Galactic Conquest support
-- you only need to change the variables in this section.
-- If you want to do advanced things, you will need to
-- learn how the real game does it.
-- If you need to change something else in the game, it is
-- best to 'take control' of the function as done
-- a few times below this section. This allows you to
-- change parts of the shell without replacing shell.lvl.

--To use this script in your own custom Galactic Conquest,
-- 1) you need to search/replace: cgc11/cgc#
-- 2) you need to search/replace: gc_11/cg_#
-- where '#' is the number of this custom Galactic Conquest

-- 3) this button tag must be unique for each button in the Galactic Conquest screen
local gcTag = "Test"

-- 4) this is the string your Galactic Conquest button will use
-- if the game cannot find the a localization version of the string,
-- it will directly display the text on the button
local gcString = "Galactic Conquest Test" --"mods.custom_gc.tht.name"

-- 5) load any other scripts from your custom_gc_11.lvl

ScriptCB_DoFile("ifs_freeform_init_cw_2")
ScriptCB_DoFile("ifs_freeform_start_cw_2")

-- ScriptCB_DoFile("ifs_freeform_main_2") ---- causes problems <----------------



-- 6) this is your script that starts your Galactic Conquest game
--local start_gc = ifs_freeform_start_zer
local start_gc = ifs_freeform_start_cw_2

-- 7) read in any strings you need
--ReadDataFile("..\\..\\addon\\XXX\\core.lvl")

-------------------------------------------------------------------------------
-- The end of the 7 step section
-------------------------------------------------------------------------------

--add a button to the shell for our custom Galactic Conquest
if custom_GetGCButtonList then
print("custom_gc_11: Taking control of custom_GetGCButtonList()...")

--check for possible loading errors
if cgc11_custom_GetGCButtonList then
print("custom_gc_11: Warning: Someone else is using our cgc11_custom_GetGCButtonList variable!")
print("custom_gc_11: Exited")
return
end

--backup the current custom_GetGCButtonList function
cgc11_custom_GetGCButtonList = custom_GetGCButtonList

--this is our new custom_GetGCButtonList function
custom_GetGCButtonList = function()
print("custom_gc_11: custom_GetGCButtonList(): Entered")

--get the button table from the real function
local list = cgc11_custom_GetGCButtonList()

--add in the button for our Galactic Conqust
local ourButton = { tag = gcTag, string = gcString, }
table.insert( list, 1, ourButton )

print("custom_gc_11: custom_GetGCButtonList(): Exited")
return list
end
else
print("custom_gc_11: Warning: No custom_GetGCButtonList() to take over")
print("custom_gc_11: Exited")
return
end

--Note: if you want your Galactic Conquest to only be visible at certain times (like when some other GC is completed), you will need to take over the ifs_sp_campaign_fnUpdateButtonVis() and/or ifs_sp_gc_fnUpdateButtonVis() functions (like you did with custom_GetGCButtonList()). Both of these functions can be found in Common\scripts\PC\ifs_sp_campaign.lua

--listen for when our Galactic Conquest button is clicked
if custom_PressedGCButton then
print("custom_gc_11: Taking control of custom_PressedGCButton()...")

--check for possible loading errors
if cgc11_custom_PressedGCButton then
print("custom_gc_11: Warning: Someone else is using our cgc11_custom_PressedGCButton variable!")
print("custom_gc_11: Exited")
return
end

--backup the current custom_GetGCButtonList function
cgc11_custom_PressedGCButton = custom_PressedGCButton

--this is our new custom_GetGCButtonList function
custom_PressedGCButton = function( tag )
print("custom_gc_11: custom_PressedGCButton(): Entered")

--not our conquest, so let the game process it normally
if tag ~= gcTag then
return cgc11_custom_PressedGCButton()
end

--it is our Galactic Conquest button, so get our game going
start_gc(ifs_freeform_main)

print("custom_gc_11: custom_PressedGCButton(): Exited")
return true
end
else
print("custom_gc_11: Warning: No custom_PressedGCButton() to take over")
print("custom_gc_11: Exited")
return
end

print("custom_gc_11: Exited")[/code]
but when I try to do this in custom_gc_11.lua

Code: Select all

ScriptCB_DoFile("ifs_freeform_main_2")
(which is the unedited script, just the one that I own)

along with

Code: Select all

local start_gc = ifs_freeform_start_cw_2

Code: Select all

start_gc(ifs_freeform_main_2)
The screen turns black when I start my custom GC and I get this in the debug log:

Code: Select all

Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to index field `teamCode' (a nil value)
stack traceback:
	(none): in function `OneTimeInit'
	(none): in function <(none):1118>
It seems no matter what I do in that file it does not change the error. The only time teamCode is referenced in ifs_freefrom_main:OneTimeInit is here

Code: Select all

-- load sides
			ifs_purchase_load_data(this.teamCode[1], this.teamCode[2])
I am thinking maybe the order of ScriptCB_DoFile in the custom_gc_11.lua could be off, if that matters? Any ideas?
Has anyone been able to successfully override this script?
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4779
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Custom Galactic Conquest troubles [UNSOLVED]

Post by Anakin »

i run into this error "nil OneTimeInit" multiple times.
First i recommend to throw away this old garbage gc script ;)
You can use the new Remaster interface script, that does exactly the same, but with this code instead:

Code: Select all

-- STAR WARS BATTLEFRONT II - REMASTER
-- Developer Documentation by Anakin

-- load all scripts needed for your custom gc match here
ScriptCB_DoFile("ifs_freeform_init_cgc")
ScriptCB_DoFile("ifs_freeform_start_cgc")

-- some variables needed by the register function
local gcButtonTag = "cgcButton"				-- the button tag needs to be unique
local gcButtonString = "CGC Tutorial"		-- the name can be localized or hardcoded
local start_gc = ifs_freeform_start_cgc		-- This is the function that starts the gc match.

-- register the button
swbf2Remaster_registerCGCButton(gcButtonTag, gcButtonString, start_gc )
If you install Remaster, check the Developer Documentation, it's explained there, how to use it.

i may find the time to look into detail by the end of next day, when i did all my exams. remind me on discord, i'm not so active on GT anymore
MileHighGuy
Jedi
Jedi
Posts: 1145
Joined: Fri Dec 19, 2008 7:58 pm

Re: Custom Galactic Conquest troubles [UNSOLVED]

Post by MileHighGuy »

So with Anakin's help I was able to override the ifs_freeform_main function

essentially all you have to do is re-assign the function in ifs_freeform_main before it is called by the start script (you can do the same thing with any other table too)

so if you are using the version 1.3 way of setting up a galactic conquest you can do this in the custom_gc_11.lua, or if you are using battlefront remastered you could put it in the RTS_interface_script (where RTS is your project name).

Code: Select all

ifs_freeform_main.OneTimeInit = function(this, showLoadDisplay)
--do code here
--can add print() statements for debugging
end
you can do it like this because ifs_freeform_main is a table. each of its entries are a function. so If you override a function it will look at that new one.

you should take more care though to make sure that it is only overridden when you actually press start, so maybe it would be better to override it in the beginning of the
ifs_freeform_start_cw_2 function

So you could put all the code concerned with overriding in a new .lua file and then call ScriptCB_DoFile("override_main_filename") where you want to override it

I'm also not sure if this will cover it when you load a saved game

not to mention how to set it back to normal if you quit the galactic conquest game and play a different galactic conquest. i suppose you could store the original like so

Code: Select all

original_ifs_freeform_main = ifs_freeform_main
--do override here

--when you want to set it back somewhere
ifs_freeform_main = original_ifs_freeform_main
I will keep this thread open for other questions i might have
Post Reply