# few questions!

Discussion in 'Triggers & Scripts' started by feerme3, Apr 5, 2010.

1. ### feerme3

Joined:
Apr 26, 2009
Messages:
92
Resources:
0
Resources:
0
Ok my first question is about the following trigger, why doesn't it work? (Its supposed to spawn units in a 'pit' wait until they're dead, spawn a boss, wait until that's dead then move the hero out of the pit)

• Pit 1
• Events
• Conditions
• Actions
• Set Round = (Round + 1)
• Game - Display to (All players) the text: ((Wave + (String(Round))) + (: 24 + (String(creep[Round]))))
• For each (Integer A) from 1 to 12, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Number of units in (Units in Pit[(Integer A)])) Equal to 1
• Then - Actions
• Set temppoint = (Center of Pit[(Integer A)])
• Unit - Create 24 creep[Round] for Neutral Hostile at temppoint facing Default building facing degrees
• Set wave[(Integer A)] = (Last created unit group)
• Wait until ((wave[(Integer A)] is empty) Equal to True), checking every 1.00 seconds
• Game - Display to (Player group((Player((Integer A))))) the text: (Boss + ((String(Round)) + (: 1 + (String(boss[Round])))))
• Unit - Create 1 boss[Round] for Neutral Hostile at temppoint facing Default building facing degrees
• Set boss2[(Integer A)] = (Last created unit)
• Custom script: call RemoveLocation(udg_temppoint)
• Wait until ((boss2[(Integer A)] is dead) Equal to True), checking every 1.00 seconds
• Unit - Move hero[(Integer A)] instantly to (Center of Spawn <gen>)
• Else - Actions

My second question is: Is it possible to make is so Conversion String-UnitType will return the units name not its raw data code?

Thanks a bunch

2. ### Pharaoh_

Joined:
Nov 6, 2008
Messages:
8,128
Resources:
11
Icons:
3
Skins:
1
Spells:
6
Tutorials:
1
Resources:
11
• Set wave[(Integer A)] = (Last created unit group)

To claim that you have (Last created unit group), you need an action through the Unit Group category, not the Unit category. You simply created a Unit, you didn't create a Unit Group. So, change the wave[] variable into a Unit variable, instead of the current Unit Group and use
• Wait until ((wave[(Integer A)] is dead) Equal to True), checking every 1.00 seconds

You don't have to make a conversion of Unit-type, you just need the "Unit - Unit name" function. When it asks you to add a string (in the Strings window, e.g. "Game - Display to All players the text: Text"), scroll to Unit - Unit name. Example:
• Game - Display to (All players) the text: (Name of (Triggering unit))

Jass way:

Code (vJASS):
GetUnitName(GetTriggerUnit())

3. ### feerme3

Joined:
Apr 26, 2009
Messages:
92
Resources:
0
Resources:
0
Actually in my trigger its creating 24 units, and if you read Blizzard's disruption of 'create unit' it says use 'last created unit group to refer to these units.

And are you sure because the 'creep' variable I use in the trigger is a unit-type variable not a unit one. I'd need to create that type of unit or something.

I think it has to do with the wait causing a bug in the loop but I can't figure out a workaround

4. ### ZiggyMcjoney

Joined:
May 4, 2008
Messages:
109
Resources:
1
Maps:
1
Resources:
1
I'm afraid you are mistaken. If you create 24 units at once, you can't use Last created unit group to refer to all of them, without setting them into an actual unit group.

Code (Text):
For each Integer B from 1 to 24 do:
Loop (Actions):
Unit - Create 1 creep[Round] for Neutral Hostile at temppoint facing Default building facing degrees
Unit Group - Add (Last created unit) to CreepGroup[Integer A]
CreepGroup is a unit group variable, obviously.

Also, I'm assuming you have twelve players, and thus twelve pits?

If you have waits inside those loops, what is going to happen is that the units spawn for player 1, then when he kills them all, the boss spawns, he kills that boss, then the units will spawn for player 2. This will go in a cycle until it reaches the 12th player, and then come back to player 1 again. It will take forever.

The answer is to basically not use waits.

The other problem you have with what you have done is that a unit is not actually removed from the unit group automatically when it dies. You have to do that yourself.

I'd suggest using custom values or something to identify which unit belongs to which Player's pit (you could also use a "Unit is in region" condition) and then remove them from the unit group when they die, and ALSO check if there are no units left in that group.

So after you spawn them, do "Unit - Set Custom Value of (Last created unit) to Integer A"

You'll also need to set each player's region to a region array variable, say "Spawn_Region"

Code (Text):
Events
A unit dies

