if ScriptCB_IsFileExist not working for 1 folder map pack.

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
User avatar
Jendo7
Sith
Sith
Posts: 1304
Joined: Wed Apr 01, 2009 6:37 pm
Location: Cambridge, England.
Contact:

if ScriptCB_IsFileExist not working for 1 folder map pack.

Post by Jendo7 »

I'm adding all my maps to run from one three letter folder, and because my maps have support for both DTII, and BFX, I'm trying to get the code IsFileExist working, so that people without these mods won't see the extra era's on the selection screen. I've got it working for individual maps, but can't get it working for a map pack, as only the new era's show up for one map, and not the others. If I don't use the code if ScriptCB_IsFileExist all the era's work fine. Below is my addme script:
Hidden/Spoiler:
[code]--Search through the missionlist to find a map that matches mapName,
--then insert the new flags into said entry.
--Use this when you know the map already exists, but this content patch is just
--adding new gamemodes (otherwise you should just add whole new entries to the missionlist)
function AddNewGameModes(missionList, mapName, newFlags)
for i, mission in missionList do
if mission.mapluafile == mapName then
for flag, value in pairs(newFlags) do
mission[flag] = value
end
end
end
end




--insert totally new maps here:
local sp_n = 0
local mp_n = 0

sp_n = table.getn(sp_missionselect_listbox_contents)
sp_missionselect_listbox_contents[sp_n+1] = { isModLevel = 1, mapluafile = "BNE%s_%s", era_g = 1, era_c = 1, mode_con_g = 1, mode_con_c = 1, mode_ctf_g = 1, mode_ctf_c = 1, mode_eli_g = 1, mode_hunt_g = 1, mode_xl_g = 1, mode_xl_c = 1,}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

AddNewGameModes( sp_missionselect_listbox_contents, "end1%s_%s", {era_c = 1, mode_con_c = 1,} )

sp_n = table.getn(sp_missionselect_listbox_contents)
sp_missionselect_listbox_contents[sp_n+1] = { isModLevel = 1, mapluafile = "HTI%s_%s", era_g = 1, era_c = 1, mode_con_g = 1, mode_hunt_g = 1, mode_con_c = 1,}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

sp_n = table.getn(sp_missionselect_listbox_contents)
sp_missionselect_listbox_contents[sp_n+1] = { isModLevel = 1, mapluafile = "TDS%s_%s", era_g = 1, era_c = 1, mode_con_g = 1, mode_con_c = 1, mode_ctf_g = 1, mode_ctf_c = 1, mode_eli_g = 1, mode_hunt_g = 1,}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

-- associate this mission name with the current downloadable content directory
-- (this tells the engine which maps are downloaded, so you need to include all new mission lua's here)
-- first arg: mapluafile from above
-- second arg: mission script name
-- third arg: level memory modifier. the arg to LuaScript.cpp: DEFAULT_MODEL_MEMORY_PLUS(x)

AddDownloadableContent("BNE","BNEg_con",4)
AddDownloadableContent("BNE","BNEc_con",4)
AddDownloadableContent("BNE","BNEg_ctf",4)
AddDownloadableContent("BNE","BNEc_ctf",4)
AddDownloadableContent("BNE","BNEg_eli",4)
AddDownloadableContent("BNE","BNEg_hunt",4)
AddDownloadableContent("BNE","BNEg_xl",4)
AddDownloadableContent("BNE","BNEc_xl",4)
AddDownloadableContent("end1","end1c_con",4)
AddDownloadableContent("TDS","TDSg_hunt",4)
AddDownloadableContent("HTI","HTIg_con",4)
AddDownloadableContent("HTI","HTIg_hunt",4)
AddDownloadableContent("HTI","HTIc_con",4)
AddDownloadableContent("TDS","TDSg_con",4)
AddDownloadableContent("TDS","TDSc_con",4)
AddDownloadableContent("TDS","TDSg_ctf",4)
AddDownloadableContent("TDS","TDSc_ctf",4)
AddDownloadableContent("TDS","TDSg_eli",4)


local bfxfile = "..\\..\\addon\\BFX\\data\\_LVL_PC\\mission.lvl"

if ScriptCB_IsFileExist(bfxfile) == 0 then
print("Cannot find "..bfxfile..". Skipping BFX's extra missions")
else
print("Found "..bfxfile..". Adding BFX's missions")

sp_missionselect_listbox_contents[sp_n+1].era_a = 1 --adds the a era checkbox
sp_missionselect_listbox_contents[sp_n+1].mode_con_a = 1 --adds the con mode checkbox
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

AddDownloadableContent("BNE","BNEa_con",4)
AddDownloadableContent("HTI","HTIa_con",4)
AddDownloadableContent("TDS","TDSa_con",4)

end

local dtfile = "..\\..\\addon\\BDT\\data\\_LVL_PC\\SIDE\\dark.lvl"

if ScriptCB_IsFileExist(dtfile) == 0 then
print("Cannot find "..dtfile..". Skipping DT's extra missions")
else
print("Found "..dtfile..". Adding DT's missions")

ReadDataFile("..\\..\\addon\\BDT\\data\\_LVL_PC\\dtshell.lvl")

sp_missionselect_listbox_contents[sp_n+1].era_1 = 1 --adds the 1 era checkbox
sp_missionselect_listbox_contents[sp_n+1].mode_con_1 = 1 --adds the con mode checkbox
sp_missionselect_listbox_contents[sp_n+1].mode_eli_1 = 1 --adds the eli mode checkbox
sp_missionselect_listbox_contents[sp_n+1].change = {
era_1 = { name="Dark Times", icon2="darktimes_icon" },
} --adds the icon?
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

AddDownloadableContent("BNE","BNE1_con",4)
AddDownloadableContent("BNE","BNE1_eli",4)
AddDownloadableContent("HTI","HTI1_con",4)
AddDownloadableContent("HTI","HTI1_eli",4)
AddDownloadableContent("TDS","TDS1_con",4)

end

-- all done
newEntry = nil
n = nil

-- Now load our core.lvl into the shell to add our localize keys
ReadDataFile("..\\..\\addon\\SWB\\data\\_LVL_PC\\core.lvl")[/code]
Any help would be appreciated.
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:

Re: if ScriptCB_IsFileExist not working for 1 folder map pac

Post by [RDH]Zerted »

You're only adding the new eras and game modes to map TDS. Is that what you're trying to do or did you want them added to the other two maps as well?

I think what you really want is to be using AddNewGameModes() inside of your IsFileExists() checks. Notice how the sp_n variable changes each time you added a new map: sp_n = table.getn(sp_missionselect_listbox_contents) That line says get the size of the list and the sp_n+1 code ends up meaning put this new map info at a new entry at the end of the list.

Inside your IsFileExists() checks, you don't change sp_n, so it only adds the eras once and only to the last map you added (TDS).

Also, change your AddNewGameModes() to the new version I've posted about a couple times. It matters that more people use it. It keeps map list from becoming unstable. We're not going to want to deal with the user support nightmare of maps replacing parts of each other's entires. I'm too lazy/cold/hungry/busy to look up where that code is right now.
User avatar
Jendo7
Sith
Sith
Posts: 1304
Joined: Wed Apr 01, 2009 6:37 pm
Location: Cambridge, England.
Contact:

Re: if ScriptCB_IsFileExist not working for 1 folder map pac

Post by Jendo7 »

Thank you for getting back so quickly, I do appreciate it.

I did want to add the new eras and game modes for the other two maps as well, so I think you've given me enough info to go on. It will just take me time to figure it out. I'll do a search for your other posts on the subject, and get working on it. I'll let you know how I get on, and update this post.
Post Reply