Jump to content
McKay Development

Creating Current Stock and Stock Limit


Recommended Posts

How and where are your prices/items that you are buying or selling stored?

If there in a JSON file, I would add a `maxStock` and `currentStock` in the file, so it would look something like this:

"Team Captain": {
	"buy": ...
	"maxStock": 3,
	"currentStock" 1

Then, in your process function:

let amountInTrade = {}

for (var i = 0; i < theirItemsNames.length; i++) {
	amountInTrade[theirItemsNames[i]].amount = (amountInTrade[theirItemsNames[i]] ? amountInTrade[theirItemsNames[i]] + 1 : 1)

if (prices[itemName].currentStock + amountInTrade[itemName] <= prices[itemName].maxStock) { // if the amount they are giving plus how much we have is smaller than or equal to maxStock
	// accept the offer
} else {
	// decline 


Edited by vrtgn
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...