Conditions
Owner of (Triggering unit) Equal to Neutral Hostile

Actions
For each Integer A from 1 to 12, do:
Loop - (Actions):
If (Triggering unit) is in CreepGroup[Integer A] then do:
Remove (Triggering unit) from CreepGroup[Integer A]
If (Number of units in CreepGroup[Integer A]) Less than or equal to 0 then:
Set Temp_Point = Centre of Spawn_Region[Integer A]
Create 1 boss[round] for Neutral Hostile at Temp_Point facing Default building facing degrees
call RemoveLocation(udg_Temp_Point)
And whatever else you need to do.

Sorry if you don't actually need the last bit, but you almost definitely do need to get rid of that wait!

5. ### feerme3

Joined:
Apr 26, 2009
Messages:
92
Resources:
0
Resources:
0
Ok so the main problem is solved, i just separated the waits into 3 different triggers.

Trigger1
• Pit 1
• Events
• Conditions
• Actions
• Set Round = (Round + 1)
• Game - Display to (All players) the text: ((Wave + (String(Round))) + (: 24 + (String(creep[Round]))))
• For each (Integer A) from 1 to 12, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Number of units in (Units in Pit[(Integer A)])) Equal to 1
• Then - Actions
• Set temppoint = (Center of Pit[(Integer A)])
• Unit - Create 24 creep[Round] for Neutral Hostile at temppoint facing Default building facing degrees
• Set wave[(Integer A)] = (Last created unit group)
• Else - Actions
• Wait 2.00 seconds
• Trigger - Turn on Pit 1 Copy 2 <gen>

Trigger 2
• Pit 1 Copy 2
• Events
• Time - Every 1.00 seconds of game time
• Conditions
• Actions
• For each (Integer A) from 1 to 12, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (All units of wave[(Integer A)] are dead) Equal to True
• (Pit[(Integer A)] contains hero[(Integer A)]) Equal to True
• Boss_spawn[(Integer A)] Equal to False
• Then - Actions
• Set temppoint = (Center of Pit[(Integer A)])
• Game - Display to (Player group((Player((Integer A))))) the text: (Boss + ((String(Round)) + (: 1 + (String(boss[Round])))))
• Unit - Create 1 boss[Round] for Neutral Hostile at temppoint facing Default building facing degrees
• Set boss2[(Integer A)] = (Last created unit)
• Set Boss_spawn[(Integer A)] = True
• Custom script: call DestroyGroup(udg_wave[GetForLoopIndexA()])
• Custom script: call RemoveLocation(udg_temppoint)
• Else - Actions
• Wait 2.00 seconds
• Trigger - Turn on Pit 1 Copy 2 Copy <gen>

Trigger 3
• Pit 1 Copy 2 Copy
• Events
• Time - Every 1.00 seconds of game time
• Conditions
• Actions
• For each (Integer A) from 1 to 12, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• pit_players Equal to pit_players_Copy
• Pit_active Equal to True
• Then - Actions
• Trigger - Turn off Pit 1 Copy 2 <gen>
• Trigger - Turn off Pit 1 <gen>
• Trigger - Turn off (This trigger)
• Game - Display to (All players) the text: Well done, wave com...
• Countdown Timer - Start Break_timer as a One-shot timer that will expire in 60.00 seconds
• Countdown Timer - Create a timer window for (Last started timer) with title Break Time
• Set Pit_active = False
• Hero - Instantly revive hero[(Integer A)] at (Center of Spawn <gen>), Show revival graphics
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (boss2[(Integer A)] is dead) Equal to True
• Boss_spawn[(Integer A)] Equal to True
• (Pit[(Integer A)] contains hero[(Integer A)]) Equal to True
• Then - Actions
• Unit - Move hero[(Integer A)] instantly to (Center of Spawn <gen>)
• Camera - Set the camera bounds for (Player((Integer A))) to (Initial camera bounds)
• Camera - Pan camera for (Player((Integer A))) to (Center of (Playable map area)) over 0.00 seconds
• Game - Display to (Player group((Player((Integer A))))) the text: (Well done. You have completed wave + ((String(Round)) + . Please wait until all other players are finished))
• Set pit_players_Copy = (pit_players_Copy + 1)
• Else - Actions

P.S if last created group doesnt work then why does this
Group trigger
• Melee Initialization
• Events
• Time - Elapsed game time is 5.00 seconds
• Conditions
• Actions
• Unit - Create 24 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
• Set Unit_group_var = (Last created unit group)
• Wait 2.00 seconds
• Unit Group - Pick every unit in Unit_group_var and do (Actions)
• Loop - Actions
• Unit - Kill (Picked unit)