Random Sides Script (Release)

Releasing the source files for your mod or map? Post em' here. (Applies to both SWBF1 & SWBF2)

Moderator: Moderators

Post Reply
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Random Sides Script (Release)

Post by Ace_Azzameen_5 »

I got sick of playing as the 501st when bug-testing my WIP map and I came up with this lil' script to randomly load either the 501st or 1 of 4 clone legions sitting in my DATA folder from the Conversion Pack.

Its not only useful for those making a map that will use the Conversion Pack Assets, I think with the readme and the comments as a guide it should be relatively easy to rig the script to work with just about anything - even different side mods.

Unfortunately, after a couple days' failed attempts at using LUA PCall, (protected call) the game will crash if it randomly selects a side whose .lvl side is missing.

README:
Hidden/Spoiler:
This script will randomly select 1 of 4 Republic Legion Sides for the map it is implemented
in. It currently uses 4 of the legions in the SWBF1 Conversion Pack v 1.9.

Implementation:
Place RandomRepLegion.lua into your "*:\BF2_ModTools\data_***\Common\scripts\***" folder.
Then open "*:\BF2_ModTools\data_***\Common\mission.req" and add "RandomRepLegion" under
REQN
{
"script" .
Then open the LUA Script for every game mode you want this implemented in, and paste
ScriptCB_DoFile("RandomRepLegion")
at the top of the file.

Next Scroll down to under "function ScriptInit()" and replace the
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_rocketeer_chaingun",
"rep_fly_gunship_sc",
"rep_hero_anakin",
"rep_hover_barcspeeder",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")

with a call to the new function; RandomLegion()

IMPORTANT: To load your desired non-infantry units or vehicles from the rep side,
you must edit RandomRepLegion.lua. Inside you will notice a smaller ReadDataFile("SIDE\\rep.lvl",
block that loads a hero and the BARC speeder. ADD/Remove what you desire here.

Credits: Ace Azzameen 5 and Teancum, for the COnPack and it's Republic Sides (not distributed in this package)
And of course, Pandemic, for the SWBF2 ZE v1.1 which this script runs on, and LA and George Lucas for Star wars.

--////More serious modification and Credits////--
I don't mind anyone using modified versions of this script.
You don't have to credit me or this script for just showing you that math random exists, but if you use
this script, even if heavily modified, please credit me with a 'for basis of the random sides script' or inspiration etc.
etc etc.

Note: If you want to use this script in a case where the choice of Random Sides' correspondng units don't have all the same
name, move a few copies of the setup_teams info under each team's ReadDataFile in RandomRepLegion.

Good Luck, Have fun, and Keep Creating!

Ace

(I got my name when I registered my copy of XWA at LA forums :P)

RandomRepLegion.lua
Hidden/Spoiler:
[code]--
-- Random Sides Script for Star Wars Battlefront II Copyright (c) 2007 A.A.5. Productionzorz, All rights reserved.
-- Side Setup Script, Star Wars Battlefront II and Zero Engine Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
function RandomLegion()
if unexpected_condition then error() end
CloneLegion = math.random(1,10) --Pic a number between 1 and 10

if CloneLegion <4 then --if math.random results in 2 or three (and maybe 1) 501st
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_rocketeer_chaingun",
"rep_fly_gunship_sc",
"rep_hero_anakin",
"rep_hover_barcspeeder",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")
else
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_rocketeer_chaingun",
"rep_fly_gunship_sc",
"rep_hero_anakin",
"rep_hover_barcspeeder")
end


if CloneLegion >3 and CloneLegion <6 then --if math.random results in 4 or 5 327th
ReadDataFile("SIDE\\rep327th.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")
end

if CloneLegion >5 and CloneLegion <8 then --if math.random results in 6 or 7 212th
ReadDataFile("SIDE\\rep212th.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")
end

if CloneLegion >7 and CloneLegion <11 then --if math.random results in 6 or 7 146th
ReadDataFile("SIDE\\rep146th.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")
end
end[/code]

Download Link
RandomRepLegion.zip


Please post concerns or comments or help with PCall

..Thanks Zerted.
Whoops 3 year edit 1 year 1 month after a 2 year bump
Last edited by Ace_Azzameen_5 on Mon Sep 27, 2010 9:41 pm, edited 1 time in total.
cloneknight
Chief Warrant Officer
Chief Warrant Officer
Posts: 357
Joined: Sun Aug 20, 2006 11:39 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Random Sides Script (Release)

Post by cloneknight »

wow nice.
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: Random Sides Script (Release)

Post by [RDH]Zerted »

Here is a pcall example from v1.3. The Code Console command uses it:
--convert the user's input into a funtion
local userFunction = loadstring( value )

--attempt to run the user's funtion
local result = pcall( userFunction )
Anyway, you could just use ScriptCB_IsFileExist() to see if a file exists.
Edit: Oops, a 2 year bump. Well, I added info and the topic was recently linked to. At least the month and day looked good...
Post Reply