Page 1 of 2

Random units

Posted: Sat Jun 12, 2010 4:08 pm
by skelltor
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.

Re: random units

Posted: Sat Jun 12, 2010 5:28 pm
by myers73
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.

Re: Random units

Posted: Tue Jun 15, 2010 4:14 pm
by skelltor
ok thx

edit i am a bit confused as to how to do it help please?

Re: Random units

Posted: Wed Jun 16, 2010 1:08 am
by fasty
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

Re: Random units

Posted: Tue Jul 06, 2010 2:23 pm
by skelltor
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?

Re: Random units

Posted: Tue Jul 06, 2010 9:27 pm
by lucasfart
just add

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
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.

Re: Random units

Posted: Wed Jul 07, 2010 6:02 pm
by skelltor
ok so i have to make many commbonations of the units as i want? or is there a way to make it smaller?

Re: Random units

Posted: Wed Jul 07, 2010 6:14 pm
by myers73
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.

Re: Random units

Posted: Wed Jul 07, 2010 6:21 pm
by skelltor
ok thx both of you :D 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?

Re: Random units

Posted: Wed Jul 07, 2010 10:48 pm
by myers73
it would add less that a kb per map

Re: Random units

Posted: Thu Jul 08, 2010 1:47 am
by lucasfart
skelltor wrote: edit2 when you say sidename/number its just one of those right?
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)

Re: Random units

Posted: Thu Jul 08, 2010 9:06 am
by skelltor
ok thx guys i will try it out soon :D

Re: Random units

Posted: Thu Jul 08, 2010 9:53 am
by Teancum
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

Re: Random units

Posted: Thu Jul 08, 2010 10:02 am
by skelltor
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?

Re: Random units

Posted: Thu Jul 08, 2010 11:10 am
by DarthD.U.C.K.
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

Re: Random units

Posted: Thu Jul 08, 2010 12:17 pm
by skelltor
ok thx

Re: Random units

Posted: Thu Jul 08, 2010 1:42 pm
by myers73
they dont have to, but it would be more organized.

Re: Random units

Posted: Sun Jul 18, 2010 7:43 pm
by skelltor
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?

Re: Random units

Posted: Sun Jul 18, 2010 9:19 pm
by Teancum
Can't help without seeing your lua.

Re: Random units

Posted: Mon Jul 19, 2010 1:45 am
by sim-al2
The Great Munge Log wrote:}' expected (to close `{' at line 132) near `AddUnitClass'
That means you need to look for a missing bracket where you added your units in.