I'm making an RPG style map, where heroes can be teleported back to base. This is achieved by giving the base building a "Summon Hero" spell. The way it's supposed to work is this:
1) Player clicks on Summon Hero spell in base building.
2) Glowy SFX appears around hero, 5 second wait.
3) If hero hasn't been attacked in this five-second delay, teleport happens sucessfully.
If, at any point during the wait, the hero is attacked, the teleport is cancelled.
Here's my code:
TeleportingHeroes - UnitGroup
TeleportSFX - Array to store special effects for later deletion.
temp_Unit, temp_UnitGroup and temp_Point are exactly what they say.
I also have another trigger which fires whenever a unit from the TeleportingHeroes unit group gets attacked, and removes said unit from the unit group.
The trigger works fine if I leave out the check to make sure the unit is still in the group, but when I enable the check, everything goes south. :banghead: The teleporting SFX stays on the unit indefinitely, and the teleport never happens.
The unit group has one unit in it, both before and after the wait. I've already made sure that the other trigger isn't firing accidentally.
Any thoughts?
1) Player clicks on Summon Hero spell in base building.
2) Glowy SFX appears around hero, 5 second wait.
3) If hero hasn't been attacked in this five-second delay, teleport happens sucessfully.
If, at any point during the wait, the hero is attacked, the teleport is cancelled.
Here's my code:
TeleportingHeroes - UnitGroup
TeleportSFX - Array to store special effects for later deletion.
temp_Unit, temp_UnitGroup and temp_Point are exactly what they say.
Code:
Teleport
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Summon Hero
Actions
Custom script: local unit udg_temp_Unit
Set temp_UnitGroup = (Units owned by (Owner of (Casting unit)) matching (((Matching unit) is A Hero) Equal to True))
Set temp_Unit = (Random unit from temp_UnitGroup)
Unit Group - Add temp_Unit to TeleportingHeroes
Game - Display to (All players) the text: (String((Number of units in TeleportingHeroes)))
Special Effect - Create a special effect attached to the origin of temp_Unit using Abilities\Spells\Human\MassTeleport\MassTeleportTo.mdl
Set TeleportSFX[(Player number of (Owner of temp_Unit))] = (Last created special effect)
Wait 5.00 game-time seconds
Game - Display to (All players) the text: wait done
Game - Display to (All players) the text: (String((Number of units in TeleportingHeroes)))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(temp_Unit is in TeleportingHeroes) Equal to True
Then - Actions
Unit Group - Remove temp_Unit from TeleportingHeroes
Special Effect - Destroy TeleportSFX[(Player number of (Owner of temp_Unit))]
Special Effect - Create a special effect attached to the origin of temp_Unit using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
Special Effect - Destroy (Last created special effect)
Set temp_Point = (Position of (Triggering unit))
Unit - Move temp_Unit instantly to temp_Point
Else - Actions
Do nothing
Custom script: call DestroyGroup(udg_temp_UnitGroup)
Custom script: call RemoveLocation(udg_temp_Point)
Custom script: set udg_temp_Unit = null
I also have another trigger which fires whenever a unit from the TeleportingHeroes unit group gets attacked, and removes said unit from the unit group.
The trigger works fine if I leave out the check to make sure the unit is still in the group, but when I enable the check, everything goes south. :banghead: The teleporting SFX stays on the unit indefinitely, and the teleport never happens.
The unit group has one unit in it, both before and after the wait. I've already made sure that the other trigger isn't firing accidentally.
Any thoughts?