• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Bug, Related to Items and Units [Help]

Status
Not open for further replies.
Hello dear Hivers again :D

I have made a little system that allows you to make greater item from two same weaker ones (like you have two Rings of Protection +1, and this system mades Ring of Protection +2 for your unit)

Main feature of this system is, that items of this kind doesn't take 2 invertory slots, but only 1. :D

The system works pretty well actually, the problem comes when there are two units on the map owned by same player, so if one unit have one Ring of Protection +1, and the second unit have also one Ring of Protection +1
the system will bug and will create Ring of Protection +2 for the second unit, and first unit will still have Ring of Protection +1 in it's invertory.

Do you know what i mean?

  • Ring of Protection
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set Item_Owner[6] = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item_Owner[6] has an item of type Item[16]) Equal to True
        • Then - Actions
          • Set Item_Counter2[(Player number of (Owner of (Triggering unit)))] = (Item_Counter2[(Player number of (Owner of (Triggering unit)))] + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Counter2[(Player number of (Owner of (Triggering unit)))] Equal to 2
        • Then - Actions
          • Set Item_Counter2[(Player number of (Owner of (Triggering unit)))] = 0
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • Item - Remove (Item carried by Item_Owner[6] of type Item[16])
          • Hero - Create Item[17] and give it to Item_Owner[6]
          • Special Effect - Create a special effect attached to the origin of Item_Owner[6] using Abilities\Spells\Demon\DarkPortal\DarkPortalTarget.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
This is the main trigger that checks for the amount of same items, in this case is 2, and if it's 2 removes those two items and creates the new one.

  • Ring of Protection Drop
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Item[16]
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Counter2[(Player number of (Owner of (Triggering unit)))] Equal to 1
        • Then - Actions
          • Set Item_Counter2[(Player number of (Owner of (Triggering unit)))] = (Item_Counter2[(Player number of (Owner of (Triggering unit)))] - 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Counter2[(Player number of (Owner of (Triggering unit)))] Equal to 0
        • Then - Actions
          • Set Item_Counter2[(Player number of (Owner of (Triggering unit)))] = 0
        • Else - Actions
This trigger is secondary trigger that checks if the item has ben removed from invertory, so I just simply reset the counter



Edit I:

Oh, I forgot to mention... When you see Item [11]...Items are loaded in another trigger.

Thanks!

~Berz
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I've seen another very good system, but I can't seem to find it right now...
I've used it in my map "DoomRaiders ORPG", your problem doesn't occur there (I've got a hero and an 'item slave', it the item slave has a sword and the hero has a sword, nothing happens, while if you trade one of the swords, it becomes a 'magical sword').

Since it's open source, you can just pick the system out of my map.
(I don't need to say it to you I guess, but give credits when used :p).

The reason is that you've made it MPI, because of the "player number".
If you could - somehow - make it MUI, it would be solved ^^ (or wait for HashTables...).
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
It can be done MUI, in a very weird way. When sb picks up an item, save it's type a variable, remove it, check if it has more. If it has remove that one too and give the enhanced, else create it again fot him.

A bit blunt, but does the job (I think) .
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This trigger I did tells if a heroe has already an item of the same type he acquires in inventory, or if the other hero has it in his inventory. You can expand from here. Or I can do it, give me a moment :)


  • Untitled Trigger 003 Copy 2
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set isDuplicate = 0
      • Set itemOwner = (Hero manipulating item)
      • Set AcquiredItem = (Item being manipulated)
      • Set itemType = (Item-type of AcquiredItem)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • itemOwner Equal to HeroesArray[0]
        • Then - Actions
          • Set OtherUnitIs = HeroesArray[1]
        • Else - Actions
          • Set OtherUnitIs = HeroesArray[0]
      • For each (Integer loopA) from 1 to 6, do (Actions)
        • Loop - Actions
          • For each (Integer loopB) 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 itemOwner in slot loopA)) Equal to (Item-type of (Item carried by itemOwner in slot loopB))
                  • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                  • loopA Not equal to loopB
                • Then - Actions
                  • Set isDuplicate = 1
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to (Item-type of (Item carried by OtherUnitIs in slot loopB))
                      • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                    • Then - Actions
                      • Set isDuplicate = 1
                    • Else - Actions
                      • Do nothing
      • Floating Text - Create floating text that reads (String(isDuplicate)) at (Position of itemOwner) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
      • Floating Text - Change (Last created floating text): Disable permanence
 
Last edited:
Maker, your system is same as my only that yours checks the whole invertory and my checks for an item. An it would bug, if other units owned by other player would have one of this item :<

And there is a mistake (i think) when you set the isDuplicate for the second time, shouldn't it be Set isDuplicate = 2, else it makes no sense ^^
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
The first IF that sets isDuplicate checks if the acquiring hero has a duplicate in his inventory. The second IF checks whether another hero has the same item in his inventory or not. So that does not bug. The HeroesArray contains the heroes for Player1. I'll try to refine the trigger so it works for all players.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This trigger works for all players, the acquiring hero checks his inventory and the player's other heroes' inventory and notifies if a duplicate exists:

  • DuplicateCheck
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set isDuplicate = 0
      • Set itemOwner = (Hero manipulating item)
      • Set AcquiredItem = (Item being manipulated)
      • Set itemType = (Item-type of AcquiredItem)
      • For each (Integer A) from (((Player number of (Owner of (Hero manipulating item))) - 1) x 3) to (((Player number of (Owner of (Hero manipulating item))) x 3) - 1), do (Actions)
        • Loop - Actions
          • For each (Integer loopA) from 1 to 6, do (Actions)
            • Loop - Actions
              • For each (Integer loopB) 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 itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                      • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                      • loopA Not equal to loopB
                    • Then - Actions
                      • Set isDuplicate = 1
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                          • itemOwner Not equal to HeroesArray[(Integer A)]
                        • Then - Actions
                          • Set isDuplicate = 1
                        • Else - Actions
                          • Do nothing
      • Floating Text - Create floating text that reads (String(isDuplicate)) at (Position of itemOwner) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
      • Floating Text - Change (Last created floating text): Disable permanence
You just neet to create an unit array, and assign P1 Hero #1 to [0], P1 Hero #2 to [1], P1 Hero #3 to [2], P2 Hero #1 to [3] and so on.

I'll try to add remove/add items now.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
There we go. Now it removes the correct items from the hero if he gets a duplicate, or from heroes if hero #X has one and hero #Y has the other.

  • DuplicateReplace
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set isDuplicate = 0
      • Set itemOwner = (Hero manipulating item)
      • Set AcquiredItem = (Item being manipulated)
      • Set itemType = (Item-type of AcquiredItem)
      • For each (Integer A) from (((Player number of (Owner of (Hero manipulating item))) - 1) x 3) to (((Player number of (Owner of (Hero manipulating item))) x 3) - 1), do (Actions)
        • Loop - Actions
          • For each (Integer loopA) from 1 to 6, do (Actions)
            • Loop - Actions
              • For each (Integer loopB) 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 itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                      • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                      • loopA Not equal to loopB
                    • Then - Actions
                      • Set isDuplicate = 1
                      • Item - Remove (Item carried by itemOwner of type itemType)
                      • Item - Remove (Item carried by itemOwner of type itemType)
                      • For each (Integer ItemCreationInt) from 0 to 19, do (Actions)
                        • Loop - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • itemType Equal to ItemsToCombine[ItemCreationInt]
                            • Then - Actions
                              • Hero - Create ItemsToCreate[ItemCreationInt] and give it to (Hero manipulating item)
                            • Else - Actions
                              • Do nothing
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                          • itemOwner Not equal to HeroesArray[(Integer A)]
                        • Then - Actions
                          • Set isDuplicate = 1
                          • Item - Remove (Item carried by itemOwner of type itemType)
                          • Item - Remove (Item carried by HeroesArray[(Integer A)] of type itemType)
                          • For each (Integer ItemCreationInt) from 0 to 19, do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • itemType Equal to ItemsToCombine[ItemCreationInt]
                                • Then - Actions
                                  • Hero - Create ItemsToCreate[ItemCreationInt] and give it to (Hero manipulating item)
                                • Else - Actions
                                  • Do nothing
                        • Else - Actions
                          • Do nothing
      • Floating Text - Create floating text that reads (String(isDuplicate)) at (Position of itemOwner) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
      • Floating Text - Change (Last created floating text): Disable permanence
You also need to create item arrays, ItemsToCombine and ItemsToCreate. Initialize the arrays with your item types, like ItemsToCombine[0] = Ring of Protection +2 and ItemsToCreate[0] = Ring of Protection +3. So two +2 rings get combined to +3 ring.

You can also optimize the loops, there's some unnecessary iterations done when a duplicate is already found. Saves some precious CPU time :)

Hmm...I'll use this in my RPG map :)

Ok, I tidied up the trigger. Added some iteration skipping, remove unnecessary variables and removed a bug that caused items not in the item list to be removed. We don't want that :)

  • Duplicate Replace
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set itemOwner = (Hero manipulating item)
      • Set AcquiredItem = (Item being manipulated)
      • Set itemType = (Item-type of AcquiredItem)
      • For each (Integer A) from (((Player number of (Owner of (Hero manipulating item))) - 1) x 3) to (((Player number of (Owner of (Hero manipulating item))) x 3) - 1), do (Actions)
        • Loop - Actions
          • For each (Integer loopA) from 1 to 6, do (Actions)
            • Loop - Actions
              • For each (Integer loopB) 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 itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                      • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                      • loopA Not equal to loopB
                    • Then - Actions
                      • For each (Integer ItemCreationInt) from 0 to 19, do (Actions)
                        • Loop - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • itemType Equal to ItemsToCombine[ItemCreationInt]
                            • Then - Actions
                              • Item - Remove (Item carried by itemOwner of type itemType)
                              • Item - Remove (Item carried by itemOwner of type itemType)
                              • Hero - Create ItemsToCreate[ItemCreationInt] and give it to (Hero manipulating item)
                              • Skip remaining actions
                            • Else - Actions
                              • Do nothing
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to (Item-type of (Item carried by HeroesArray[(Integer A)] in slot loopB))
                          • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                          • itemOwner Not equal to HeroesArray[(Integer A)]
                        • Then - Actions
                          • For each (Integer ItemCreationInt) from 0 to 19, do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • itemType Equal to ItemsToCombine[ItemCreationInt]
                                • Then - Actions
                                  • Item - Remove (Item carried by itemOwner of type itemType)
                                  • Item - Remove (Item carried by HeroesArray[(Integer A)] of type itemType)
                                  • Hero - Create ItemsToCreate[ItemCreationInt] and give it to (Hero manipulating item)
                                  • Skip remaining actions
                                • Else - Actions
                                  • Do nothing
                        • Else - Actions
                          • Do nothing
 
Wow, snake trigger :p

and actally I figured out, on my map I'll have onlo one hero per player and one stash per player. So I just added a condition "triggering unit is a hero" so stash can't "make" items only hero can :D

Oh, and good luck with your RPG map ^^

Btw, remove Do nothing actions, they do nothing, and since they do nothing it's pointless to have an acton like that. ^^
 
Status
Not open for further replies.
Top