• 🏆 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!

[General] Trigger broken: Item used to spawn units

Status
Not open for further replies.
Level 7
Joined
Mar 9, 2016
Messages
226
I want to allow a player to be able to spawn an army when they hold an item called "Emperor's key".
After they write "-Unlock" the item is consumed (Deletes)

Here's the trigger, for some reason its not working.

  • Emperors Key
    • Events
      • Player - (Owner of Emperor's Key 0437 <gen>) types a chat message containing -Unlock as An exact match
    • Conditions
      • (Matching item) Equal to Emperor's Key 0437 <gen>
    • Actions
      • Unit - Create 44 Footman for (Triggering player) at (Center of Kings spawn <gen>) facing Default building facing degrees
      • Unit - Create 4 Captain for (Triggering player) at (Center of Kings spawn <gen>) facing Default building facing degrees
      • Item - Remove Emperor's Key 0437 <gen>
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
There is no matching item.

Matching item only works within filter functions for item groups.
Just remove the condition (and the leaks, but that's a different problem).
 
Level 7
Joined
Mar 9, 2016
Messages
226
Why not make the item usable instead of requiring a clunky chat command? There are events for an item being used, and then you can just remove the item being manipulated.
Maybe, but that still doesn't solve the issue, its just a different approach to trigger the event. Its a good one though.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
I think the event does not work.
Events are created at map initialization, so you cannot use non-constant variables in it (at least they won't work as you intended). You must use any playable player types...
and add a condition triggering player == owner of ...
 
Level 11
Joined
Jun 2, 2004
Messages
849
The issue is ownership; the item is not in fact "owned" by the unit holding it. The owner of a preplaced item will always be player 16 as far as I can tell.


Internally, items are just slightly-modified units and have some weird behavior along these lines.
 
Level 12
Joined
May 13, 2017
Messages
139
Will this work for you?

FinishCinematic.png
 
Level 7
Joined
Mar 10, 2013
Messages
366
It's best to check the event for "-Unlock" for anyone, and check if the triggering player's hero has the Emperor's key.

If players can have more than one unit I can help with a trigger to overcome that problem, otherwise, it will probably be easy (you probably already have an array of heroes matching each player, don't you?).
 
Level 7
Joined
Mar 9, 2016
Messages
226
It's best to check the event for "-Unlock" for anyone, and check if the triggering player's hero has the Emperor's key.

If players can have more than one unit I can help with a trigger to overcome that problem, otherwise, it will probably be easy (you probably already have an array of heroes matching each player, don't you?).
Yeah, there's over 10 heroes for each player.

Will this work for you?

View attachment 268672

There's only 1 item, only 1 "Emperor's key" and it disappears after use, wouldn't that condition require all heroes to have the item?
There's 8 heroes on the map by default, though more heroes are trained within the gameplay, so I cant really select them from the editor.
 
Level 7
Joined
Mar 10, 2013
Messages
366
  • Emperor Key Unlock
    • Events
      • Player - Player 1 (Red) types a chat message containing -Unlock as An exact match
      • Player - Player 2 (Blue) types a chat message containing -Unlock as An exact match
      • Player - Player 3 (Teal) types a chat message containing -Unlock as An exact match
      • Player - Player 4 (Purple) types a chat message containing -Unlock as An exact match
    • Conditions
    • Actions
      • Set PlayerHeroesGroupTemp = (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))
      • Set AnyHeroHasEmperorKey = False
      • Unit Group - Pick every unit in PlayerHeroesGroupTemp and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has an item of type Emperor's Key) Equal to True
            • Then - Actions
              • Set AnyHeroHasEmperorKey = True
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AnyHeroHasEmperorKey Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in PlayerHeroesGroupTemp and do (Actions)
            • Loop - Actions
              • Item - Remove (Item carried by (Picked unit) of type Emperor's Key)
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • Custom script: call DestroyGroup( udg_PlayerHeroesGroupTemp )
I couldn't test this, but it should work for you. There are some improvements that could be made, but overall it's fine and doens't leak.

Don't forget, it has two variables:
- PlayerHeroesGroupTemp of type Unit Group
- AnyHeroHasEmperorKey of type Boolean

Any questions, I'm here to answer.
 
Status
Not open for further replies.
Top