Help with cashing out an item

oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
79
Reaction score
8
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,543
Reaction score
12,059
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

Blech. I hate coming up with stories. Making gameplay is fun but coming up with lore and reasons for these areas/mechanics just makes me sleepy.
40 card deck size, the plugin seems more sluggish.
Village theme I composed for a commission!
Stream will be live shortly with some Haunting Ground! Feel free to drop by!

Forum statistics

Threads
94,567
Messages
921,938
Members
124,430
Latest member
Venator123
Top