Teleport trigger trouble.

Cookie!

Member
Reaction score
0
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.

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?
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Could you upload the map containing the effect? I can't see a problem just from the text.
 

Cookie!

Member
Reaction score
0
Here's a map illustrating what I'm trying to say:
 

Attachments

  • Teleport trouble.w3x
    18.7 KB · Views: 242

jackall

You can change this now in User CP.
Reaction score
37
I see that you tried shadowing a global variable using a local one and afaik that is no longer possible. I deleted that line

Trigger:
  • Custom script: local unit udg_temp_Unit


and the triggers worked as intended.

View attachment Teleport trouble.w3x

Hmm... Nevermind about the shadowing, it seems to be working. Looks like there's just something wrong about that local unit variable.
 

Cookie!

Member
Reaction score
0
No longer possible? I'm afraid you lost me there.

I need the variable to be local, as several players could be teleporting at once. If that line is removed, the trigger loses MPI functionality, right?
 

afisakov

You can change this now in User CP.
Reaction score
37
Afraid I don't know too much about local variable, but another good way to make it MPI is to make temp_unit an array, and then set the number equal to player number.
so the the line would look like: set temp_unit[player number of owner of casting unit]=...
this makes it MPI without needing local variables, assumming each player has only 1 hero, which seems true if u can find that hero with "Random unit from temp_UnitGroup"

btw, I would move
Custom script: call DestroyGroup(udg_temp_UnitGroup)
to just above the wait, u r done with it by then and it prevents the risk that it gets overwritten by another player (during the wait) before it can be removed.

As for the special effect, it stays on because by the time u try to get rid of it, it is no longer "last created". You might have to make a special effect array, set it to last created special effect, and then remove the special effect later this way. Not sure, never actually tried doing this.
 

Cookie!

Member
Reaction score
0
After a bit of testing, I've come to the conclusion that jackall is right, it is the shadowing that is messing the trigger up. I implemented a check right after the wait to find out if temp_Unit is alive, and apparently, it wasn't. :nuts:

Anyhow, I designed something along the lines of what afisakov suggested, and I have something that works.

I've used a dummy unit to buff the teleporting hero with a "Teleporting" buff, and the trigger checks for this buff after the wait. The other trigger removes this buff if the unit gets attacked.

Trigger:
  • Teleport Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Summon Hero
    • Actions
      • Set temp_UnitGroup = (Units owned by (Owner of (Triggering unit)) matching (((Matching unit) is A Hero) Equal to True))
      • Set Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))] = (Random unit from temp_UnitGroup)
      • Custom script: call DestroyGroup(udg_temp_UnitGroup)
      • Set temp_Point = (Position of Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))])
      • Unit - Create 1 Dummy Unit for (Owner of (Triggering unit)) at temp_Point facing Default building facing degrees
      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
      • Unit - Add Teleport Dummy to (Last created unit)
      • Unit - Order (Last created unit) to Orc Shaman - Bloodlust Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))]
      • Custom script: call RemoveLocation(udg_temp_Point)
      • Wait 5.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))] has buff Teleporting ) Equal to True
        • Then - Actions
          • Unit - Remove Teleporting buff from Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))]
          • Special Effect - Create a special effect attached to the origin of Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))] using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
          • Special Effect - Destroy (Last created special effect)
          • Set temp_Point = (Position of (Triggering unit))
          • Unit - Move Teleporting_Heroes[(Player number of (Owner of (Triggering unit)))] instantly to temp_Point
          • Camera - Pan camera as necessary for (Owner of (Triggering unit)) to temp_Point over 1.00 seconds
          • Custom script: call RemoveLocation(udg_temp_Point)
        • Else - Actions


Note that the glowy SFX is now applied through the buff, so that's one less variable for me to trip over. :D

As for the special effect, it stays on because by the time u try to get rid of it, it is no longer "last created". You might have to make a special effect array, set it to last created special effect, and then remove the special effect later this way. Not sure, never actually tried doing this.

I was talking about the first effect, which I did store in an array. Despite this, it remained on the unit. (Because, for some reason, the unit was "dead")
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top