Percentaje x of a variable range?

Hello. Thanks and apologies in advance for requiring your time to help me.
As my first language is Spanish I will try to explain myself as best I can, to avoid misunderstandings, so please forgive any language errors you may find. 😢
The problem is very mathematical, and I am wondering if it will be possible to do it in javascript to check in conditional branch.
For example, let's say an item "x" has a standard value of 100.
I would like to calculate the range of that variable in 10%, for example or x%.
That is, check if the range is between values of "90-110". I don't know if I'm explaining myself well.
If the percentage is 20%, range 80-120... and so on. Both positive and negative. Calculate it.
That percentage can be modified in the game, so it would also be stored in a variable.
Something like...
A= $gameVariable(1) [original or standard price of the selected item, Database]
B= $gameVariable(2) [Price selected input by the item selected]
C= $gameVariable(2) [percentage +- of A [10, 25... 50...%]
D= $gameVariable(3) [ID of the item selected to show in the counter]

How would you know if the selected custom price (A) for item(D) is not more than x% (C) (both negative and positive) than the original price (A)? True or false result check is ok.
True if the input is inside that values. False if not.
Please, someone can help me?
I kinda get what you're trying to do, but rather than explaining it mechanically can you tell me what this is actually *for*? I'll be able to give you a more accurate answer if I know what sort of gameplay element it's intended to accomplish.
Hi, @Trihan! Thank you for answer! I will try to explain in more detail!
I want to sell items in counter (table) map in my game. So, the player walk in front of a event or tile, and interact with it, letting put a "x" item in inventory [with "Select Item Command"], that will store ID of selected item in a variable [D] refered before. Then, ask to input a number for quantitie and custom price, that I will store in a self variable, same as D. That will be B variable.
Ok. Everything is ok until here. But, in my game it is a talent, that for example I will call it "Economy". The difference between sold or not be sold it will be determined by the level of this variable.
If I select a potion, and his value in database is 100...
If the custom price that I inputted is more (because less of course will be buyed, but I want to know how to check less too, for putting a heart maybe XD) than "X" percentage, don't be sold! Because is too expensive! And the customer will be angry and leave.
I don't know if you have played Recettear, is the nearest example that I can imagine.
But this percentage will be increased with the progression of the talent. So, maybe you cannot sell to more than 10% at first or without the talent, but in last level of Economy you can sell even in 200% of his value.
Please, can U help me with this or have any idea how can I reach it?😅
Ahh, okay. So you're basically doing a thing where the player is acting as a merchant, selling items to NPCs, and you need them to be able to input how many they're selling and the price they're selling for, and there's a calculation in the background to determine whether they've chosen a price that's permissible for the item, which will be a percentage range determined by a variable?
Ahh, okay. So you're basically doing a thing where the player is acting as a merchant, selling items to NPCs, and you need them to be able to input how many they're selling and the price they're selling for, and there's a calculation in the background to determine whether they've chosen a price that's permissible for the item, which will be a percentage range determined by a variable?
Yes, exactly!😤
I'm glad at less you understood me... @Trihan.
Item selected: Potion.
Original Value: 100
Custom Price to sell: 150
Economy in level 1 (10%+) : People will not buy it! Because they only accept values between 90-110!
But in Economy level higher: 50%+ is in range, and acceptable. They will buy it! (50-150!)
But in even higher... they will buy it in a blink! 100%, 200% or more... for example.

Percentage need to be stored in a variable, because can be changed across game, and talent progression but is a percentage of original value (and I need to check a range that included positive and negative of this to know if the sale is able or not).
Do you want this to be done entirely with eventing or are you okay with some scripting?
I want to know two ways if is possible🙏! Eventing or scripting! Both are Ok!
This is the basic setup for doing it with just eventing (with the exception of original price which needs to be a script since there's no other way to set a variable to an item price from the database).

1648001151034.png
Thank you very much, @Trihan . I've been testing it and it works perfect! In the end it was more of a mathematical problem than anything else. (I feel a bit silly for not realizing it myself, when I thought about using events but didn't quite know how to do it with percentages and so many variables. I think I lose a little myself there and think that is not possible.😐) It's nice that it was able to be solved on a pure event. Thank you very much for your example😍. You help me very much. If my game ever sees the light, rest assured you'll be in the credits. In the meantime, thank you very much for helping me!
You're the best! 😤
Thank you very much, @Trihan . I've been testing it and it works perfect! In the end it was more of a mathematical problem than anything else. (I feel a bit silly for not realizing it myself, when I thought about using events but didn't quite know how to do it with percentages and so many variables. I think I lose a little myself there and think that is not possible.😐) It's nice that it was able to be solved on a pure event. Thank you very much for your example😍. You help me very much. If my game ever sees the light, rest assured you'll be in the credits. In the meantime, thank you very much for helping me!
You're the best! 😤
You can do it much more easily with a script (where x and y are the IDs of the lower and upper range respectively, z is the ID of the number input variable, and e is the ID of the economy level variable):

JavaScript:
const price = $dataItems[$gameVariables.value(z)].price;
const percentage = Math.floor(price * ($gameVariables.value(e) * 10) / 100);
$gameVariables.setValue(x, price - percentage);
$gameVariables.setValue(y, price + percentage);

Then you'd just do the same conditional branches.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/percentaje-x-of-a-variable-range.146026/