A shop that restocks with random items [SOLVED]

lightwriter
I know how timers work in general but I'm looking specifically for a way o make a timer that will basically restock the shop with a new batch of items whether they are already stocked or not but getting rid of the old ones first. The main issue I'm having is getting rid of the old ones. I basically can get it to add a new random item every x seconds but don't know how to make it so it has no more then, let's say 5 items at 1 time. Any suggestions?
Is there a way to clear all items from a room?
If I can't override the objects in a room, I'd like to at least be able to add a max count where the shop quits refilling once it reaches a certain amount of items.

XanMag
Can you make the object you want to add the items to a player object? If so, you can then set the inventory max limit to 5.

I'm not sure how your timer will work, but after a set time, could you just move the objects to a dead room? You might need to add another name to each object that could end up in the room. Not sure if that would work...

Good luck!

lightwriter
No, that won't work... I want an actual shop... maybe there's way using 'Before Entering the Room' script instead of a timer or kinda like mixing the two...

XanMag
Are the objects on/in a counter in the shop? You can make any object a 'player' object and name it whatever you like. You could use the before entering a room, too. That might be easier. That way, you could manually decide what items and how many you want to move in/out.

lightwriter
I tried using a container with limited inventory but it still just keeps on adding stuff...
I want the items to be random, I'm using Pixie's Shop Library but I don't want everything to be on display all at once.

The Pixie
I would set up another room that holds the stock not yet available, say notstockroom. Then each time you want a random item, this code will move one item picked at random to stockroom:
l = GetDirectChildren(notstockroom)
n = GetRandomInt(0, ListCount(l))
item = ObjectListIem(l, n)
item.parent = stockroom

You could have that trigger each time the player enters the room, every so many turns (my preference), three times after she does something XP worthy, etc.

Marzipan
They want a script to clear the old items out first though, not just add new ones.

XanMag
Can you just set a flag somewhere in Pixie's code that reverses the movement of the random object? Put one in 'stockroom' and one in 'notstockroom'? You could even link it to a percentage chance when leaving the room? Maybe? That would only swap out one object at a time though.

If this were my problem (and I'm glad it is not), I would probably create like 10 identical 'chests' that get swapped in/out of your 'storeroom' every time the player leaves the room (or once a flag was raised). Each chest would have a different combination of items in them. Once an object has been added to the players inventory, I'd move all identical items to a dead room. It's a dumb solution, but the only one I'd be capable of pulling off... lol

Good luck!

The Pixie
Okay, try this:
// remove old stock from the shop
foreach (item, GetDirectChildren(stockroom)) {
item.parent = notstockroom
}

// Add new stock (5 items in this case)
for (i, 1, 5) {
l = GetDirectChildren(notstockroom)
n = GetRandomInt(0, ListCount(l))
item = ObjectListIem(l, n)
item.parent = stockroom
}

lightwriter
Pixie, I'm getting an error: Error running script: Error evaluating expression 'ObjectListItem(l, n)': ObjectListItem: index 0 is out of range for this list (0 items, last index is -1)

Pertex
I think it must be
n = GetRandomInt(0, ListCount(l)-1)

lightwriter
thanks! It works now!

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums