Random units
Moderator: Moderators
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Random units
Ok so i was thinking about random units for bfsm so that every time a map loded it would pick the 4 normal units. But also randomly chose the 5 other units from a selection of units for each point catorgory. Is this possible and if so how would i do it? I looked at the random legion script but am not sure how to adapt it to fit my purposes.
-
myers73
- Lieutenant General

- Posts: 690
- Joined: Fri Apr 03, 2009 11:04 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Atlanta, GA xfire=myers73 IngameName=mYers
Re: random units
you would always have to load them in your sidename.lvl. then use the random script and AddUnitClass. give it a shot, should not be too hard to figure out.
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok thx
edit i am a bit confused as to how to do it help please?
edit i am a bit confused as to how to do it help please?
-
fasty
- 1st Lieutenant

- Posts: 438
- Joined: Thu Apr 15, 2010 4:17 am
- Projects :: Server modding
- Contact:
Re: Random units
I'm not sure if this is what you want or anything but, take a look at this:
http://www.gametoast.com/forums/viewtop ... 64&t=10843
http://www.gametoast.com/forums/viewtop ... 64&t=10843
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
yes i have that i am just not sure how to modifiy it so it lodes random units instead of legions i mean if all it does are combonations of units i would have to have every combonation of units entered and that would be vary large.btw does anyone know if there are any other random unit scripts? what script was used in ubfcw?or is there a example of what mav uses in bfdt?
- lucasfart
- Sith

- Posts: 1440
- Joined: Tue Feb 24, 2009 5:32 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Australia
Re: Random units
just add
You should note that all your units will have to be called in the .lvl file lower down, and you should only have units in the 4 slots that you want already called.
That should work, i just wrote it off the top of my head. Its a fairly easy thing to write and you should get the hang of it straight away.
Code: Select all
random = math.random(1, #) --replace hash with the number of variations you want
function random()
if random == 1
then AddUnitClass(#, "Unit_Name_here")-- # = Side number/name
AddUnitClass(#, "Unit_Name_here")-- # = Side number/name
AddUnitClass(#, "Unit_Name_here")-- # = Side number/name
AddUnitClass(#, "Unit_Name_here")-- # = Side number/name
AddUnitClass(#, "Unit_Name_here")-- # = Side number/name
elseif random == 2
--repeat the first example however many times you want.
end
That should work, i just wrote it off the top of my head. Its a fairly easy thing to write and you should get the hang of it straight away.
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok so i have to make many commbonations of the units as i want? or is there a way to make it smaller?
-
myers73
- Lieutenant General

- Posts: 690
- Joined: Fri Apr 03, 2009 11:04 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Atlanta, GA xfire=myers73 IngameName=mYers
Re: Random units
there really isnt a way to make it smaller as you will have to have AddUnitClass for each unit for each condition, so if you only want two conditions, and 4 troopers for each, then it will be at least about 12 lines, if you want 5 conditions for each team, then you will be up closer to 60-75 lines in total. Dont get scared by that though, most of it is copy+paste and renaming.
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok thx both of you
btw if i do it to all of the stock maps how much more memory would it use up?
edit i also need to load all the unit i would want to use upahead right?
edit2 when you say sidename/number its just one of those right?
edit i also need to load all the unit i would want to use upahead right?
edit2 when you say sidename/number its just one of those right?
-
myers73
- Lieutenant General

- Posts: 690
- Joined: Fri Apr 03, 2009 11:04 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Atlanta, GA xfire=myers73 IngameName=mYers
Re: Random units
it would add less that a kb per map
- lucasfart
- Sith

- Posts: 1440
- Joined: Tue Feb 24, 2009 5:32 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Australia
Re: Random units
It's either gonna be 1/REP or 2/CIS. number or word, it doesn't matter. Obviously if you made a third side you would use the number of that side (eg. locals)skelltor wrote: edit2 when you say sidename/number its just one of those right?
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok thx guys i will try it out soon 
- Teancum
- Jedi Admin

- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Random units
Here's the idea, but know this is Visual Basic pseudocode and not actual LUA (admittedly I don't know LUA very well). It just gives you the gist of what you're looking at:
Code: Select all
ScriptPostLoad()
ReadDataFile("DC:mycoolstuff.lvl")
"blablabla")
'Random() will return between 0 and 1, so we need to multiply it by the number of units we want
Dim randomNumber = Random() * 5
If randomNumber <= 1
AddUnitClass("first choice")
ElseIf randomNumber = 2
AddUnitClass("second choice")
ElseIf randomNumber = 3
AddUnitClass("third choice")
ElseIf randomNumber = 4
AddUnitClass("fourth choice")
ElseIf randomNumber = 5
AddUnitClass("fifth choice")
'Now catch any exceptions, just in case
Else
AddUnitClass("backup choice")
EndIf- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok thx tean my ? with that script is how do i get the units to lode vin the order i want them to? just copy and paste it in the order i want it to or what? and where does it go in my lua?
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: Random units
the order depends on the "class" of the unit, i think
(soldier, then assault, engineer, sniper, officer, special and pilot) the order of the extraunits should be determinated by the order you added them in the lua
the code must be added in the addteamssection into the teamname ={} brackets, the cide for additionalunits should go after or between the two setteam-sections, just where you would have put them without the randomization
(soldier, then assault, engineer, sniper, officer, special and pilot) the order of the extraunits should be determinated by the order you added them in the lua
the code must be added in the addteamssection into the teamname ={} brackets, the cide for additionalunits should go after or between the two setteam-sections, just where you would have put them without the randomization
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
ok thx
-
myers73
- Lieutenant General

- Posts: 690
- Joined: Fri Apr 03, 2009 11:04 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Atlanta, GA xfire=myers73 IngameName=mYers
Re: Random units
they dont have to, but it would be more organized.
- skelltor
- Sith

- Posts: 1431
- Joined: Fri Dec 11, 2009 6:24 pm
- Projects :: BFSM
- xbox live or psn: skelltor95
- Location: minisnowta
- Contact:
Re: Random units
i have played around with it but cant get it right i always get this error C:\BF2_ModTools\data_MAP\_BUILD\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\MAP\RNFr_con.lua:161: `}' expected (to close `{' at line 132) near `AddUnitClass'
ERROR[scriptmunge scripts\MAP\RNFr_con.lua]:Could not read input file.ERROR[scriptmunge scripts\MAP\RNFr_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings
can somone plese post an example lua for me?
ERROR[scriptmunge scripts\MAP\RNFr_con.lua]:Could not read input file.ERROR[scriptmunge scripts\MAP\RNFr_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings
can somone plese post an example lua for me?
- Teancum
- Jedi Admin

- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Random units
Can't help without seeing your lua.
- sim-al2
- 2nd Lieutenant

- Posts: 412
- Joined: Mon Jul 06, 2009 10:26 pm
- Projects :: Mapping on occasion
- Location: In the cockpit of some vehicle...
Re: Random units
That means you need to look for a missing bracket where you added your units in.The Great Munge Log wrote:}' expected (to close `{' at line 132) near `AddUnitClass'
