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

[Solved] How can i add item to the stocks?

Level 17
Joined
Jun 2, 2009
Messages
1,137
Hello. I am trying to create system like this.
When you click on this building, you can combine 2 leather pieces into 1 leather.
When i do that, i want to add leather as free item to the shop.

Example: You are combining 4 leathers into 2 leather, it will NOT appear to your inventory but to this shop as 2 stocks.
You can ignore the trigger if you understand what i mean.

  • DeriDeriParcasindan
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Deri üret
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Charges remaining in (Item carried by UnitPlayer[(Player number of (Owner of (Triggering unit)))] of type Deri Parçasi)) Greater than or equal to 2
        • Then - Actions
          • Item - Set charges remaining in (Item carried by UnitPlayer[(Player number of (Owner of (Triggering unit)))] of type Deri Parçasi) to ((Charges remaining in (Item carried by UnitPlayer[(Player number of (Owner of (Triggering unit)))] of type Deri Parçasi)) - 2)
          • Hero - Create Deri and give it to (Triggering unit)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Charges remaining in (Item carried by (Triggering unit) of type Canavar Derisi)) Greater than or equal to 1
        • Then - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Canavar Derisi) to ((Charges remaining in (Item carried by (Triggering unit) of type Canavar Derisi)) - 1)
          • Hero - Create Deri and give it to (Triggering unit)
          • Set SatilanDeri = (SatilanDeri + 1)
          • Neutral Building - Add Deri to Dokuma Tezgahi 0236 <gen> with SatilanDeri in stock and a max stock of 999
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
You can use one of the million item systems / tutorials on here that explain how to combine items.

But these systems create the item and give it to the hero. So you need to step in and Remove that item and add it to the Shop instead. Or edit the system to never create the item in the first place.

First you should just learn how to combine items.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
I know how to combine items. You can ignore the trigger.
How to find guide about the add item to market?
Don't you already know how?
Also, there's a million guides on that as well, just search for them. I recommend using google "Hiveworkshop add items to shop".
 
Level 17
Joined
Jun 2, 2009
Messages
1,137
Don't you already know how?
Also, there's a million guides on that as well, just search for them. I recommend using google "Hiveworkshop add items to shop".
Yes it is my request and still it is unsolved. I was gave up and i said solved in there. But still i need it for another project :)
I already searched but none of the guides was talking about 0 stock. This is why i have created topic.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Yes it is my request and still it is unsolved. I was gave up and i said solved in there. But still i need it for another project :)
I already searched but none of the guides was talking about 0 stock. This is why i have created topic.
I answered your question. You can't give an Item a Max Stock of 0. That's like saying the shop doesn't sell any.

So this line doesn't make sense:
  • Neutral Building - Add |cffdda0ddDurability|r to Lich3 0000 <gen> with 0 in stock and a max stock of 0
You need to give your Items a Max Stock of at least 1.


So after reading those we learned that:
1) Our shop needs the Sell Items ability.
2) It cannot have any Techtree - Items Sold inside of the Object Editor. We're going to add/remove these with triggers.

There's also some other annoying problems with these shops where adding/removing items doesn't work as expected.

You can try a system like this to get around it where you manage the Stock yourself and empty/restock the Shops whenever an item is purchased or runs out of stock. This is meant as a proof of concept:
  • Setup Item Stock
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet Item_Hashtable = (Last created hashtable)
      • -------- --------
      • Set VariableSet Item_Types[1] = Claws of Attack +15
      • Set VariableSet Item_Type = Claws of Attack +15
      • Set VariableSet Item_Stock = 1
      • Set VariableSet Item_Max_Stock = 3
      • Custom script: set udg_Item_Id = udg_Item_Type
      • Hashtable - Save Item_Stock as 0 of Item_Id in Item_Hashtable.
      • Hashtable - Save Item_Max_Stock as 1 of Item_Id in Item_Hashtable.
      • Neutral Building - Add Item_Type to Goblin Merchant 0000 <gen> with Item_Stock in stock and a max stock of Item_Max_Stock
      • -------- --------
      • Set VariableSet Item_Types[2] = Kelen's Dagger of Escape
      • Set VariableSet Item_Type = Kelen's Dagger of Escape
      • Set VariableSet Item_Stock = 1
      • Set VariableSet Item_Max_Stock = 1
      • Custom script: set udg_Item_Id = udg_Item_Type
      • Hashtable - Save Item_Stock as 0 of Item_Id in Item_Hashtable.
      • Hashtable - Save Item_Max_Stock as 1 of Item_Id in Item_Hashtable.
      • Neutral Building - Add Item_Type to Goblin Merchant 0000 <gen> with Item_Stock in stock and a max stock of Item_Max_Stock
