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

[Trigger] Array +1 with limit

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
If you want to store 20 Items for more than 1 unit you should use a Hashtable.
A Complete Beginners Guide to Hashtables

The question is, do you want to save the Item Type or the actual Item because these are two different things. Item-Type is saved as an Integer where as Items can be saved using the Item's handle.

For Item-Types you can save them in a Hashtable as Integers like this:

  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet ItemHashtable = (Last created hashtable)
  • Acquire Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set VariableSet Total = (Load 0 of (Key (Triggering unit).) from ItemHashtable.)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Total Less than 20
        • Then - Actions
          • Set VariableSet Total = (Total + 1)
          • Hashtable - Save Total as 0 of (Key (Triggering unit).) in ItemHashtable.
          • Set VariableSet ItemType = (Item-type of (Item being manipulated))
          • Custom script: set udg_Item = udg_ItemType
          • Hashtable - Save Item as Total of (Key (Triggering unit).) in ItemHashtable.
        • Else - Actions
This is just the basic system without any extra functionality. It will store the first 20 Item-Types you acquire in the Hashtable saving them at positions 1 to 20 using the Acquiring Unit as the Key.

An example of getting and creating a Unit's 5th saved Item from the Hashtable:
  • Load Item Type
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet Item = (Load 5 of (Key (Triggering unit).) from ItemHashtable.)
      • Custom script: set udg_ItemType = udg_Item
      • Item - Create ItemType at (Position of (Triggering unit))
 

Attachments

  • Item Hashtable Example.w3m
    17.8 KB · Views: 10
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Do you mean like this?

  • Item Type Array
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Items[1] = Claws of Attack +15
      • Set VariableSet Items[2] = Crown of Kings +5
      • Set VariableSet Items[3] = Kelen's Dagger of Escape
      • Set VariableSet Items[4] = Mask of Death
      • Set VariableSet Items[5] = Orb of Frost
 
Level 26
Joined
Dec 3, 2018
Messages
873
Whenever I buy an item it gets to be a variable. The trigger should look like what Warseeker sent the 1st time, but there are 4 unclear things:

A unit Sells an item (from shop)

Item type of (Sold item) Equal to Item X

If ItemCount Less than or equal to 20

Then Set ItemCount = ItemCount + 1

Else Remove (Sold item)

Where do I find the ''If ItemCount Less than or equal to 20'' condition?
And what Index should the 1st itemcount from ''Then Set ItemCount = ItemCount + 1'' have? and ItemCount is an item type, not an iteger, right?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
ItemCount is an Integer.

When you go into the conditions and click Integer Comparison, you'll see a bubble at the top that says Variable. Select that and choose ItemCount from the list of Integer variables.

Then hit OK and you'll be able to edit the rest.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ItemCount Less than 20
    • Actions
      • Set VariableSet ItemCount = (ItemCount + 1)
      • Set VariableSet ItemType[ItemCount] = (Item-type of (Item being manipulated))
OR

  • Untitled Trigger 001
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • ItemCount Less than 20
    • Actions
      • Set VariableSet ItemCount = (ItemCount + 1)
      • Set VariableSet ItemType[ItemCount] = (Item-type of (Sold Item))
ItemCount = Integer
ItemType = Item-Type (Array)
 
Last edited:
Status
Not open for further replies.
Top