tomexplodes

Veteran
Veteran
Joined
Oct 15, 2012
Messages
32
Reaction score
6
First Language
English
Primarily Uses
I've turned Luck into a Charisma stat, just wondering if there's a script or plugin to change the prices in a shop based on a stat. I can make a million different shop events based on setting it to and calling it a variable, but if there's an easier way, that would be great. Also, being able to set what the sell prices are would help. Thanks!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,869
Reaction score
14,989
First Language
English
Primarily Uses
RMMV

I've moved this thread to Plugin Requests. Thank you.

 

Solovei

Has approximate knowledge of many things
Veteran
Joined
Apr 28, 2021
Messages
37
Reaction score
47
First Language
English
Primarily Uses
RMMV
I hope it's okay to add that I've also been looking for something like this! Except I wanted to set it up so that having a certain person in your party gives you a discount on shop items. But still, similar idea!
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
If you're handy with JS at all, in the rpg_scenes.js, there are these two functions:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price(this._item);
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor(this._item.price / 2);
};

You could write a tiny plugin (or edit the code directly) that modifies the value it puts out. If it's luck stat, you could set up a common event that you would call before each shop event, in it you could grab the actor's luck parameter and do whatever to get your price modification, and stick it in a variable, say variable 1. So then in the plugin, you'd write something like:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price(this._item) * $gameVariables.value(1);
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * $gameVariables.value(1)) / 2);
};

It's slightly complicated but involves the least code, I try not to assume anyone's skill. This would affect ALL items in ALL shops this way, unless you set an item's price to something other than standard when setting up the shop scene. You'd replace the .value(1) with whatever variable number you choose to use for it.

Other conditions are possible too, depending on what you're wanting, just know that anything written in those two functions will affect all items equally if their prices are set as standard when setting up the shop. The sky's the limit, really.
 

tomexplodes

Veteran
Veteran
Joined
Oct 15, 2012
Messages
32
Reaction score
6
First Language
English
Primarily Uses
If you're handy with JS at all, in the rpg_scenes.js, there are these two functions:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price(this._item);
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor(this._item.price / 2);
};

You could write a tiny plugin (or edit the code directly) that modifies the value it puts out. If it's luck stat, you could set up a common event that you would call before each shop event, in it you could grab the actor's luck parameter and do whatever to get your price modification, and stick it in a variable, say variable 1. So then in the plugin, you'd write something like:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price(this._item) * $gameVariables.value(1);
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * $gameVariables.value(1)) / 2);
};

It's slightly complicated but involves the least code, I try not to assume anyone's skill. This would affect ALL items in ALL shops this way, unless you set an item's price to something other than standard when setting up the shop scene. You'd replace the .value(1) with whatever variable number you choose to use for it.

Other conditions are possible too, depending on what you're wanting, just know that anything written in those two functions will affect all items equally if their prices are set as standard when setting up the shop. The sky's the limit, really.
Just to make sure I understand correctly, in

JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price(this._item) * $gameVariables.value(1);
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * $gameVariables.value(1)) / 2);
};

all items will be affected by whatever variable I set that too, and then the math is the bottom one for how I want to affect prices by it? For example, say I want the price reduced by .5 percent per point of Charisma, would it be... crap I can't math.

