HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How can I compress this trigger?

12-06-2003, 10:28 PM#1
zotax
This triggers currently not complete, because in its current state it will require a lot of c n p work, and have about 100-300 lines. Illd like to avoid c n p 200+ lines, the going through them and changing most of the values, and im expecting that in its current state for this trgg to generate massive amounts of lag. This trigger is intended to create random spawns. (sorry forgot how to make the special scripting text)

Event: Every 5 secs of gametime
Conditons; n/a
Actions:
If, RandomSpawns=False
Then,
Create 1 UnitTypeSpawned[1] for Player 1 @ UnitSpawnPlace[1]
Create 1 UnitTypeSpawned[2] for Player 2 @ UnitSpawnPlace[2]
.......
Create 1 UnitTypeSpawned[12] for Player 12 @ UnitSpawnPlace[3]
Else
Set RandomRaceNumber=(random number between 1 and 5)
If, Random racenumber=1
Then, If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Peasant
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Peon
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Acoylte
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Treant
.................
If, playerrace[12] is equal to 1 then set UnitTypeSpawned[12] = peasant
If, playerrace[12] is equal to 2 then set UnitTypeSpawned[12] = Peon
If, playerrace[12] is equal to 3 then set UnitTypeSpawned[12] = Acolyte
If, playerrace[12] is equal to 4 then set UnitTypeSpawned[12] = Treant
If, Random racenumber=2
Then, If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Mortar
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Catapult
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = MeatWagon
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Ballista
.................
If, playerrace[12] is equal to 1 then set UnitTypeSpawned[12] = Mortar
If, playerrace[12] is equal to 2 then set UnitTypeSpawned[12] = Catapult
If, playerrace[12] is equal to 3 then set UnitTypeSpawned[12] = MeatWagon
If, playerrace[12] is equal to 4 then set UnitTypeSpawned[12] = Ballista
..........
If, Random racenumber=5
Then, If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Rfileman
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Headhunter
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Crypt Fiend
If, playerrace[1] is equal to 1 then set UnitTypeSpawned[1] = Archer
.................
If, playerrace[12] is equal to 1 then set UnitTypeSpawned[12] = peasant
If, playerrace[12] is equal to 2 then set UnitTypeSpawned[12] = Peon
If, playerrace[12] is equal to 3 then set UnitTypeSpawned[12] = Acolyte
If, playerrace[12] is equal to 4 then set UnitTypeSpawned[12] = Treant

I think you can compress by using something like playner number (something) for each array, but I dont know what to put in the (something). Any help greatly appreciated!
12-06-2003, 10:53 PM#2
Kerry
Use loops. For example you could do like this:

For each (Integer A) from 1 to 12, do (Actions)
Loop - Actions
Unit - Create 1 UnitTypeSpawned[(Integer A)] for (Player((Integer A))) at (Center of UnitSpawnPlace[(Integer A)]) facing Default building facing degrees

Integer A will start on 1 and end on 12 wich means that first it will create a unit of type UnitTypeSpawned[1] at location UnitSpawnPlace[1] and then when done with the actions it will start over but it will create a unit of type UnitTypeSpawned[2] at location UnitSpawnPlace[2]

That's just a example, the rest is for you to figure out by yourself :)
12-07-2003, 04:39 AM#3
zotax
Omg, ty :foot: :foot: how didnt I see this amazing function before?
Triggering just got a lot faster and cleaner, thanks alot.

Had a question, but I think Ive found the solution.
12-07-2003, 12:57 PM#4
Kerry
No problem, I live to help :P

If you ever start programming for 'real' then you will very soon realize that loops are a very useful thing, same goes for if, then, else's.