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

[Spell] Item Upgrade type (I need help for triggers)

Status
Not open for further replies.
Level 4
Joined
Aug 15, 2010
Messages
53
Hi,
First I apologize for my bad english.
I'm using google translate. I try to make upgrade system for items.

I try to use this triggers but I get an error message when I get every Gauntlet Upgrade Item from the vendor.

Code:
Upgrade System
    Events
        Unit - A unit Sells an item (from shop)
    Conditions
    Actions
        -------- ----------------------------------------------------------------------------------------------------------- --------
        -------- Gauntlet (Upgrade) --------------------------------------------------- --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Item-type of (Sold Item)) Equal to Gauntlet Upgrade Item
                ((Item carried by (Buying unit) of type Gauntlets) is owned) Equal to True
            Then - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        And - All (Conditions) are true
                            Conditions
                                ((Item carried by (Buying unit) of type Gauntlets) is owned) Equal to True
                    Then - Actions
                        Special Effect - Create a special effect attached to the origin of (Buying unit) using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
                        Item - Remove (Item carried by (Buying unit) of type Gauntlets)
                        Hero - Create Gauntlets +1 and give it to (Buying unit)
                        Game - Display to (Player group((Owner of (Buying unit)))) the text: |c0000ff00Items upg...
                    Else - Actions
            Else - Actions
        -------- Gauntlet +1 (Upgrade) --------------------------------------------------- --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Item-type of (Sold Item)) Equal to Gauntlet Upgrade Item
                ((Item carried by (Buying unit) of type Gauntlets +1) is owned) Equal to True
            Then - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        And - All (Conditions) are true
                            Conditions
                                ((Item carried by (Buying unit) of type Gauntlets +1) is owned) Equal to True
                                ((Owner of (Buying unit)) Current gold) Greater than or equal to 500
                                SkorSayaci[(Player number of (Owner of (Buying unit)))] Greater than or equal to 125
                    Then - Actions
                        Special Effect - Create a special effect attached to the origin of (Buying unit) using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
                        Item - Remove (Item carried by (Buying unit) of type Gauntlets +1)
                        Player - Add -500 to (Owner of (Buying unit)) Current gold
                        Set SkorSayaci[(Player number of (Owner of (Buying unit)))] = (SkorSayaci[(Player number of (Owner of (Buying unit)))] - 125)
                        Hero - Create Gauntlets +2 and give it to (Buying unit)
                        Game - Display to (Player group((Owner of (Buying unit)))) the text: |c0000ff00Items upg...

[Error Message Settings]====================

                    Else - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-type of (Sold Item)) Equal to Gauntlet Upgrade Item
                                ((Item carried by (Buying unit) of type Gauntlets +1) is owned) Equal to True
                            Then - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Or - Any (Conditions) are true
                                            Conditions
                                                ((Owner of (Buying unit)) Current gold) Less than 500
                                                SkorSayaci[(Player number of (Owner of (Buying unit)))] Less than 125
                                    Then - Actions
                                        Special Effect - Create a special effect attached to the overhead of (Buying unit) using Abilities\Spells\Orc\FeralSpirit\feralspiritdone.mdl
                                        Game - Display to (Player group((Owner of (Buying unit)))) the text: |c008080ffYour supp...
                                    Else - Actions
                            Else - Actions
            Else - Actions
        -------- ----------------------------------------------------------------------------------------------------------- --------
        -------- New Item 01 (Upgrade) --------------------------------------------------- --------
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
Could you use the [trigger]--your code here--[/trigger] instead of [code]--your code not here--[/code]? It becomes easier to read it, and we can help you faster...

Now, there's something related to the conditions that you are doing wrong. For example:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (some other condition)
      • ((Item carried by (Buying unit) of type Gauntlets +1) is owned) Equal to True <== THIS
    • Then - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • ((Item carried by (Buying unit) of type Gauntlets +1) is owned) Equal to True <== AND THIS
It looks like you are trying to check if a unit owns 2 of the same item type (Recently, I have helped someone about this same topic). Then trying to remove them and add a new one in their place. Well, both conditions are currently returning true for the same item. That means... even if you have ONLY one item of that type, it would return true for both conditions. Unfortunately, Blizzard have not made a function that counts the amount of item-type a unit owns. You have to make one yourself. It is possible to make one in GUI triggers, though it is a pain (at least for me) to set a lot of variables and check a trigger, then try to do whatever you want with a item type.

Example: I will show an easy and fast way to create such function (in GUI).

