• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

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