• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Spell that teleports hero to it's position 10 seconds ago [Using position array]

Status
Not open for further replies.
Level 2
Joined
Jan 1, 2020
Messages
8
Hello, I am trying to create an item that allows the hero to teleport to it's position 10 seconds ago. To do this, I used a position array of 10 blocks, 1 block for each second in the 10 sec cycle. "SecondCounter" is a integer that I use to move across blocks in the position array. "StillAlive_Red" is to see if the hero was still alive 10 seconds ago, if not I plan to revive it.

I tired running the code but nothing happens. Any help? Trying to stick with GUI.
ZkgtJWR.png
6cB4Ihv.png
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,878
Some pointers:

  • You should design your triggers to be Event based.
  • Stay away from Waits inside Loops if possible. Be wary of using Waits as they can often cause problems if you don't follow a specific set of rules (long story short, Triggering Unit is the only safe Event Response to use after a Wait).
  • You're leaking Points. See Things That Leak in my signature. I clean up the Points in my examples using the "RemoveLocation" custom script.
  • That StillAlive_Red boolean serves no purpose, just use the Condition that you were already using:
  • (Blademaster of Fire 0004 <gen> is alive) Equal to True

Here's an example map I threw together that takes advantage of Unit Groups, Unit arrays, Point arrays, and using Player Numbers to keep track of these Arrays. Red = 1, Blue = 2, Teal = 3, etc... You'll see that I use these numbers in my [Arrays] to keep track of information for each specified player. This makes triggering a much easier process with a lot less repetition. You should try to avoid variables like TenSecAgoPos_Red that will have a version for each player (TenSecAgoPos_Blu, TenSecAgoPos_Teal, etc). There's always a better alternative, if you can't use an Array then Hashtables can get the job done.

Maybe your map only has one Blademaster that can be teleported which makes a lot of what I've done overkill and unnecessary, but I wanted to show you how this can be setup for multiple players regardless.

  • Setup heroes
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Keep track of and add player 1/2/3 blademaster's to the unit group --------
      • Set VariableSet BM_Heroes[1] = Blademaster 0000 <gen>
      • Set VariableSet BM_Heroes[2] = Blademaster 0001 <gen>
      • Set VariableSet BM_Heroes[3] = Blademaster 0002 <gen>
      • Unit Group - Add Blademaster 0000 <gen> to BM_Group
      • Unit Group - Add Blademaster 0001 <gen> to BM_Group
      • Unit Group - Add Blademaster 0002 <gen> to BM_Group

This may have issues since it only tracks the positions every 10 seconds but I wanted to show you how one single trigger could keep track of the positions of blademasters for multiple players.
  • Set positions
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in BM_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet BM_PN = (Player number of (Owner of (Picked unit)))
          • -------- --------
          • -------- This custom script will prevent the point from leaking (look up memory leaks) it helps with map performance --------
          • Custom script: if udg_BM_Point[udg_BM_PN] != null then
          • Custom script: call RemoveLocation (udg_BM_Point[udg_BM_PN])
          • Custom script: endif
          • -------- --------
          • Set VariableSet BM_Point[BM_PN] = (Position of (Picked unit))

I wasn't sure how your map worked but in this case I designed the Use Item trigger to work so that it teleported the Blademaster that belonged to the player that used the item. It can be adjusted to lets say teleport the target unit of the item for example.
  • Move hero
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • Set VariableSet BM_PN = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (BM_Heroes[BM_PN] is alive) Equal to True
        • Then - Actions
          • Unit - Move BM_Heroes[BM_PN] instantly to BM_Point[BM_PN]
        • Else - Actions

Since we're tracking the Blademasters in a unit group, we can easily determine when any of them die and revive them. Triggering Unit is safe to use here after the Wait, it's the one Event Response that you can do this with.
  • Revive hero
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in BM_Group.) Equal to True
    • Actions
      • Wait 10.00 seconds
      • Set VariableSet BM_Point[0] = (Position of (Triggering unit))
      • Hero - Instantly revive (Triggering unit) at BM_Point[0], Hide revival graphics
      • Custom script: call RemoveLocation (udg_BM_Point[0])
 

Attachments

  • BM Teleport.w3m
    18.4 KB · Views: 18
Last edited:
Stay away from Waits inside Loops if possible. Be wary of using Waits as they can often cause problems if you don't follow a specific set of rules (long story short, Triggering Unit is the only safe Event Response to use after a Wait).

The revival trigger also only works for one player.

Aside from that, the core logic is there. I'm still curious if the revival part is enforced automatically without using the item (which is why I'm asking the OP for a description of the item for a clearer picture).
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,878
The issue is that the Event Responses can get overwritten. They aren't local to the trigger as far as I'm aware, aside from Triggering Unit.

The revival trigger should work for all players, or at least Player 1/2/3 in this case.

And yeah, I didn't really know what he wanted exactly but I figured I'd throw something simple together.
 
Last edited:
Level 2
Joined
Jan 1, 2020
Messages
8
The issue is that the Event Responses can get overwritten. They aren't local to the trigger as far as I'm aware, aside from Triggering Unit.

The revival trigger should work for all players, or at least Player 1/2/3 in this case.

And yeah, I didn't really know what he wanted exactly but I figured I'd throw something simple together.
Thank you so much, the trigger works as excepted. As for the full item description; after using the items all blademasters (there are 7 allied blademasters, all will be affected by the item regardless of distance) will be returned to their position, HP and Mana to what they were 10 seconds ago. If a blademaster has died in the last 10 second they would be revived as well in their position 10 seconds ago. However, if the BM died more than 10 second ago nothing would happen to them. I created IsStillAlive boolean to keep track of a specific blademaster was stilll 10 sec ago.

Could you add in the restore HP and Mana part to the trigger as well? Thanks so much, I am not very good with the editor xD
 
Status
Not open for further replies.
Top