How do I use the math.random function for sides?

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
666rulerofclones
Command Sergeant Major
Command Sergeant Major
Posts: 281
Joined: Fri Aug 08, 2008 1:30 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: The Badger State!

How do I use the math.random function for sides?

Post by 666rulerofclones »

Hey, I'm making a mod and I have more clone legions than I do maps. I was wondering how I would use the math.random function to load them correctly. I know about setting up the sides and all, but I was wondering about using it to use different units. What I mean is this:
Hidden/Spoiler:
ReadDataFile("dc:SIDE\\rep.lvl",
"rep_inf_ep2_rifleman",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_engineer",
"rep_inf_ep2_sniper",
"rep_inf_ep2_jettrooper",
"rep_inf_ep2_officer",
"rep_inf_ep2_pilot",
"rep_inf_ep2_marine")
----"rep_bldg_defensegridturret")
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_rocketeer",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_droideka",
"cis_inf_officer",
"cis_inf_pilot",
"cis_inf_marine",
"cis_hero_jangofett")
----"cis_bldg_defensegridturret")
ReadDataFile("dc:SIDE\\heroes.lvl",
"rep_hero_ep2_obiwan")
ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_chaingun_roof",
"tur_weap_built_gunturret")

SetAttackingTeam(ATT)
SetupTeams{
rep = {
team = REP,
units = 32,
reinforcements = 250,
soldier = { "rep_inf_ep2_rifleman",9, 25},
assault = { "rep_inf_ep2_rocketeer",1, 4},
engineer = { "rep_inf_ep2_engineer", 1, 4},
sniper = { "rep_inf_ep2_sniper",1, 4},
officer = { "rep_inf_ep2_officer",0, 1}, --I have different names for different officer units and special units for each of
special = { "rep_inf_ep2_jettrooper",1,2}, -- my legions. What I want to know is how to make it load a random legion
medic = { "rep_inf_ep2_pilot",1,4}, -- with it's legion-specific units.
elite = { "rep_inf_ep2_marine",1,4},

},
cis = {
team = CIS,
units = 32,
reinforcements = 250,
soldier = { "cis_inf_rocketeer",9, 25},
assault = { "cis_inf_rifleman",1, 4},
engineer = { "cis_inf_engineer", 1, 4},
sniper = { "cis_inf_sniper",1, 4},
officer = { "cis_inf_officer",0, 1},
special = { "cis_inf_droideka",1,2},
medic = { "cis_inf_pilot",1,4},
elite = { "cis_inf_marine",1,4},

},

}

SetHeroClass(REP, "rep_hero_ep2_obiwan")
SetHeroClass(CIS, "cis_hero_jangofett")
Thanks!
Aman/Pinguin
Jedi
Jedi
Posts: 1104
Joined: Tue Jan 30, 2007 6:04 am
Projects :: Inactive
Location: Germany

Re: How do I use the math.random function for sides?

Post by Aman/Pinguin »

Would be helpful to know what names you gave your legions.
Here just an example how it could work:



Guessing you are naming your units like this: rep_inf_ep1_jettrooper, rep_inf_ep2_jettrooper, rep_inf_ep3_jettrooper, rep_inf_ep4_jettrooper, rep_inf_ep5_jettrooper

Hidden/Spoiler:
randyrandom = math.random(1,NUMBEROFLEGIONSHERE)

ReadDataFile("dc:SIDE\\rep.lvl",
"rep_inf_ep2_rifleman",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_engineer",
"rep_inf_ep2_sniper",
"rep_inf_ep" .. randyrandom .. "_jettrooper",
"rep_inf_ep" .. randyrandom .. "_officer",
"rep_inf_ep2_pilot",
"rep_inf_ep2_marine")

ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_rocketeer",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_droideka",
"cis_inf_officer",
"cis_inf_pilot",
"cis_inf_marine",
"cis_hero_jangofett")

ReadDataFile("dc:SIDE\\heroes.lvl",
"rep_hero_ep2_obiwan")

ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_chaingun_roof",
"tur_weap_built_gunturret")