Explanation:
  • Variables:
    • CIT_Unit: This is the unit/hero which will have its inventory scanned;
    • CIT_ItemType: This is the item you are looking for in a unit inventory;
    • CIT_ItemAmount: Counts the amount of items you are looking for that are being carried by CIT_Unit;
    • CIT_MatchingItems: It is a helper variable, which its purpose is to be used for referencing found items - I'll show you an example later
    • CIT_Loop: This is used by a loop in order to check every inventory slot. You won't even touch it.
Main trigger:
  • Count ItemType
    • Events
    • Conditions
      • (Size of inventory for CIT_Unit) Greater than 0
    • Actions
      • Set CIT_ItemAmount = 0
      • For each (Integer CIT_Loop) from 1 to (Size of inventory for CIT_Unit), do (Actions)
        • Loop - Actions
          • -------- Nulling previous matching items --------
          • Set CIT_MatchingItems[CIT_Loop] = No item
          • -------- Check if current item in inventory slot matches the chosen item-type - CIT_ItemType --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by CIT_Unit in slot CIT_Loop)) Equal to CIT_ItemType
            • Then - Actions
              • -------- It matches; it's an item that we are looking for. Count it, and assign that item to the helper variable so that we may reference it later --------
              • Set CIT_ItemAmount = (CIT_ItemAmount + 1)
              • -------- That's a helper variable which is used for future actions, such as deleting this item later, or doing whatever you wish. --------
              • Set CIT_MatchingItems[CIT_ItemAmount] = (Item carried by CIT_Unit in slot CIT_Loop)
            • Else - Actions
Before using the main trigger, you need to set some variables, then run it.
  • Set CIT_Unit = AnyUnit
  • Set CIT_ItemType = Item
  • Trigger - Run Count ItemType <gen> (checking conditions)
Afterwards, the main trigger will assign some values to a few variables. Since I described what each variable does, it should be easy from now on.

Demonstration:
  • Combine same Items
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set CIT_Unit = (Triggering unit)
      • -------- -------- --------
      • -------- Combine 2x Frostguard into Searing Blade --------
      • -------- -------- --------
      • Set CIT_ItemType = Frostguard
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to CIT_ItemType
        • Then - Actions
          • Trigger - Run Count ItemType <gen> (checking conditions)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CIT_ItemAmount Greater than or equal to 2
            • Then - Actions
              • -------- Remember the helper variable? The CIT_MatchingItems[]? --------
              • -------- I want to remove those 2 items from the hero, and add a new. I now have access to those items with no need to use more functions to get item slot --------
              • Item - Remove CIT_MatchingItems[1]
              • Item - Remove CIT_MatchingItems[2]
              • -------- Do your stuff --------
              • Hero - Create Searing Blade and give it to CIT_Unit
              • Special Effect - Create a special effect attached to the origin of CIT_Unit using Abilities\Spells\Items\AIem\AIemTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
        • Else - Actions
      • -------- -------- --------
      • -------- Combine 2x Claws of Attack +6 into a +12 one. --------
      • -------- -------- --------
      • Set CIT_ItemType = Claws of Attack +6
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to CIT_ItemType
        • Then - Actions
          • Trigger - Run Count ItemType <gen> (checking conditions)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CIT_ItemAmount Greater than or equal to 2
            • Then - Actions
              • -------- Remember the helper variable? The CIT_MatchingItems[]? --------
              • -------- I want to remove those 2 items from the hero, and add a new. I now have access to those items with no need to use more functions to get item slot --------
              • Item - Remove CIT_MatchingItems[1]
              • Item - Remove CIT_MatchingItems[2]
              • -------- Do your stuff --------
              • Hero - Create Claws of Attack +12 and give it to CIT_Unit
              • Special Effect - Create a special effect attached to the origin of CIT_Unit using Abilities\Spells\Items\AIem\AIemTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
        • Else - Actions
As for the JASS version, it is already explained in that mentioned thread.

Try to change your code a little bit by implementing this into it, and let us know what happens.
 

Attachments

  • GUI_CountItemType.w3x
    18.7 KB · Views: 39
Last edited:
Level 4
Joined
Aug 15, 2010
Messages
53
First of all, I found out where my mistake is. I fully understand what you told me. When you are two or more of the same item, you told them to combine them. As you do, the system checks every item in the inventory one by one. Then combine it.
In my system, certain items are being changed when the power up item is purchased from the dealer. But the problem is, When Gauntlet +0 is upgraded, it gives Gauntlet + 1. And the other code in the line of Trigger is controlling with the Gauntlet +1 on the character. So in my system the problem arises because of the trigger sequence. (Again, I apologize for my bad english. I'm using google translate.)

And I try to
  • xxx
code.
bkz:
 
Status
Not open for further replies.
Top