HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Another trigger problem

11-08-2003, 03:27 AM#1
Vallian88
I have a trigger that makes a random number, the random number is between 1 and 10. I have 10 regions and the random number is that region. Then it makes a tower, and a few units there. I need to make it so that when this trigger runs it first checks if there already is a tower in that region.
This is what I have so far:

randomint = random number between 1 and 10
spwanregions = my 10 regions

Events:
Conditions:
Actions:
Trigger - Run Random Intiger <gen> (ignoring conditions)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(spwanregions[randomint] contains (Triggering unit)) Equal to False
Then - Actions
Camera - Pan camera for (Picked player) to (Center of spwanregions[randomint]) over 0.00 seconds
Unit - Create 1 Guard Tower for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Unit - Create 5 Footman for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Unit - Create 5 Rifleman for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Unit - Create 2 Priest for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Else - Actions
Trigger - Run (This trigger) (ignoring conditions)

Basicly I need to make "triggering unit" into the unit-type gaurd tower.
11-08-2003, 03:35 AM#2
AllPainful
I could be wrong, but it looks like your using a Unit comparison for the Conditions...

You need a UNIT-TYPE comparison not a unit comparison...

Then you could set it just fine.

In other words, the condition would be:

Unit type of (unit in region) equal to guard tower
11-08-2003, 03:49 AM#3
Vallian88
Actually I was using a boolean comparison. A unit-type comparison dosen't have anything that checks the region the unit is in. Unit - Unit in region was the only thing I could find.

There is no unit in region or anything of the like.
Unit type of (unit in region) equal to guard tower
11-08-2003, 03:55 AM#4
AllPainful
Unit type comparison can check if a units in region (or so I thought, I never used it, I always do the "Pick all units" it just works better)...

NOTE: CanBuild is a boolean variable, here are the actions you want.

Code:
Set "CanBuild" to true
Pick all units in region
  If
    Picked unit is of type (tower) 
   Then
    set variable "CanBuild" to false
   Else
    do nothing
If
  CanBuild = True
 Then
  ***Your actions here if there is no tower in region***
 Else
  ----Actions here for if region already contains tower----


PS. NEVER do a "Run (this trigger)" without a wait, it will crash that map. Just fair warning. Put a "Wait .5 seconds" before the "run (this trigger)"..
11-08-2003, 04:07 AM#5
Vallian88
How do I do "Pick all units in region"?
The only thing I can find is:

Unit Group - Pick every unit in (Units in spwanregions[randomint]) and do (Actions)
Loop - Actions

But for some reason it came with a loop.
11-08-2003, 04:10 AM#6
AllPainful
It came with a loop, because it is a loop. It picks 1 unit at a time in the region and does the actions. And it loops until it has picked every unit in the region. Which takes nanoseconds to do unless theres like 700 units in that region. :ggani:

Unit Group - Pick every unit in (Units in spwanregions[randomint]) and do (Actions)
Loop - Actions

That is EXACTLY what your looking for.

Just put the

. If
. Picked unit is of type (tower)
. Then
. set variable "CanBuild" to false
. Else
. do nothing

in the loop and you will have the trigger your looking for. :D
11-08-2003, 04:24 AM#7
Vallian88
do you even need the canbuild variable?
This will work fine right?

Actions
Trigger - Run Random Intiger <gen> (ignoring conditions)
Unit Group - Pick every unit in (Units in spwanregions[randomint]) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of (Picked unit)) Equal to Guard Tower
Then - Actions
Wait 0.01 seconds
Trigger - Run (This trigger) (ignoring conditions)
Else - Actions
Camera - Pan camera for (Picked player) to (Center of spwanregions[randomint]) over 0.00 seconds
Unit - Create 1 Guard Tower for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Unit - Create 7 Footman for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
Unit - Create 5 Rifleman for (Picked player) at (Random point in spwanregions[randomint]) facing Default building facing degrees
11-08-2003, 04:26 AM#8
AllPainful
No you don't need the varaible (I just like using them, which is a habit I should prolly get out of...) and yes that should work fine.


EDIT: I WAS WRONG!!!!!! THAT WON'T WORK!!


That won't work because its a loop. Because it picks ALL units (even if the first unit picked matches the condition, it still picks all the others), so if there are 5 units, and 4 aren't towers, then it will run the "Then" actions 1 time and the "Else" actions 4 times... IT WON'T WORK THAT WAY, I was right the first time, you MUST use the variable Idea.