How to Change Shop Inventory Based on Past Purchases?

Tsaffrogua

Villager
Member
Joined
Sep 9, 2022
Messages
6
Reaction score
5
First Language
English
Primarily Uses
RMMZ
What I want: To update the inventory of a shop based on past purchases/items in inventory.

What I have: I have a shop which sells a set of items that have improved sequels. Blessing 1 -> Blessing 2 -> Blessing 3

1676090598494.png

What I need: A way to make the inventory change as items are acquired.
Eg. When player has Blessing of Death 1, add Blessing of Death 2 to shop & remove Blessing of Death 1 from shop.

I can obviously set an event to check for the player having items, but I don't know how to make the inventory change as a result. As far as I can tell it will need a script, but I can't find any examples of someone trying this before.

Can anyone help me figure this out?

P.S. I could have the item trigger a whole new shop processing event, but with 16 items the player can purchase in any order that event would quickly become a hundreds of pages long hydra.)
 

Andar

Regular
Regular
Joined
Mar 5, 2013
Messages
39,933
Reaction score
11,878
First Language
German
Primarily Uses
RMMV
you'll need a plugin then, one that implements advanced control and stoc limits on the shop.

without a plugin the only way would have been what you mentioned, different shop processing.
 

rpgLord69

Regular
Regular
Joined
Oct 23, 2021
Messages
688
Reaction score
906
First Language
Finnish
Primarily Uses
RMMZ
Can't you just create one shop processing event (with the script event command) that has game variables in the array for those special items and then before the event put single line conditional checks that check if the party has one of those special items and then changes the variables used in the shop array as a result?

EDIT:
A pic just to show an example (in here the variable 20 was set to 7 in the beginning)

shop_process.JPG
 
Last edited:

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,244
Reaction score
1,932
First Language
English
Primarily Uses
RMMZ
This doesn't require a plugin. A script command such as this one should work:

JavaScript:
/* Change these values to represent the Item IDs of each blessing */
const blessings = [
    [id1, id2, id3],  // Blessing of Death
    [id1, id2, id3],  // Blessing of Field
    [id1, id2, id3],  // Blessing of Forest
    [id1, id2, id3],  // Blessing of Sea
    [id1, id2, id3],  // Blessing of Storm
    [id1, id2, id3],  // Blessing of Sun
    [id1, id2, id3],  // Blessing of Trickery
    [id1, id2, id3]   // Blessing of War
];

const goods = [];

blessings.forEach(blessing => {
    for (const id of blessing) {
        if (!$gameParty.hasItem($dataItems[id])) {
            goods.push([0, id, 0]);
            break;
        }
    }
});

if (goods.length > 0) {
    SceneManager.push(Scene_Shop);
    SceneManager.prepareNextScene(goods, true);
} else {
    $gameMessage.setFaceImage('Actor3', 3);
    $gameMessage.setBackground(0);
    $gameMessage.setPositionType(2);
    $gameMessage.setSpeakerName('Ninshubur');
    $gameMessage.add('You have already received all of the Goddess\' blessings!');
    this.setWaitMode('message');
}

You just have to edit the blessings array to contain the actual item IDs of each level of blessing. So for example if the item id of Blessing of Death I is 21, and the id of BoD II is 22, and the id of BoD III is 23, then you'd change this line:
JavaScript:
[id1, id2, id3],  // Blessing of Death
to this:
JavaScript:
[21, 22, 23],  // Blessing of Death

*Edited to account for the possibility that the player has already purchased all blessings.
 
Last edited:

Tsaffrogua

Villager
Member
Joined
Sep 9, 2022
Messages
6
Reaction score
5
First Language
English
Primarily Uses
RMMZ
I'm attempting Arthran's method but I've done something wrong.
I keep getting a syntax error for various different brackets.

The version below returns Syntax Error: Unexpected Token ')'
Here's the id list and my attempt at the script, I've pared it back to just one blessing for now until the error is solved.

1676157218778.png

