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

Get number of stock in shops

Status
Not open for further replies.
Level 23
Joined
Feb 6, 2014
Messages
2,466
How can I get the number of item stocks in a shop? I tried searching for natives but I can't find one. Any workarounds?
Example, if I have an item with initially a stock of 5 in a market and a player bought 2, there are 3 stocks remaining. Then after a minute, the stock replenishes to 4 stocks. How can I detect those number of stocks at any specific time?
 
You'll have to manage it yourself via triggers.

In an initialization triggers, map the item-types to their initial stocks using a hashtable.

Since you can have multiple shops, you'll want to map particular shops with their current stock value. Since hashtables have a 'parent' and a 'child' key, we can do a simple mapping like so:

Parent Key: Shop; Child Key: Item-type; Value: Current Stock

Create a trigger with a 'sell item' event. Check if the "shop" + "child key" combination exists within the hashtable. If it does, then change its value to its current value - 1 (since the stock is reduced by 1 when an item is sold). If it doesn't exist, save a new entry with the initial stock value - 1.

In that same trigger, start a timer for that item's stock replenish interval (you can save that in the hashtable on initialization as well), and then at the end of the timer, increase the value stored in the hashtable by 1. You'll have to make tests for multiple cases though to see exactly how wc3's stock replenish works. (e.g. buying an item while it is still replenishing)

It is not simple, but it should work. The only annoying part is setting up the initial stock and the replenish time.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
You'll have to manage it yourself via triggers.

In an initialization triggers, map the item-types to their initial stocks using a hashtable.

Since you can have multiple shops, you'll want to map particular shops with their current stock value. Since hashtables have a 'parent' and a 'child' key, we can do a simple mapping like so:

Parent Key: Shop; Child Key: Item-type; Value: Current Stock

Create a trigger with a 'sell item' event. Check if the "shop" + "child key" combination exists within the hashtable. If it does, then change its value to its current value - 1 (since the stock is reduced by 1 when an item is sold). If it doesn't exist, save a new entry with the initial stock value - 1.

In that same trigger, start a timer for that item's stock replenish interval (you can save that in the hashtable on initialization as well), and then at the end of the timer, increase the value stored in the hashtable by 1. You'll have to make tests for multiple cases though to see exactly how wc3's stock replenish works. (e.g. buying an item while it is still replenishing)

It is not simple, but it should work. The only annoying part is setting up the initial stock and the replenish time.

This was actually what I had in mind, but it is not scalable. Oh well I guess that's the only way.

I also thought of another workaround that will make a dummy units continuosly buy the item type from the shop and counting how many items the dummy bought and then re-adding the stock depending on how many were bought. The Time-Complexity although is O(n) and I haven't tested yet if it is even possible to add stock to a shop.
 
Last edited:
Status
Not open for further replies.
Top