Page 1 of 1

Loading a Random Unit

Posted: Sun Jan 15, 2012 5:18 pm
by destos
So when determining the sides I wanted to use, I got a cool Idea but I'm not sure if its possible.

Basically I wanted to have a team that has a list of average units, but then one of the playable units is selected at random from a list of soldiers on the other team. (in a sense to simulate a random "bribe" towards an enemy soldier to fight for your side, and the class unit is selected at random)

Since It would be cool to have team 1 have one unit that team 2 has, but I wasn't sure if there was a way to code for a random selection of the unit that was to be "bribed".

Heres a visual representation of what I mean
Hidden/Spoiler:
Imperial Army:
StormTrooper
Rockettrooper
Scout
Engineer
officer
Dark Trooper

Rebel team:
Infantry
vanguard
Sniper
Engineer
Spy
Random Unit from the Imperial List
Any and all help would be appreciated.

Re: Loading a Random Unit

Posted: Sun Jan 15, 2012 5:34 pm
by willinator
I think that the easiest way to do this is the script released here. Then, what you would do is make each of the sides the same, except load a different imperial unit on the rebel's team for each side. I believe this will work, however, in battle it will be very confusing. The AI will deal with it just fine, but you will probably kill your own men a lot.

Re: Loading a Random Unit

Posted: Sun Jan 15, 2012 5:37 pm
by TK432
I'm not sure if you can make a class change sides after they've been set up. But you could add a random class while playing:
Hidden/Spoiler:
function RandomClass()
if unexpected_condition then error() end
Class = math.random(1,10) --Pic a number between 1 and 10

if Class <4 then
AddUnitClass(ALL, "<impclass1>",1,2)

if Class >3 and Class <6 then
AddUnitClass(ALL, "<impclass2>",1,2)

if Class >5 and Class <8 then
AddUnitClass(ALL, "<impclass3>",1,2)

if Class >7 and Class <11 then
AddUnitClass(ALL, "<impclass4>",1,2)

end
That's the randomness, you'd just have to do a timer to make it happen during the game. But in that version the chosen class wouldn't leave the other side.

Re: Loading a Random Unit

Posted: Sun Jan 15, 2012 5:56 pm
by destos
@ Tk: I didn't mean after loading, I meant before loading, so that each side both had one unit on both sides, but every time you played the map it was a different unit every time. Think of it as the Hutts (which is really the side I was planning to use this is) captured or bribed some soldiers before the battle began from the other team, and used them in battle. That was more what I was going for.

@ Willinator: This was what I was thinking of, but thought that there might have been another way to do it instead of making multiple sides just to have one unit different each time it loaded. Also to deal with the confusion I might just make slight variants of the unit so that they have a special insignia or something on them, that way the confusion is much less likely.

Thank You!

Re: Loading a Random Unit

Posted: Sun Jan 15, 2012 6:02 pm
by TK432
Then just use the code i posted above. It does that exact thing. If you change the sides and classes in AddUnitClass it works for the imperials aswell.
If you just want that selected unit to be playable while other classes run around you should go with the script willinator posted and use a 3rd team for the units you don't wanna have playable.

Re: Loading a Random Unit

Posted: Sun Jan 15, 2012 6:09 pm
by Noobasaurus
destos wrote:@ Tk: I didn't mean after loading, I meant before loading, so that each side both had one unit on both sides, but every time you played the map it was a different unit every time. Think of it as the Hutts (which is really the side I was planning to use this is) captured or bribed some soldiers before the battle began from the other team, and used them in battle. That was more what I was going for.
Untested timer, but it's a short one so that right as the game starts it'll start, do what it needs to do, and then be gone. Insert what TK432 put after funtion(timer) and before DestroyTimer(timer).

Code: Select all

	     UnitTimer = CreateTimer("Unit")
	    SetTimerValue(UnitTimer, 0.1)             
	    	StartTimer(UnitTimer)
	    	OnTimerElapse(
	    		function(timer)
	    		DestroyTimer(timer)
	    	end,
	    	UnitTimer
	)