Page 1 of 1

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

Posted: Thu Sep 24, 2009 10:57 pm
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!

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

Posted: Fri Sep 25, 2009 6:01 am
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")

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

Posted: Fri Sep 25, 2009 9:11 am
by Teancum
Hmm, slick code. Dunno if that works, but if it does that's pretty efficient.

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

Posted: Fri Sep 25, 2009 9:50 am
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.

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

Posted: Fri Sep 25, 2009 10:41 am
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. :)

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

Posted: Fri Sep 25, 2009 1:28 pm
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. :)