SetAttackingTeam(ATT)



SetupTeams{
rep = {
team = REP,
units = 32,
reinforcements = 250,
soldier = { "rep_inf_ep2_rifleman",9, 25},
assault = { "rep_inf_ep2_rocketeer",1, 4},
engineer = { "rep_inf_ep2_engineer", 1, 4},
sniper = { "rep_inf_ep2_sniper",1, 4},
officer = { "rep_inf_ep" .. randyrandom .. "_officer",0, 1},
special = { "rep_inf_ep" .. randyrandom .. "_jettrooper",1,2},
medic = { "rep_inf_ep2_pilot",1,4},
elite = { "rep_inf_ep2_marine",1,4},

},
cis = {
team = CIS,
units = 32,
reinforcements = 250,
soldier = { "cis_inf_rocketeer",9, 25},
assault = { "cis_inf_rifleman",1, 4},
engineer = { "cis_inf_engineer", 1, 4},
sniper = { "cis_inf_sniper",1, 4},
officer = { "cis_inf_officer",0, 1},
special = { "cis_inf_droideka",1,2},
medic = { "cis_inf_pilot",1,4},
elite = { "cis_inf_marine",1,4},

},

}

SetHeroClass(REP, "rep_hero_ep2_obiwan")
SetHeroClass(CIS, "cis_hero_jangofett")
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: How do I use the math.random function for sides?

Post by Teancum »

Hmm, slick code. Dunno if that works, but if it does that's pretty efficient.
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: How do I use the math.random function for sides?

Post by [RDH]Zerted »

Don't forget, doing it that way will cause client crashes in MP (there are a few ways to not cause the crash, but they are more complex). As such in the addme.lua, you shouldn't add that mission to the MP map table.
User avatar
666rulerofclones
Command Sergeant Major
Command Sergeant Major
Posts: 281
Joined: Fri Aug 08, 2008 1:30 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: The Badger State!

Re: How do I use the math.random function for sides?

Post by 666rulerofclones »

Aman/Pinguin wrote:Would be helpful to know what names you gave your legions.
Legion names: rep, rep212th, rep327th, rep41st, repshock, repmarine, rep91st, rep78th.

Commander names: rep_hero_appo, rep_hero_cody, rep_hero_bly, rep_hero_gree, rep_hero_thire, rep_hero_barcara, rep_hero_neyo, rep_hero_vace.

Special Unit Names: rep_inf_ep2_rocketeer_chaingun, rep_inf_ep2_jettrooper, rep_inf_ep3_elite, rep_inf_guard, rep_inf_assassin, rep_inf_captain, rep_inf_ep3_barc, rep_inf_ep3_recon, rep_inf_ep3_jettrooper.

That's it. :)
Aman/Pinguin
Jedi
Jedi
Posts: 1104
Joined: Tue Jan 30, 2007 6:04 am
Projects :: Inactive
Location: Germany

Re: How do I use the math.random function for sides?

Post by Aman/Pinguin »

666rulerofclones wrote:
Aman/Pinguin wrote:Would be helpful to know what names you gave your legions.
Legion names: rep, rep212th, rep327th, rep41st, repshock, repmarine, rep91st, rep78th.

Commander names: rep_hero_appo, rep_hero_cody, rep_hero_bly, rep_hero_gree, rep_hero_thire, rep_hero_barcara, rep_hero_neyo, rep_hero_vace.

Special Unit Names: rep_inf_ep2_rocketeer_chaingun, rep_inf_ep2_jettrooper, rep_inf_ep3_elite, rep_inf_guard, rep_inf_assassin, rep_inf_captain, rep_inf_ep3_barc, rep_inf_ep3_recon, rep_inf_ep3_jettrooper.

That's it. :)
You might think up the code yourself, learning by doing. ;)

[RDH]Zerted wrote:Don't forget, doing it that way will cause client crashes in MP (there are a few ways to not cause the crash, but they are more complex). As such in the addme.lua, you shouldn't add that mission to the MP map table.
I think you know my lua-knowledge is very limited. :)
Post Reply