• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Spacebar point to Hero

Status
Not open for further replies.
Level 7
Joined
Jun 19, 2017
Messages
141
Hello, i'm trying to make the Spacebar, when pressed to pan the camera at the location of the triggering players Hero. Since there is no event a "A player presses the spacebar", i came out with something like this:
  • Spacebar Camera
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set SpaceUnitGroup = (Units in (Entire map) matching ((((Matching unit) is A Hero) Equal to True) and ((((Matching unit) is hidden) Equal to False) and (((Owner of (Matching unit)) controller) Equal to User))))
      • Unit Group - Pick every unit in SpaceUnitGroup and do (Actions)
        • Loop - Actions
          • Set SpacePoint[(Player number of (Owner of (Picked unit)))] = (Position of (Picked unit))
          • Camera - Set a spacebar-point for (Owner of (Picked unit)) at SpacePoint[(Player number of (Owner of (Picked unit)))]
      • Custom script: call DestroyGroup(udg_SpaceUnitGroup)
I have 2 questions.
1. Will it be a problem if this trigger runs through the entire game?
2. How to delete the location for SpacePoint[(Player number of (Owner of (Picked unit)))]?[/trigger]
 
Last edited:
That is a very costly trigger you have right there. Since enumeration is done quite a lot, it will slow things down. For a workaround, only enumerate the heroes once at map start, and have an enters region event detect more heroes to reduce overhead. The heroes are then to be added to a static group.

In your trigger, all you have to do at this point is to pick every hero in the group as specified above.

2. You destroy the location inside the loop.
 
Level 7
Joined
Jun 19, 2017
Messages
141
I tried destroying it with something like this
  • Custom script: call RemoveLocation(udg_SpacePoint[(Player number of (Owner of (Picked unit)))]
But it gives an error. Any idea what's the correct code for that array ?
 
Last edited:
Level 9
Joined
Apr 23, 2011
Messages
527
Set an integer variable to (Player number of (Owner of Picked unit)). The loop then becomes like this:
  • Unit Group - Pick every unit in SpaceUnitGroup and do (Actions)
    • Loop - Actions
      • Set integer = (Player number of (Owner of (Picked unit)))
      • Set SpacePoint[integer] = (Position of (Picked unit))
      • Camera - Set a spacebar-point for (Player[integer]) at SpacePoint[integer]
      • Custom script: call RemoveLocation(udg_SpacePoint[integer])
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
I have a very different problem with this. I really do not like what is happening in this trigger.

Does the player have only 1 hero EVER or is it like melee and can have 3-4 or more?
In the later case, it will not work as intended at all.
In the former case it does way too many unnecessary things.

If you just register the heroes in a variable and the point to them instead of a unit group like:
  • Set Hero[playerNumber] = hero of player X somehow
and it becomes the following: (warnin, syntax may varry)
  • Spacebar Camera
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each Index from 0 to numberOfPlayers -1
        • Loop - Actions
          • If - Conditions
            • (Hero[Index] is alive equals to true)
          • Then
            • Set TempPoint = Position of Hero[Index]
            • Camera - Set a spacebar-point for Player(index + 1) at TempPoint
            • Custom script: call RemoveLocation(udg_TempPoint)
          • Else
 
Last edited:
Status
Not open for further replies.
Top