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

2 sames item check

Status
Not open for further replies.
Level 3
Joined
Nov 5, 2010
Messages
28
Hi huys :)

I shematize my problem :

Event
Condition : triggering unit have 2 items A
Action : remove 2 items A of triggering unit and add 1 item B

Of course, I tried a lot of triggers, but I failed :(

(sorry for my poor english)

Thanks :)
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
What you need to do is check each inventory slot and use a counting variable.
If the slot holds an item-type A, increase the count variable by 1.
After all 6 slots are checked, see if count is at least 2.
If it is, use a similar process to remove 2 of the item-type A and add 1 of item-type B.
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
  • A
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-Type of (Item being manipulated)) Equal to Item A
    • Actions
      • Set ItemACount = (ItemACount + 1)
      • If All Conditions are true then do (Multiple Actions) else do (Multiple Actions)
        • If - Conditions
          • ItemACount Greater than or equal to 2
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Item A)
          • Item - Remove (Item carried by (Triggering unit) of type Item A)
          • Set tempPoint = (Position of (Triggering unit))
          • Item - Create Item B at tempPoint
          • Custom script : call RemoveLocation (udg_tempPoint)
        • Else - Actions
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
This would only work right if he also made a trigger checking if the player drops the item and its not MUI so if someone gets an item type A and the count is already at 1 then he gets the item.

ah, completely forgot about that.

