Random units

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

User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Random units

Post 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.
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 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: Atlanta, GA xfire=myers73 IngameName=mYers

Re: random units

Post 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.
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post by skelltor »

ok thx

edit i am a bit confused as to how to do it help please?
fasty
1st Lieutenant
1st Lieutenant
Posts: 438
Joined: Thu Apr 15, 2010 4:17 am
Projects :: Server modding
Games I'm Playing :: SWBF2
Contact:

Re: Random units

Post 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
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post 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?
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Random units

Post 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.
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post 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?
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 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: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Random units

Post 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.
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post 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?
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 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: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Random units

Post by myers73 »

it would add less that a kb per map
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Random units

Post 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)
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post by skelltor »

ok thx guys i will try it out soon :D
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: Random units

Post 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
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post 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?
User avatar
DarthD.U.C.K.
Master of the Force
Master of the Force
Posts: 6027
Joined: Wed Sep 27, 2006 11:05 am
Location: Duckburg, Germany

Re: Random units

Post 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
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post by skelltor »

ok thx
myers73
Lieutenant General
Lieutenant General
Posts: 690
Joined: Fri Apr 03, 2009 11:04 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: Atlanta, GA xfire=myers73 IngameName=mYers

Re: Random units

Post by myers73 »

they dont have to, but it would be more organized.
User avatar
skelltor
Sith
Sith
Posts: 1431
Joined: Fri Dec 11, 2009 6:24 pm
Projects :: BFSM
Games I'm Playing :: SWBFII
xbox live or psn: skelltor95
Location: minisnowta
Contact:

Re: Random units

Post 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?
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: Random units

Post by Teancum »

Can't help without seeing your lua.
User avatar
sim-al2
2nd Lieutenant
2nd Lieutenant
Posts: 412
Joined: Mon Jul 06, 2009 10:26 pm
Projects :: Mapping on occasion
Games I'm Playing :: SWBFII + MW4 + SC4
Location: In the cockpit of some vehicle...

Re: Random units

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