• 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.

[Trigger] Items with the same name don't stack

Status
Not open for further replies.
Level 5
Joined
Oct 5, 2012
Messages
67
I want to make a map, where no one could own a item twice (or the second one will have no effect). Is there a way to do this by triggers?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
To prevent a unit from having the same item twice you hve to
  • Events
    • Unit - A unit acquires an item
  • Conditions
    • Unit has item of type(Item-Type of (Item Being Manipulated))
  • Actions
    • Hero - Drop (Item Being Manipulated)
To make it have no effect, you need a Hashtable, a disabled item for each item you have, and replace the enable with the disabled if the unit already owns one item of that type, and turn that disabled item again to enabled when it's dropped.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Better to just drop the same item rather than creating each copy of it (inefficient).
For the same item prevention, here is the code;
  • SSIPS Event
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set ItemCounter = 0
      • Set TempUnit = (Triggering unit)
      • Set TempItem = (Item being manipulated)
      • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of TempItem) Equal to (Item-type of (Item carried by TempUnit in slot LoopingInteger))
            • Then - Actions
              • Set ItemCounter = (ItemCounter + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemCounter Greater than 1
        • Then - Actions
          • Hero - Drop TempItem from TempUnit
        • Else - Actions
Here is the test mapz.
 

Attachments

  • Simple Same Item Prevent System.w3x
    13 KB · Views: 27
Level 12
Joined
Oct 16, 2010
Messages
680
EDITED:

  • SSIPS Event
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set TempUnit = (Triggering unit)
      • Set TempItem = (Item being manipulated)
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of TempItem) Equal to (Item-type of (Item carried by TempUnit in slot (Integer A))
              • TempItem Not Equal to (Item carried by TempUnit in slot (Integer A))
            • Then - Actions
              • Hero - Drop TempItem from TempUnit
            • Else - Actions
defskull is right, but this is just enough
 
Last edited:
Level 12
Joined
Oct 16, 2010
Messages
680
Simple solution without a counter is to drop the item from the hero at the start of the trigger, and give it back to the hero later on when it is determined that they don't have it. Don't forget to turn off/turn on the trigger before/after giving the item back to prevent an infinite loop.

That won't work with drop order though,cuz
since the unit recieves the order the trigger continues and finishes before actually the unit drops the item:S
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
But there is a main problem with all of these triggers.
Are you sure it includes my trigger as well ?

Also,
If you repeatedly pick up two items, occasionally it ends with picking one up even if you already have 1 like it:p
What do you meant by "repeatedly pick up two items" ?
Do you mean to pick that item in a quick manner ?
You do know that all of that triggers are instant ?
No delay occurs, therefore it will run as single-thread as it intended, no bugs will occur such as having 1 item leak (event leak) because of "too fast event".
 
EDITED:

  • SSIPS Event
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set TempUnit = (Triggering unit)
      • Set TempItem = (Item being manipulated)
      • For each (Integer LoopingInteger) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of TempItem) Equal to (Item-type of (Item carried by TempUnit in slot (Integer A))
              • TempItem Not Equal to (Item carried by TempUnit in slot (Integer A))
            • Then - Actions
              • Hero - Drop TempItem from TempUnit
            • Else - Actions
defskull is right, but this is just enough

doesn't work
 
Status
Not open for further replies.
Top