this should work

  • Unit Indexer
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call ExecuteFunc("InitializeUnitIndexer")
      • Custom script: endfunction
      • -------- --------
      • -------- This is the most important function - it provides an index for units as they enter the map --------
      • -------- --------
      • Custom script: function IndexUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • -------- --------
      • -------- You can use the boolean UnitIndexerEnabled to protect some of your undesirable units from being indexed --------
      • -------- - Example: --------
      • -------- -- Set UnitIndexerEnabled = False --------
      • -------- -- Unit - Create 1 Dummy for (Triggering player) at TempLoc facing 0.00 degrees --------
      • -------- -- Set UnitIndexerEnabled = True --------
      • -------- --------
      • -------- You can also customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UnitIndexerEnabled Equal to True
        • Then - Actions
          • -------- --------
          • -------- Generate a unique integer index for this unit --------
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • UDexRecycle Equal to 0
            • Then - Actions
              • Set UDex = (UDexGen + 1)
              • Set UDexGen = UDex
            • Else - Actions
              • Set UDex = UDexRecycle
              • Set UDexRecycle = UDexNext[UDex]
          • -------- --------
          • -------- Link index to unit, unit to index --------
          • -------- --------
          • Set UDexUnits[UDex] = (Matching unit)
          • Unit - Set the custom value of UDexUnits[UDex] to UDex
          • -------- --------
          • -------- Use a doubly-linked list to store all active indexes --------
          • -------- --------
          • Set UDexPrev[UDexNext[0]] = UDex
          • Set UDexNext[UDex] = UDexNext[0]
          • Set UDexNext[0] = UDex
          • -------- --------
          • -------- Fire index event for UDex --------
          • -------- --------
          • Set UnitIndexEvent = 0.00
          • Set UnitIndexEvent = 1.00
          • Set UnitIndexEvent = 0.00
          • Custom script: set udg_UDex = pdex
        • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function is called each time a unit enters the map --------
      • -------- --------
      • Custom script: function IndexNewUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • Custom script: local integer ndex
      • -------- --------
      • -------- Recycle indices of units no longer in-play every (15) units created --------
      • -------- --------
      • Set UDexWasted = (UDexWasted + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UDexWasted Equal to 15
        • Then - Actions
          • Set UDexWasted = 0
          • Set UDex = UDexNext[0]
          • Custom script: loop
          • Custom script: exitwhen udg_UDex == 0
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of UDexUnits[UDex]) Equal to 0
            • Then - Actions
              • -------- --------
              • -------- Remove index from linked list --------
              • -------- --------
              • Custom script: set ndex = udg_UDexNext[udg_UDex]
              • Custom script: set udg_UDexNext[udg_UDexPrev[udg_UDex]] = ndex
              • Custom script: set udg_UDexPrev[ndex] = udg_UDexPrev[udg_UDex]
              • Set UDexPrev[UDex] = 0
              • -------- --------
              • -------- Fire deindex event for UDex --------
              • -------- --------
              • Set UnitIndexEvent = 2.00
              • Set UnitIndexEvent = 0.00
              • -------- --------
              • -------- Recycle the index for later use --------
              • -------- --------
              • Set UDexUnits[UDex] = No unit
              • Set UDexNext[UDex] = UDexRecycle
              • Set UDexRecycle = UDex
              • Custom script: set udg_UDex = ndex
            • Else - Actions
              • Set UDex = UDexNext[UDex]
          • Custom script: endloop
          • Custom script: set udg_UDex = pdex
        • Else - Actions
      • -------- --------
      • -------- Handle the entering unit (Matching unit) --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Matching unit)) Equal to 0
        • Then - Actions
          • Custom script: call IndexUnit()
        • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function initializes the core of the system --------
      • -------- --------
      • Custom script: function InitializeUnitIndexer takes nothing returns nothing
      • Custom script: local integer i = 0
      • Custom script: local region re = CreateRegion()
      • Custom script: local rect r = GetWorldBounds()
      • Set UnitIndexerEnabled = True
      • Custom script: call RegionAddRect(re, r)
      • Custom script: call TriggerRegisterEnterRegion(CreateTrigger(), re, Filter(function IndexNewUnit))
      • Custom script: call RemoveRect(r)
      • Custom script: set re = null
      • Custom script: set r = null
      • Custom script: loop
      • Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), Filter(function IndexUnit))
      • Custom script: set i = i + 1
      • Custom script: exitwhen i == 16
      • Custom script: endloop
      • -------- --------
      • -------- This is the "Unit Indexer Initialized" event, use it instead of "Map Initialization" for best results --------
      • -------- --------
      • Set UnitIndexEvent = 3.00
      • Set UnitIndexEvent = 0.00
  • Pick
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Item A
    • Actions
      • Set cv = (Custom value of (Triggering unit))
      • Set ItemACount[cv] = (ItemACount[cv] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemACount[cv] Equal to 2
        • Then - Actions
          • Item - Remove (Item carried by (Triggering unit) of type Item A)
          • Item - Remove (Item carried by (Triggering unit) of type Item A)
          • Hero - Create Item B and give it to (Triggering unit)
        • Else - Actions
  • Drop
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Item A
    • Actions
      • Set cv = (Custom value of (Triggering unit))
      • Set ItemACount[cv] = (ItemACount[cv] - 1)
Here is a test map. i'm using UnitIndexer
 

Attachments

  • Item.w3x
    21.2 KB · Views: 31
Last edited:
Level 3
Joined
Nov 5, 2010
Messages
28
Wow so much replies :D What is UnitIndexer ? (the utility ?)

Thanks :) I edit the post if I have problems with my edited version of triggers for my map.

(I hope you understand my english ;p)

Edit : It's work perfectly :D Thanks a lot !
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
@TwoVenomous: You are over-complicating it! When a unit picks up an item, loop over each inventory slot. If the item-type in that slot is of type A, increase a TEMPORARY count variable by 1. After all slots have been checked, check if the count variable equals 2. If it does, remove 2 items and add item B.

EDIT: Here is a simple trigger:

  • Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set count = 0
      • 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 (Item carried by (Triggering unit) in slot (Integer A))) Equal to Claws of Attack +15
            • Then - Actions
              • Set count = (count + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • count Greater than or equal to 2
        • Then - Actions
          • Set toRemove = 2
          • 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
                  • toRemove Greater than 0
                  • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to Claws of Attack +15
                • Then - Actions
                  • Set toRemove = (toRemove - 1)
                  • Hero - Drop (Item carried by (Triggering unit) in slot (Integer A)) from (Triggering unit)
                  • Item - Remove (Last dropped item)
                • Else - Actions
          • Hero - Create Kelen's Dagger of Escape and give it to (Triggering unit)
        • Else - Actions
You must obviously change Claws of Attack +15 and Kelen's Dagger of Escape to the item-types you want.
 
Status
Not open for further replies.
Top