return Math.floor((this._item.price * $gameVariables.value(1)) * 0.85

Is this right?

EDIT or is it.... return Math.floor((this._item.price * 1 - $gameVariables.value(1)) / 200);

EDIT AGAIN Okay this is what I attempted
Code:
Scene_Shop.prototype.buyingPrice = function() {
    return this._buyWindow.price((this._item.price * (1 - ($gameVariables.value(6) / 200));
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * (1 - ($gameVariables.value(6) / 200));
};

Are decimals possible, or are we only dealing in integers? Alternatively, did I do it wrong? I have no javascript experience. 6 being the variable I set to your Charisma score before running the shop.
My father, who knows math and how to program, tells me it should basically be set to : (1 - (charisma/200)). Does THAT make sense?
Also ignore the selling price one, I realize after the fact that those two were buying/selling, that can be fixed once I figure out how to even do it.
 
Last edited:

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
Well, in the example I gave, it multiplies the price by whatever you set in the variable. So in the common event before each shop call, that's where you'd set the value IN that variable. In this case you'd store the character's charisma(luck) to that variable. Then, if you want a half-percent drop per luck point, you'd set that variable to its own value multiplied by .05, then set it to 1 - its own value.

So if you had LUK of 3, it would go like this:
Set variable 6 to character's LUK (3).
Set variable 6 to multiply the value of variable 6 by .05 (3 * 0.05 = 0.015, which is 1 1/2 percent).
Set variable 6 to 1 minus the value of variable 6 (1 - 0.015 = 0.985, or 98 1/2 percent of normal price).
Then when the shop is opened immediately after, it should take all prices and set them to 99% of the value defined in the database, since the function rounds the result, in this case up(see below).

Yeah, I forgot about decimals. It CAN be done, but it's not MEANT to if your game isn't designed to handle non-rounded values in your currency. So for the buyingPrice function, it should be this instead:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * $gameVariables.value(6));
};

I'm not sure where the "/200" came from... but I see how the rest came about. The variable controls above should account for that, so that when the shop is called, the final value of the variable after the common event right before it should equal the discount percentage.

If I get some time today (going in to work soon) I can whip something up for ya so that you don't need the common event. Shouldn't take too long, and I can post it when I get home tonight. I'd need to know how to find the right character's luck stat to use. Do you only have one character? Or do you want the highest luck in the party? Or is it the sum or average of EVERYONE in the party?
 

tomexplodes

Veteran
Veteran
Joined
Oct 15, 2012
Messages
32
Reaction score
6
First Language
English
Primarily Uses
Well, in the example I gave, it multiplies the price by whatever you set in the variable. So in the common event before each shop call, that's where you'd set the value IN that variable. In this case you'd store the character's charisma(luck) to that variable. Then, if you want a half-percent drop per luck point, you'd set that variable to its own value multiplied by .05, then set it to 1 - its own value.

So if you had LUK of 3, it would go like this:
Set variable 6 to character's LUK (3).
Set variable 6 to multiply the value of variable 6 by .05 (3 * 0.05 = 0.015, which is 1 1/2 percent).
Set variable 6 to 1 minus the value of variable 6 (1 - 0.015 = 0.985, or 98 1/2 percent of normal price).
Then when the shop is opened immediately after, it should take all prices and set them to 99% of the value defined in the database, since the function rounds the result, in this case up(see below).

Yeah, I forgot about decimals. It CAN be done, but it's not MEANT to if your game isn't designed to handle non-rounded values in your currency. So for the buyingPrice function, it should be this instead:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * $gameVariables.value(6));
};

I'm not sure where the "/200" came from... but I see how the rest came about. The variable controls above should account for that, so that when the shop is called, the final value of the variable after the common event right before it should equal the discount percentage.

If I get some time today (going in to work soon) I can whip something up for ya so that you don't need the common event. Shouldn't take too long, and I can post it when I get home tonight. I'd need to know how to find the right character's luck stat to use. Do you only have one character? Or do you want the highest luck in the party? Or is it the sum or average of EVERYONE in the party?

That would be awesome. Yeah, before each shop event, I set the variable number 6 to my luck(charisma) stat in the event window, no big deal. And there's only one character/class in the game. I figure if I want to change individual shop prices, I just multiply it to decrease the price etc. So anyway, yes. I would love it if you want to make this work for me, I'll keep pawing at it in the meantime.

EDIT Got it!

Code:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * (1 - $gameVariables.value(6)/200));
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.round((this._item.price) * (1 + $gameVariables.value(6)/200)/2);
};
does exactly what I want
 
