SWBFGamers

Modding for the Original SWBF1 and SWBF2 => SWBF1 Modding => Topic started by: Dark_Phantom on December 16, 2019, 07:59:22 AM

Title: BF1 Randomizer
Post by: Dark_Phantom on December 16, 2019, 07:59:22 AM
It's time for me to show off my newest project:
https://www.twitch.tv/videos/520770317
https://youtube.com/v/M9aHzflIMTk?t=2474
https://youtube.com/v/M9aHzflIMTk?t=2474;allowFullScreen="true"
What this project does:

Future plans:

Comments and suggestions are appreciated.
Title: Re: BF1 Randomizer
Post by: wsa30h on December 16, 2019, 10:14:49 AM
cross era cant wait for the future when you do that one i will definitely use it.battlefront 1 needs more cross era.
quick question will it support cross era announcers like republic vs empire ?
Title: Re: BF1 Randomizer
Post by: Ty294 on December 16, 2019, 06:38:46 PM
Wow, that is really cool!

How did you manage to randomize the unit choices? I've been meaning to ask if there is a way to have a random unit selection (albeit a slightly more controlled one) in Battlefront 1, similar to the BF2 Dark Times mod (I think).
Title: Re: BF1 Randomizer
Post by: Led on December 16, 2019, 06:42:52 PM
https://www.swbfgamers.com/index.php?topic=4503.0
Title: Re: BF1 Randomizer
Post by: Dark_Phantom on December 17, 2019, 06:53:26 AM
Quote from: wsa30h on December 16, 2019, 10:14:49 AM
quick question will it support cross era announcers like republic vs empire ?
I prefer consistency in this department.  I'm probably going to write a function to randomize which sound set it will pick (r,i,c,a), but I want them all to sound like they are from the same team.  So yes, but not completely.
Quote from: Ty294 on December 16, 2019, 06:38:46 PM
How did you manage to randomize the unit choices? I've been meaning to ask if there is a way to have a random unit selection (albeit a slightly more controlled one) in Battlefront 1, similar to the BF2 Dark Times mod (I think).
Led hits it on the head, and there's a ton of relevant information in there about randomization.  The big points are that online is a pain (what I'm going to try to work out to transfer the seed from the server, we'll see how it goes), and that you just have to make sure that all the units you want randomized are loaded in.  This is actually how I do it:

*code abbreviated for readability*
Code (lua) Select

ReadDataFile("SIDE\\all.lvl","all_inf.....","all_inf_luke_skywalker");
--load all sides and subreqs, make sure you have CIS, REP, gam, etc.
classes = { "all_inf_soldier", "cis_inf_droideka", "all_inf_luke_skywalker","rep_inf_jet_trooper","gam_inf_gamorreanguard" } --all the classes you want loaded in to a table

for i=1,5 do --do this section 5 times
  k = random(1,getn(classes)) -- select a number between 1 and classes, this is flexible so you can just add more units, getn gets number of entries in table
AddUnitClass(1, classes[k],5) -- on team 1, use random class, 5 units declared
end


This is pretty simplified, but is the jist of the code I wrote to do it.  Actually, I moved all that stuff to its own function for readability - I plan to upload the source when I'm done but it's pretty rough right now.  I run the exact same type of randomizer on everything individually - bonuses, team names, etc.
Title: Re: BF1 Randomizer
Post by: wsa30h on December 17, 2019, 10:17:54 AM
sounds like your busy either way i cant wait for this mod.
Title: Re: BF1 Randomizer
Post by: Dark_Phantom on December 17, 2019, 11:32:59 AM
For no good reason the smaller video wouldn't export so I used the full video and linked to the relevant portion.  See OP for embedded video.
Title: Re: BF1 Randomizer
Post by: wsa30h on December 17, 2019, 12:55:32 PM
this work your doing is amazing do you have any idea on how i can munge the stock cw and gcw announcers i need to modify it so that i can get the clone anouncer in cross era vs empire, so far though have no luck on getting it to munge  :confused:
Title: Re: BF1 Randomizer
Post by: Ty294 on December 17, 2019, 05:39:51 PM
Quote from: Led on December 16, 2019, 06:42:52 PM
https://www.swbfgamers.com/index.php?topic=4503.0

Quote from: Dark_Phantasmagorical on December 17, 2019, 06:53:26 AM
I prefer consistency in this department.  I'm probably going to write a function to randomize which sound set it will pick (r,i,c,a), but I want them all to sound like they are from the same team.  So yes, but not completely.Led hits it on the head, and there's a ton of relevant information in there about randomization.  The big points are that online is a pain (what I'm going to try to work out to transfer the seed from the server, we'll see how it goes), and that you just have to make sure that all the units you want randomized are loaded in.  This is actually how I do it:

