HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with hero chooser

08-14-2007, 02:08 AM#1
botanic
I have a set of regions that when it is entered I want it to pick a hero for the player as long as the hero is in the region (max one of each hero).

I use this trigger to set the variables
Trigger:
Hero Variables
Collapse Events
Map initialization
Conditions
Collapse Actions
Set Hero_Region[1] = Shapeshifter Loc <gen>
Set Hero_Enter[1] = Shapeshifter <gen>
Set Hero_Region[2] = Demon Loc <gen>
Set Hero_Enter[2] = Demon <gen>
Set Hero_Region[3] = Stormbringer Loc <gen>
Set Hero_Enter[3] = Stormbringer <gen>
Set Hero_Region[4] = Jaguar Loc <gen>
Set Hero_Enter[4] = Jaguar <gen>
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Trigger - Add to Hero Create <gen> the event (Unit - A unit enters Hero_Enter[(Integer A)])
And this to pick it
Trigger:
Hero Create
Events
Collapse Conditions
((Triggering unit) is Summoned) Equal to False
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Wait 0.01 game-time seconds
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Hero_Enter[(Integer A)] contains (Triggering unit)) Equal to True
Collapse Then - Actions
-------- set variables --------
Set tempunitgroup = (Units in Hero_Enter[(Integer A)])
Set L = (Center of Spawn <gen>)
Set tempregion = Hero_Region[(Integer A)]
Set tempunitgroup = (Units in tempregion)
Set Temp_Unit = (Random unit from tempunitgroup)
-------- end variables --------
-------- Unit Specific Events --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of Temp_Unit) Equal to Greater Stormbringer
Collapse Then - Actions
Set Temp_Hero_String = ReplaceableTextures\CommandButtons\BTNMedivh.blp
Unit - Add Quicken to Temp_Unit
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of Temp_Unit) Equal to Demon Caller
Collapse Then - Actions
Set Temp_Hero_String = ReplaceableTextures\CommandButtons\BTNHeroBloodElfPrince.blp
Trigger - Turn on Explosive Cast <gen>
Unit - Add Infernal Strike to Temp_Unit
Collapse Unit Group - Pick every unit in tempunitgroup and do (Actions)
Collapse Loop - Actions
Set Temp_Unit = (Picked unit)
Set Explosive_Caster = (Picked unit)
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of Temp_Unit) Equal to Jaguar Warrior
Collapse Then - Actions
Set Temp_Hero_String = ReplaceableTextures\CommandButtonsDisabled\BTNJaguarWarrior.blp
Unit - Add Battle Hardened to Temp_Unit
Special Effect - Create a special effect attached to the chest of Temp_Unit using Abilities\Spells\Orc\Voodoo\VoodooAuraTarget.mdl
Set Jag_War_Effect = (Last created special effect)
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit-type of Temp_Unit) Equal to Shapeshifter (Int)
Collapse Then - Actions
Set Temp_Hero_String = ReplaceableTextures\CommandButtons\BTNAssassin.blp
Unit - Add Battle Hardened to Temp_Unit
Else - Actions
-------- End Unit Specific Events --------
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
Hero - Give (Item carried by (Triggering unit) in slot (Integer A)) to Temp_Unit
Unit - Move Temp_Unit instantly to L
Unit - Change ownership of Temp_Unit to (Owner of (Triggering unit)) and Change color
Camera - Pan camera for (Owner of (Triggering unit)) to L over 0.00 seconds
Hero - Set Temp_Unit Hero-level to (Custom value of (Triggering unit)), Hide level-up graphics
Selection - Select Temp_Unit for (Owner of (Triggering unit))
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Owner of (Triggering unit)) Equal to Players[(Integer A)]
Collapse Then - Actions
Set Repick[(Integer A)] = tempregion
Multiboard - Set the icon for Scoreboard item in column 1, row ((Integer A) + 1) to Temp_Hero_String
Else - Actions
Unit - Remove (Triggering unit) from the game
Set Repick[(Integer A)] = tempregion
Custom script: call RemoveLocation (udg_L)
Custom script: call DestroyGroup (udg_tempunitgroup)
Skip remaining actions
Else - Actions
08-14-2007, 11:14 AM#2
Pytho
It would be a good idea to tell us what's not working or why else you need help.
What I don't understand from the first look: Why are your loops going from 1 to 12 when you declared only Hero_Region[1] to Hero_Region[4].
08-17-2007, 04:22 AM#3
botanic
the loop is because there will be 12 heros just there arent yet ;/ be ways just sometimes you bring the unit over the area and it doesnt work... also sometimes it takes nearly a second of being on the area before it picks the hero -.-
08-17-2007, 12:10 PM#4
Pytho
in general it isn't a good idea to use variables which aren't initialized, that can cause unpredictable results, so better only loop through variables you have initialized.

Another thing which isn't such a good idea is to use the same variable (in your case "Integer A") in loops which run inside another loop, because both loops change the value of the variable. But I don't think that will cause the error, because you leave the trigger after running the second loop once.

I also don't understand the sense of the "wait 0.01 sec" at the beginning.

Try to enclose the point where the error occurs by using debugmessages.
08-17-2007, 07:19 PM#5
botanic
the reason for the .01 was because it wasnt working and that made it work MORE often...
08-19-2007, 08:41 PM#6
botanic
Well i tried adding in debug messages and it seems to not work at different spots...

I think it might be the "units in region" because maby the unit isnt in the region when it enters ;/

Ne ways also sometimes it takes 5+ seconds before the trigger picks a hero ~.~

so ya... no idea still