Help with cashing out an item

oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
115
Reaction score
23
First Language
english
Primarily Uses
RMMV
So, I'm trying to create a scenario where the player has the option to sell all (only all or none) an NPC for 50$ per item.

So...as far as I can tell I need to create a variable based on the amount of item X in the player's inventory, then remove a number of that item equal to that variable.

The problem is that I then want to add $ based on that variable, but I can only add a fixed amount or an amount equal to the variable. If I want to add 50 $ per item I'd have to create 50 "add gold" commands with an amount equal to the variable.


The only other thing I can think of is to multiply the original variable by 50, do an add gold command equal to the new variable amount, and then divide the variable by 50 and then reduce the player's inventory of items by an amount equal to the variable.

Is there an easier way, or is this my best bet?
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
965
Reaction score
708
First Language
English
Primarily Uses
RMMV
@oriongates What you need is a good-old loop! Store the total number of the item into a variable, wipe all of the item from the inventory of the player, then create a loop that decrements that variable by one and hands out $50 each time. Make sure to create a conditional branch within the loop that breaks out once the variable reaches zero.

Code:
◆Change Items:Potion + 99
◆Text:None, Window, Bottom
:    :Are you sure you want to sell all your Potions?
◆Show Choices:Yes, No (Window, Right, #1, #2)
:When Yes 
  ◆Control Variables:#0005 itemTotal = The number of Potion
  ◆Change Items:Potion - {itemTotal}
  ◆Loop
    ◆Control Variables:#0005 itemTotal -= 1
    ◆Change Gold:+ 50
    ◆If:itemTotal = 0
      ◆Break Loop
      ◆
    :End
    ◆
  :Repeat Above
  ◆Text:None, Window, Bottom
  :    :Nice doing business with you!
  ◆
:When No 
  ◆Text:None, Window, Bottom
  :    :Well, alright!
  ◆
:End
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,773
Reaction score
12,205
First Language
English
Primarily Uses
RMMV
No loop needed, actually.

Code:
Show Choices: [Sell One] [Sell All]
When [Sell One]
  Change Items: [item] -= 1
  Change Gold += 50
When [Sell All]
  Control Variables: [Counter] = Number [item] in Inventory
  Change Items: [item] -= Variable [Counter]
  Control Variables: [Counter] *= 50
  Change Gold += Variable [Counter]
End
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

being an extreme introvert with massive anxiety... I forget this is really, REALLY frustrating for people who are the exact opposite. still, wait this out and stay home...
I hope you all are keeping safe. <3 If you need a shoulder or an ear, I have two of both and am more than willing to listen & support you! Times are weird.
My dad, super frustrated by seclusion, asking me how I live like this. I shrug. "It helps to not like what is outside."
Apparently it's not just people who are hit by corona virus. My phone has set itself to English language on its own. Not that I'm complaining... :D
I got a new computer and can't find my product activation key for MV, what do I do ;-;

Forum statistics

Threads
95,443
Messages
929,178
Members
125,683
Latest member
medialrs
Top