*code abbreviated for readability*
Code (lua) Select

ReadDataFile("SIDE\\all.lvl","all_inf.....","all_inf_luke_skywalker");
--load all sides and subreqs, make sure you have CIS, REP, gam, etc.
classes = { "all_inf_soldier", "cis_inf_droideka", "all_inf_luke_skywalker","rep_inf_jet_trooper","gam_inf_gamorreanguard" } --all the classes you want loaded in to a table

for i=1,5 do --do this section 5 times
  k = random(1,getn(classes)) -- select a number between 1 and classes, this is flexible so you can just add more units, getn gets number of entries in table
AddUnitClass(1, classes[k],5) -- on team 1, use random class, 5 units declared
end


This is pretty simplified, but is the jist of the code I wrote to do it.  Actually, I moved all that stuff to its own function for readability - I plan to upload the source when I'm done but it's pretty rough right now.  I run the exact same type of randomizer on everything individually - bonuses, team names, etc.

Oh, fascinating! Would it be possible to share a more full example of that lua, just so I can better see the structure?

Also, this would work for SP too right? Or is this MP specific?

Essentially my ultimate goal would be where I each time you spawn, your unit potentially has a different weapon loadout and or model (so you could pick say the Rebel trooper, and it might select randomly between you getting an E-11, A280 or DH-17, for example), but I'm not sure if that is possible in BF.

