Help with cashing out an item

oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
75
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,487
Reaction score
12,032
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 Profile Posts

Broke: Dont move. -boring. -passive. -uncreative. Woke: Bewegen Sie Nicht! +authoritative. +foreign. +reminds your son that he's a garden gnome now.
My girlfriend left a note on the fridge saying 'This isn't working, goodbye.' I opened the refrigerator and it works just fine. Weird.
BCj
Could someone translate something from Japanese to English for me?
You know, I sometimes ponder if working on the story and details is more necessary than the game itself. Its... technically work, just not direct.

Like for me specifically I never stop evolving the story based on what avenues I can approach in gameplay and then I get anxious thinking "hey good thing I thought about that now instead of later". Repeat ad nauseam.
World Of Final Fantasy Livestream~!
(Ft. Kaliga)

Forum statistics

Threads
94,385
Messages
920,529
Members
124,158
Latest member
schico
Top