• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Trigger] Two units are created instead of one

Level 54
Joined
Jun 2, 2008
Messages
899
i have a trigger where if you're less than 150 distance you can pick up a frog like an item
but it's not important
i created a new empty map specifically to test it and it still happens
what i want is when you drop the frog item it replaces it with a frog critter
  • Events
    • Unit - A unit owned by Player 1 (Red) Loses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Phat Lewt
  • Actions
    • Unit - Create 1 Frog for Neutral Passive at (Position of (Item being manipulated)) facing (Facing of (Triggering unit))
    • Item - Remove (Item being manipulated)
(just imagine that Phat Lewt is some frog item)
why does it create 2 frogs?
here's the map if you don't believe me
 

Attachments

i can only imagine that the line
  • Item - Remove (Item being manipulated)
happens when the item is somehow still in inventory, so it triggers the event itself again?

try to remove this line and see if it only spawns one frog


EDIT: if this is the case, add these two lines

  • Trigger - Turn off this trigger
  • Unit - Create 1 Frog for Neutral Passive at (Position of (Item being manipulated)) facing (Facing of (Triggering unit))
  • Item - Remove (Item being manipulated)
  • Trigger - Turn on this trigger
 
Last edited:
Heyo!

My best guess is that this is a timing issue. The item is still in the Hero's inventory at the time the game handles the "Loses an item" event. Removing the item from the game as part of the trigger at this time then causes the "Loses an item" event to fire a second time, since the item is removed from the Hero's inventory.

I don't know how a sage would solve this, but here's one very inelegant way to solve your test case, which should help you get a clearer view of what's going on:

  • Events
    • Unit - A unit owned by Player 1 (Red) Loses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Phat Lewt
  • Actions
    • Wait 0.00 Seconds
    • Unit - Create 1 Frog for Neutral Passive at (Position of (Item being manipulated)) facing (Facing of (Triggering unit))
    • Item - Remove (Item being manipulated)
Remember to clean up position leaks with whatever implementation you end up using.
 
Gimli is correct. You can add this "is dead" Condition to prevent the Actions from running twice:
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Phat Lewt
    • (Current life of (Item being manipulated)) Greater than 0.00
When the item is removed from the game it'll be set to 0.00 Life, so even though the trigger runs in response to the removal it won't get past the new Condition.

But for the Frog to be created at the Position of the Item you will need a 1 frame delay. This is because the Item "lost" event occurs before the Item has actually been moved to it's new "drop position". These Item events are poorly timed...

A Wait can fix this issue but it's just asking for trouble since it needs to be synced in multiplayer and will take longer than expected. That means there's a window of opportunity where the item could be picked up again before the Frog has even been created.

A safer solution:
I attached a map with a custom "Loses an item" Event which you can use instead. It's setup to run 1 frame after the Event "A unit Loses an item" occurs, allowing for things to work as you'd expect them to. You just have to interface with the system variables instead of the usual Event Responses.
 

Attachments

Last edited:
Back
Top