I dunno if ODFs can be randomized too? Or is just Lua?
Title: Re: BF1 Randomizer
Post by: Dark_Phantom on December 17, 2019, 10:50:25 PM
So, let me give a little bit of background:
This will work in SP or MP.  The main part of my mod is SP.  I wish I could really do more randomization, but I work with what I can.  As far as I know, without editing binary (which I'm still not confident BF1 can do), you can't edit the odfs on the fly.  The same would go for the models.  The method I am going to use to get around this is just make a ton of new units that get called in, even if they only have slight (or not so slight) variations.  That's really the next big step to this mod, after all the scripting is done/mostly done.

BF1 does not really have great event scripting - the only real access is through pause menu, and that's not really ideal for most mods (but you can overwrite stuff, like sky and textures, using the pause menu).  So basically everything needs decided before ScriptInit is done.  Odfs/worlds are pretty much static entities, so I'm working around that by creating more odfs/worlds.

In the spoiler I've put the lua file I am using.  I have this munged into my mission.lvl as ranFunc.lua, but it does NOT have to be in there.  If you want it for one map, you just copy and paste the code.  Putting in a function makes it so much easier in the long run.  You can see I hard-coded all the classes and load in every side and all the sub-lvls I have currently.  The game doesn't seem to care too much except I did get a memory error (non crashing) on one of the spawn select screens and FPMs are pretty much toast for some of the units because you can only have 64 in at a time.

[spoiler]ranFunc.lua
Code (lua) Select
function randomUnits()
    ReadDataFile("SIDE\\all.lvl",
        "all_inf_basicurban",
        "all_inf_lukeskywalker",
        "all_inf_smuggler",
        "all_fly_xwing",
        "all_fly_ywing",
        "all_fly_snowspeeder",
        "all_inf_basicsnow",
        "all_inf_lukeskywalkersnow",
        "all_inf_smugglersnow",
        "all_walk_tauntaun");
    ReadDataFile("SIDE\\imp.lvl",
        "imp_walk_atst_jungle",
        "imp_walk_atat",
        "imp_walk_atst_snow",
        "imp_droid_probe",
        "imp_inf_basicsnow",
        "imp_inf_dark_troopersnow",
        "imp_hover_speederbike",
        "imp_inf_basic_tie",
        "imp_inf_dark_trooper",
        "imp_inf_darthvader",
        "imp_fly_tiebomber",
        "imp_fly_tiefighter");
    ReadDataFile("SIDE\\rep.lvl",
        "rep_bldg_forwardcenter",
        "rep_fly_assault_dome",
        "rep_fly_gunship",
        "rep_fly_jedifighter",
        "rep_fly_gunship_dome",
        "rep_fly_jedifighter_dome",
        "rep_inf_basic",
        "rep_inf_jet_trooper",
        "rep_inf_macewindu",
        "rep_walk_atte")
    ReadDataFile("SIDE\\cis.lvl",
        "cis_fly_droidfighter_dome",
        "cis_fly_fedcoreship_dome",
        "cis_fly_geofighter",
        "cis_fly_techounion_dome",
        "cis_inf_basic",
        "cis_fly_maf",
        "cis_fly_droidfighter",
        "cis_inf_countdooku",
        "cis_inf_droideka",
        "cis_tread_hailfire",
        "cis_walk_spider",
        "cis_hover_aat",
        "cis_hover_stap")
    ReadDataFile("SIDE\\ewk.lvl",
        "ewk_inf_basic");
    --ScriptCB_SetDCMap("tat3")
    ReadDataFile("SIDE\\gam.lvl",
        "gam_inf_gamorreanguard");
    ReadDataFile("SIDE\\geo.lvl",
        "gen_inf_geonosian");
    ReadDataFile("SIDE\\wok.lvl",
        "wok_inf_basic");
    ReadDataFile("SIDE\\gun.lvl",
        "gun_inf_basic");
    ReadDataFile("SIDE\\gar.lvl",
        "gar_inf_basic");
    ReadDataFile("SIDE\\des.lvl",
        "tat_inf_tuskenhunter",
        "tat_inf_tuskenraider");
    ReadDataFile("SIDE\\des.lvl",
        "tat_inf_jawa");
       
    classes = {
        "all_inf_soldierurban",
        "all_inf_vanguard",
        "all_inf_pilot",
        "all_inf_marksman",
        "all_inf_smuggler",
        "imp_inf_storm_trooper",
        "imp_inf_shock_trooper",
        "imp_inf_pilottie",
        "imp_inf_scout_trooper",
        "imp_inf_dark_trooper",
        "rep_inf_clone_trooper",
        "rep_inf_arc_trooper",
        "rep_inf_clone_pilot",
        "rep_inf_clone_sharpshooter",
        "rep_inf_jet_trooper",
        "cis_inf_battledroid",
        "cis_inf_assault",
        "cis_inf_pilotdroid",
        "cis_inf_assassindroid",
        "cis_inf_droideka",
        "geo_inf_geonosian",
        "wok_inf_mechanic",
        "wok_inf_rocketeer",
        "wok_inf_warrior",
        "gun_inf_rider",
        "gun_inf_soldier",
        "gun_inf_defender",
        "gar_inf_soldier",
        "gar_inf_pilot",
        "gar_inf_vanguard",
        "tat_inf_tuskenraider",
        "tat_inf_tuskenhunter",
        "tat_inf_jawa",
        "ewk_inf_trooper",
        "ewk_inf_repair",
        "gam_inf_gamorreanguard"
        }
    --37 = "gam_inf_gamorreanguard", --moved to stock

    for i=1,5 do
        k = random(1,getn(classes))
        AddUnitClass(1, classes[k],5)
        if i==1 then
            writeto("test.txt")
            write("TEAM 1\n".. classes[k] .. "\n")
        else
            write(classes[k] .. "\n")
        end
    end   
   
    for i=1,5 do
        k = random(1,getn(classes))
        AddUnitClass(2, classes[k],5)
        if i==1 then
            write("TEAM 2\n".. classes[k] .. "\n")
        else
            write(classes[k] .. "\n")
        end
    end

    SetHeroClass(1, "all_inf_lukeskywalker")
    SetHeroClass(2, "imp_inf_darthvader")
   
    --closefile("test.txt")
end

Then you cut out some of the redundant stuff in the mission, and just put randomUnits() in your script[/spoiler]
EDIT: this code has a chance of crashing if you don't move gam.lvl to the SIDE folder. 
Title: Re: BF1 Randomizer
Post by: Ty294 on December 18, 2019, 08:50:05 PM
Ah, I see! I put it into the LUA of one of my test maps and made it work. This is definitely something I will consider in future maps. Too bad we can't make it work in ODFs, but oh well.

Thanks for sharing this! I didn't think even this much was possible in BF1, so it's definitely a revelation to me!
Title: Re: BF1 Randomizer
Post by: Dark_Phantom on December 23, 2019, 06:41:36 AM
https://youtu.be/_NF_Wx5bszA
Platforms randomizer test
Title: Re: BF1 Randomizer
Post by: Giftheck on December 24, 2019, 11:23:02 AM
I have to say, this is bloody awesome!

I wonder if this can be used in a more 'linear' fashion. IE, making it load a specific class dependant on the option (maybe something like "Select Special Class: Brute/Aerial/Commando" to the Instant Action menu?) to 'bypass' the unit selection restriction. If you get what I'm saying. It made sense in my head :P
EhPortal 1.34 © 2024, WebDev