oriongates

Veteran
Veteran
Joined
Dec 26, 2019
Messages
219
Reaction score
59
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
1,076
Reaction score
862
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,529
Reaction score
14,848
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:

Latest Threads

Latest Posts

Latest Profile Posts

New MZ Update! Subfolders for Assets, Search in Plugin Help, Map Layer Buttons | RPG Maker News #78

A little WIP I decided to drop for something coming in 10-12 hours!
9.PNG
I just did some math and... apparently what seemed to be a little fun gimmick turned out to be an 80+ actors project :kaoswt2:
Yay! the original character contest 3 pack is here!
Both MV and MZ looks very good, congratulation for both RMW and Tkool participant!
I definitely can add these characters to use for my game project.

Steam link
The worst part of game development has to be marketing. Ugh...

Forum statistics

Threads
112,481
Messages
1,068,574
Members
146,148
Latest member
JonasEichmann
Top