2 Boots of Speed = 1 Claws of Attack added to the shop:
  • Combine Into Claws Of Attack
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Boots of Speed
    • Actions
      • Set VariableSet Item = (Item being manipulated)
      • Set VariableSet Item_Type = (Item-type of Item)
      • Set VariableSet Item_Unit = (Triggering unit)
      • Set VariableSet Item_Count = 0
      • -------- --------
      • For each (Integer Item_Slot) 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 Item_Unit in slot Item_Slot)) Equal to Item_Type
            • Then - Actions
              • Set VariableSet Item_Count = (Item_Count + 1)
            • Else - Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Count Greater than or equal to 2
        • Then - Actions
          • Item - Remove Item
          • Item - Remove (Item carried by Item_Unit of type Item_Type)
          • -------- --------
          • Set VariableSet Item_Type = Claws of Attack +15
          • Custom script: set udg_Item_Id = udg_Item_Type
          • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
          • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
          • -------- --------
          • -------- Restock shops: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Stock Less than Item_Max_Stock
            • Then - Actions
              • Set VariableSet Item_Stock = (Item_Stock + 1)
              • Hashtable - Save Item_Stock as 0 of Item_Id in Item_Hashtable.
              • Neutral Building - Limit Goblin Merchant 0000 <gen> to 0 item slots
              • Neutral Building - Limit Goblin Merchant 0000 <gen> to 11 item slots
              • For each (Integer Item_Slot) from 1 to 2, do (Actions)
                • Loop - Actions
                  • Set VariableSet Item_Type = Item_Types[Item_Slot]
                  • Custom script: set udg_Item_Id = udg_Item_Type
                  • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
                  • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
                  • Neutral Building - Add Item_Type to Goblin Merchant 0000 <gen> with Item_Stock in stock and a max stock of Item_Max_Stock
            • Else - Actions
        • Else - Actions
2 Gloves of Haste = 1 Kelen's Dagger added to the shop:
  • Combine Into Kelens Dagger
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Gloves of Haste
    • Actions
      • Set VariableSet Item = (Item being manipulated)
      • Set VariableSet Item_Type = (Item-type of Item)
      • Set VariableSet Item_Unit = (Triggering unit)
      • Set VariableSet Item_Count = 0
      • -------- --------
      • For each (Integer Item_Slot) 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 Item_Unit in slot Item_Slot)) Equal to Item_Type
            • Then - Actions
              • Set VariableSet Item_Count = (Item_Count + 1)
            • Else - Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Count Greater than or equal to 2
        • Then - Actions
          • Item - Remove Item
          • Item - Remove (Item carried by Item_Unit of type Item_Type)
          • -------- --------
          • Set VariableSet Item_Type = Kelen's Dagger of Escape
          • Custom script: set udg_Item_Id = udg_Item_Type
          • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
          • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
          • -------- --------
          • -------- Restock shops: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item_Stock Less than Item_Max_Stock
            • Then - Actions
              • Set VariableSet Item_Stock = (Item_Stock + 1)
              • Hashtable - Save Item_Stock as 0 of Item_Id in Item_Hashtable.
              • Neutral Building - Limit Goblin Merchant 0000 <gen> to 0 item slots
              • Neutral Building - Limit Goblin Merchant 0000 <gen> to 11 item slots
              • For each (Integer Item_Slot) from 1 to 2, do (Actions)
                • Loop - Actions
                  • Set VariableSet Item_Type = Item_Types[Item_Slot]
                  • Custom script: set udg_Item_Id = udg_Item_Type
                  • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
                  • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
                  • Neutral Building - Add Item_Type to Goblin Merchant 0000 <gen> with Item_Stock in stock and a max stock of Item_Max_Stock
            • Else - Actions
        • Else - Actions
When the shop sells an item we need to track it's new Stock value and remove and add all of the items back to it:
  • Shop Sells Item
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Triggering unit) Equal to Goblin Merchant 0000 <gen>
    • Actions
      • Set VariableSet Item_Type = (Item-type of (Sold Item))
      • Custom script: set udg_Item_Id = udg_Item_Type
      • -------- --------
      • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
      • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
      • -------- --------
      • -------- Restock shops: --------
      • Neutral Building - Limit Goblin Merchant 0000 <gen> to 0 item slots
      • Neutral Building - Limit Goblin Merchant 0000 <gen> to 11 item slots
      • For each (Integer Item_Slot) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set VariableSet Item_Type = Item_Types[Item_Slot]
          • Custom script: set udg_Item_Id = udg_Item_Type
          • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
          • Set VariableSet Item_Max_Stock = (Load 1 of Item_Id from Item_Hashtable.)
          • Neutral Building - Add Item_Type to Goblin Merchant 0000 <gen> with Item_Stock in stock and a max stock of Item_Max_Stock
      • -------- --------
      • -------- Subtract 1 from stock afterwards (dunno why this needs to happen later): --------
      • Set VariableSet Item_Type = (Item-type of (Sold Item))
      • Custom script: set udg_Item_Id = udg_Item_Type
      • Set VariableSet Item_Stock = (Load 0 of Item_Id from Item_Hashtable.)
      • Set VariableSet Item_Stock = (Item_Stock - 1)
      • Hashtable - Save Item_Stock as 0 of Item_Id in Item_Hashtable.
The weirdness is because Shops are very buggy when it comes to this Adding/Removing stuff.

Also, keep in mind that this doesn't handle Stock Timers, so the Item_Stock value won't increase when the replenish timer finishes.
 

Attachments

  • Item Stock 1.w3m
    22.1 KB · Views: 2
Last edited:
Top