JavaScript:
const blessings = [  
    [id34, id17, id18]   // Blessing of Moon
];

const goods = [];

blessings.forEach(blessing => {
    for (34) {
        if (!$gameParty.hasItem($dataItems[34])) {
            goods.push([0, 17, 0]);
            break;
blessings.forEach(blessing => {
    for (17) {
        if (!$gameParty.hasItem($dataItems[17])) {
            goods.push([0, 18, 0]);
        }
    }
});

SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(goods, true);
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,244
Reaction score
1,932
First Language
English
Primarily Uses
RMMZ
I'm attempting Arthran's method but I've done something wrong.
I keep getting a syntax error for various different brackets.

The version below returns Syntax Error: Unexpected Token ')'
Here's the id list and my attempt at the script, I've pared it back to just one blessing for now until the error is solved.


JavaScript:
const blessings = [
    [id34, id17, id18]   // Blessing of Moon
];

const goods = [];

blessings.forEach(blessing => {
    for (34) {
        if (!$gameParty.hasItem($dataItems[34])) {
            goods.push([0, 17, 0]);
            break;
blessings.forEach(blessing => {
    for (17) {
        if (!$gameParty.hasItem($dataItems[17])) {
            goods.push([0, 18, 0]);
        }
    }
});

SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(goods, true);
You edited a part that you're not supposed to edit, and you didn't edit the part that you were supposed to edit. The only part you should edit is the very top part. Based on the screenshot of your database, your script should look something like this:

JavaScript:
const blessings = [
    [8, 9, 10],  // Blessing of Death
    [11, 12, 13],  // Blessing of Field
    [14, 15, 16],  // Blessing of Forest
    [19, 20, 21],  // Blessing of Sea
    [22, 23, 24],  // Blessing of Storm
    [25, 26, 27],  // Blessing of Sun
    [28, 29, 30],  // Blessing of Trickery
    [31, 32, 33],  // Blessing of War
    [34, 17, 18]   // Blessing of Moon
];

const goods = [];

blessings.forEach(blessing => {
    for (const id of blessing) {
        if (!$gameParty.hasItem($dataItems[id])) {
            goods.push([0, id, 0]);
            break;
        }
    }
});

if (goods.length > 0) {
    SceneManager.push(Scene_Shop);
    SceneManager.prepareNextScene(goods, true);
} else {
    $gameMessage.setFaceImage('Actor3', 3);
    $gameMessage.setBackground(0);
    $gameMessage.setPositionType(2);
    $gameMessage.setSpeakerName('Ninshubur');
    $gameMessage.add('You have already received all of the Goddess\' blessings!');
    this.setWaitMode('message');
}
 

Tsaffrogua

Villager
Member
Joined
Sep 9, 2022
Messages
6
Reaction score
5
First Language
English
Primarily Uses
RMMZ
Ah, I see it now, I never removed the id placeholder.

Thank you for your help, everything is working now.
 

Latest Threads

Latest Posts

Latest Profile Posts

THE GAME AWARDS AHHHHHH!!!!!
I kept saying I suck at writing stories. But I can't believe I wrote one these days. Feels good now that the winged blonde girl I often share has an actual lore and plot going.
Huge breakthrough! I finally fixed the dimensions on the WEBM used in the cinematic that ends the demo and introductory segment in MC:RIS, around the one-minute mark:



(There's some audio desync because the capture is an MP4.)
Kudos to everyone making game jam games, because this month has been hell for my development time. I have made a cutscene, 2 sprites, and 1 tile.

I guess I've made conceptual progress in hammering out combat roles and having fixes to be implemented (though I haven't done that yet)
Yeah, it’s a status #3, but it’s just to let y’all know I think I’m gonna have to do a twofer on the Advent compilation tomorrow. I feel like butt. Have a fever. I want to descend into my crypt.

Forum statistics

Threads
136,819
Messages
1,270,404
Members
180,583
Latest member
Shrimpkobe
Top