Last edited:

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
That would be awesome. Yeah, before each shop event, I set the variable number 6 to my luck(charisma) stat in the event window, no big deal. And there's only one character/class in the game. I figure if I want to change individual shop prices, I just multiply it to decrease the price etc. So anyway, yes. I would love it if you want to make this work for me, I'll keep pawing at it in the meantime.

EDIT Got it!

Code:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * (1 - $gameVariables.value(6)/200));
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.round((this._item.price) * (1 + $gameVariables.value(6)/200)/2);
};
does exactly what I want
Glad you got it! And now you can say you have some javascript experience. :p

This is what I'd come up with, though I haven't been able to test it yet:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * this.priceMod());
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * this.priceMod()) / 2);
};

Scene_Shop.prototype.priceMod = function() {
    var min = 0.01 //sets minimum price to 1% of database price.
    var mod = 1 - ($gameActors.actor(1).luk * 0.05)
    return mod.clamp(min, mod);
}

This would also allow for a minimum price reduction in case you want to cap the discount no matter how much charisma your character gains. You could change the value of min to whatever percent you wanted. I just set it to 1% to avoid the player getting free items or worse, getting money for buying stuff.
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
Oh, and NOW I see what you'd been doing wrong with your first attempts. You had double parentheses where there shouldn't have been any. The "this._buyWindow.price()" part is a function, and the "this._item" was an argument given to the function. In this case, it gets the price of that item, from the database if set to standard pricing, otherwise it grabs whatever special price you set. But since you had it as "this._buyWindow.price((this._item.price * (1 - ($gameVariables.value(6) / 200))" in one of your attempts, it had really no CLUE what to do with what you were giving it, since you were trying to put a formula in the function where it wanted the item.

Javascript can be a little tricky if you're not familiar with programming... ESPECIALLY if you're not using something like Notepad++ or VisualStudio Code to write it with. Mistakes are SUPER easy to make and can be pretty tricky to track down if you're not familiar with the language.
 

tomexplodes

Veteran
Veteran
Joined
Oct 15, 2012
Messages
32
Reaction score
6
First Language
English
Primarily Uses
Glad you got it! And now you can say you have some javascript experience. :p

This is what I'd come up with, though I haven't been able to test it yet:
JavaScript:
Scene_Shop.prototype.buyingPrice = function() {
    return Math.round(this._buyWindow.price(this._item) * this.priceMod());
};

Scene_Shop.prototype.sellingPrice = function() {
    return Math.floor((this._item.price * this.priceMod()) / 2);
};

Scene_Shop.prototype.priceMod = function() {
    var min = 0.01 //sets minimum price to 1% of database price.
    var mod = 1 - ($gameActors.actor(1).luk * 0.05)
    return mod.clamp(min, mod);
}

This would also allow for a minimum price reduction in case you want to cap the discount no matter how much charisma your character gains. You could change the value of min to whatever percent you wanted. I just set it to 1% to avoid the player getting free items or worse, getting money for buying stuff.
This is MUCH more elegant than my junk! I will try it out and see if it works for me. Thanks so much for all your assistance! I will slowly add a little bit of JS every day until I actually kinda know it. That's the thing, I understand HOW programming works, I just never learned any languages. I've used so many visual scripting programs in the past that I get how the flow works and if/and/else statements and the basics like that, like I say, just no actual languages. Thanks again!

EDIT: Also, the minimum isn't technically NECESSARY for my purposes, your charisma will never go higher than 100, so you'll never get more than a 50% discount, but I like having it there as a failsafe regardless. Might also make it more useful to other people, especially since you can just alter this.priceMod to equal another stat or a variable or whatever you want, really.

EDIT AGAIN: I feel like you should publish this as a plugin, haha.

EDIT ONE MORE TIME: I felt I should explain my weird math. Basically, in calculations of things with the actual EVENT SYSTEM that can't handle having decimal points, doing 1-Charisma / 200 is getting you .05 percent. I'm used to programming with events, that's why I use weird math like that.

and another EDIT yeah I'm not sure where it went wrong, but I'm having stuff cost 0 gold with your edits.
 
Last edited:

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
This is MUCH more elegant than my junk! I will try it out and see if it works for me. Thanks so much for all your assistance! I will slowly add a little bit of JS every day until I actually kinda know it. That's the thing, I understand HOW programming works, I just never learned any languages. I've used so many visual scripting programs in the past that I get how the flow works and if/and/else statements and the basics like that, like I say, just no actual languages. Thanks again!

EDIT: Also, the minimum isn't technically NECESSARY for my purposes, your charisma will never go higher than 100, so you'll never get more than a 50% discount, but I like having it there as a failsafe regardless. Might also make it more useful to other people, especially since you can just alter this.priceMod to equal another stat or a variable or whatever you want, really.

EDIT AGAIN: I feel like you should publish this as a plugin, haha.

EDIT ONE MORE TIME: I felt I should explain my weird math. Basically, in calculations of things with the actual EVENT SYSTEM that can't handle having decimal points, doing 1-Charisma / 200 is getting you .05 percent. I'm used to programming with events, that's why I use weird math like that.

and another EDIT yeah I'm not sure where it went wrong, but I'm having stuff cost 0 gold with your edits.
I think I see the problem. The priceMod function is adjusting by 0.05, it should be 0.005. The current form means you're hitting 100% discount at 20 charisma. That's my bad. Just change the number in that line and it should be good. I had it right in my head, but my keyboard sometimes doesn't cooperate when typing 0s, and I didn't double-check.

I'm sort of in the same boat. I understand programming in general. Enough to look at most languages and figure out in broad strokes what they're doing. But I'm still learning JS. I have another language under my belt, but in this case that's a hindrance because they do things COMPLETELY differently. A lot of my mistakes are usually because I tried to do something the "old" way, and JS doesn't do it that way.

As for the minimum, I try not to assume what someone's going to want, so I put it in there just in case. Also good for accounting for buffs and such, if you're going to have any that boost charisma.

I thought about a more modular version, so anyone could set it up however they like. But that would take a bit of time and I'm busy on a huge project. While I can take short breaks for something small like this, I can't really justify getting distracted on something... bigger. For now, though, if anyone knows enough JS and enough of getting the stuff they want via script, they can modify the function to suit their needs. I'll try to remember to come back to this later and make a full-fledged plugin out of it that can be customized in the plugin manager.
 

Solovei

Has approximate knowledge of many things
Veteran
Joined
Apr 28, 2021
Messages
37
Reaction score
47
First Language
English
Primarily Uses
RMMV
Agreed, I would love this as a plugin! It could be more general too, like.... change shop prices based on an item or switch or something? Or a variable....
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
156
First Language
English
Primarily Uses
RMMZ
Agreed, I would love this as a plugin! It could be more general too, like.... change shop prices based on an item or switch or something? Or a variable....
It's certainly possible. With any JS experience, priceMod() can be modified to suit your needs. Variables and switches are the most common things people learn how to script it seems. The final plugin would even allow for custom script to be used.

The only thing to remember, if anyone wants to modify priceMod, is that the buy and sell prices are multiplied by the value given by priceMod. So it would be a percentage in decimal form. Anything over 1.00 makes the prices higher, and vice versa.
 

Latest Threads

Latest Posts

Latest Profile Posts

Checking out the Judge's Round Table. Really cool getting their perspective in a Q/A environment like this.
I'm heading back to Orlando tomorrow! Dad said he's going to take me to my favorite arcade and maybe Aquatica.
animated message windows <3
or message window that uses background images that can be animated?
Still need to fix some things, but it's going great so far :)
CEPjLJn.gif
just when I thought one of the greatest game of all time couldn't get any better, they announce a new dlc for it.
For anyone interested: there's another huge humble bundle with JRPG assets + a game jam starting next month - it's for a good cause, so check it out <3

Forum statistics

Threads
113,786
Messages
1,077,450
Members
147,821
Latest member
Zabasin
Top