Event-based Inventory Dump

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
Just want to check on this, because I know it's something of a common thing in RPGs (especially Eastern ones):

Say the party gets captured. Obviously the captors aren't going to leave them armed and well-stocked, so in the story they take away everything the party has (or most everything). Now as the developer I don't know how many items the characters have gotten, so for all I know they could have a single health potion left, or several dozen, but I want them all gone. The player may get them back later but for now they should have (basically) empty pockets.

Is there a quick way to easily dump the player's inventory out, without having to check a bajillion variables or needing to create a script to do as such? 
 

Kurisu

game dev, pilot, cat lover
Veteran
Joined
Aug 14, 2013
Messages
77
Reaction score
18
First Language
non-english
Primarily Uses
If you want to get rid of everything, perhaps the easiest way would be blocking the player's access to the item menu then?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
Well I looked at it, seems like you might not be able to access the list directly (since $game_party.items/armors/weapons return processed data from the actual list, not the list itself)... and I haven't seen a method to do it via the other event commands other than the Script event commands... so

add this script:

class Game_Party def clear_items_all @items = [] @weapons = [] @armors = [] endendthen just use the Script call:

Code:
Script: $game_party.clear_items_all
Unless of course you're fine to just create a loop that loops thru all weapons, items and armors and decrease them... that way it won't need the script... but that's quite a huge task to perform... btw, this method only needs 1 variable I believe, just for looping the indexes... since AFAIK, if you use reduce, if it goes below 0, it will simply make it 0... so you can just loop thru each item and reduce by 99...but then again, it's still quite tedious, and performance-wise inferior to the other method since it involves looping thru lots of items...
 
Last edited by a moderator:

senpoRiot

Professional Procrastinator
Veteran
Joined
Sep 6, 2012
Messages
291
Reaction score
36
First Language
Tagalog
Primarily Uses
But what if he wants to get all the same items/equipments back before it was taken away?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
then he needs to ask for it first... XD...

anyway, if he decides it that way, I will really suggest using scripts...

class Game_Party def clear_items_all(save) if save @items_old = @items @weapons_old = @weapons @armors_old = @armors end @items = [] @weapons = [] @armors = [] end def regain_items_lost @items += @items_old @weapons += @weapons_old @armors += @armors_old endendto lose all items while keeping a back-up of everything
Code:
Script: $game_party.clear_items_all(true)
use false otherwisethen just use

Code:
Script: $game_party.regain_items_lost
if you want to regain those items... note that this is not tested, so I'm not sure if it has some negative implications... I'm thinking it might not be modifying the quantities correctly, gotta test it after eating
 
Last edited by a moderator:

Zoltor

Veteran
Veteran
Joined
Jan 18, 2014
Messages
1,550
Reaction score
211
First Language
English
Primarily Uses
then he needs to ask for it first... XD...

anyway, if he decides it that way, I will really suggest using scripts...

class Game_Party def clear_items_all(save) if save @items_old = @items @weapons_old = @weapons @armors_old = @armors end @items = [] @weapons = [] @armors = [] end def regain_items_lost @items += @items_old @weapons += @weapons_old @armors += @armors_old endendthen just use

Code:
Script: $game_party.regain_items_lost
if you want to regain those items... note that this is not tested, so I'm not sure if it has some negative implications... I'm thinking it might not be modifying the quantities correctly, gotta test it after eating
I wanted to try this, but sadly through the script event command, It's not allowing me to have more then 11 lines of script.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
You're not supposed to put it there bro, even if it allowed you, it probably won't do anything...


You put that large code into the scripts section... then just use the 1 liner script I posted on the event command
 

Zoltor

Veteran
Veteran
Joined
Jan 18, 2014
Messages
1,550
Reaction score
211
First Language
English
Primarily Uses
Oh yea lol, duh my bad, wasn't thinking(It's almost 6am here)
 

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
Okay, will look into testing this script. 

Just to make sure... the "@'name' = [ ]" parts are creating empty arrays for those variables, right?

Also, would this work for, say, when I want to empty out just weapons (say, walking into a night club and for obvious reasons you can't have stabby/shooty things on you), but not items or armor as long as there's a recall as well?

ex: 

Code:
class Game_Party  def clear_items_all(save)    if save      @items_old = @items      @weapons_old = @weapons      @armors_old = @armors    end    @items = []    @weapons = []    @armors = []  end  def clear_weaps(save)    if save      @weaps_old = @weapons    end    @weapons = []  end    def regain_items_lost    @items += @items_old    @weapons += @weapons_old    @armors += @armors_old  end    def regain_weaps_lost    @weapons += @weaps_old  endend
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
AFAIK, yes that would work... though as I said, I'm not sure if the item quantities will be adjusted as well... I haven't have time to look at those yet so it might not work correctly for that matter...


EDIT: I looked at it, it seems like the item number is the actual thing saved in those arrays so I think it's all okay... :)
 
Last edited by a moderator:

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
I'll test it in a bit. Then we'll see if it blows up in my face or not XD
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
btw, make sure you don't run the restore before doing any clear, that will 99.99% throw a nil error during the first time you try it...
 
Last edited by a moderator:

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
Aaaaand throwing an error already @__@

Current layout is as follows: 

"Game" starts;

Character runs over to guard and is given various items (5 potions, 2 weapons [she dual-wields them], 1 piece of body/head armor, and 2 accessories;

Character equips them;

Character then walks down onto black hexagram (remove event);

and then this happens:



ADDENDUM: After another quick test-run, I found that unequipping/ not equipping the items allows the "purge" Event to pass successfully. However, trying to get the items to restore (via a white hexagram, or the "regain" Event) throws a different error that states: "can't convert Hash into Array" @__@
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
what is line 85? anyway, I think it seems like you need to unequip all items first before you try to do the removal script...


which line errors for the next error code?
 
Last edited by a moderator:

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
what is line 85? anyway, I think it seems like you need to unequip all items first before you try to do the removal script...
def items    @items.keys.sort.collect {|id| $data_items[id] }  endEDIT: Removed pic because derp there's already a screenshot of it in my last post @__@

It's stopped showing up when I equip stuff prior to stepping on the black hexagram, but also get this now if I try to open the Equip menu after stepping on it :\

Which line errors for the next error code?
'Game_Interpreter' line 1411. And all it has on it is "eval(script)". :\
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
then it means it's actually a hash, so you need this instead:

Code:
class Game_Party  def clear_items_all(save)    if save      @items_old = @items      @weapons_old = @weapons      @armors_old = @armors    end    @items = {}    @weapons = {}    @armors = {}  end  def clear_weaps(save)    if save      @weaps_old = @weapons    end    @weapons = {}  end    def regain_items_lost    @items += @items_old    @weapons += @weapons_old    @armors += @armors_old  end    def regain_weaps_lost    @weapons += @weaps_old  endend
this should eliminate the "keys" error... and possible the next one too, sadly evals only return eval error but never returns what really errored...
 
Last edited by a moderator:

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses
Yay! It worked!... Kinda. XD
I had to remove the '+' in the "return items" bit, because it was throwing another error ("undefined method '+' for {}:Hash"), but after doing that it worked!

Now if I could just remove the equipped items.... :\
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
oh, though that means that restoring will remove any item you currently have... w8, I'm gonna look on the operators for hash, there must be something for adding

something like this:

Code:
  def regain_weaps_lost     @weaps_old.each do |weap|      #basically we iterate each of the old weapons      #then check if that weapon exists right now      #if yes, we add the amounts, else we set the amount      @weapons[weap[0]].nil? @weapons[weap[0]] = weap[1] : @weapons[weap[0]] += weap[1]    end  end
for the equipped, well find a method to unequip all items before clearing... :)
 
Last edited by a moderator:

Caustic

Hopped Up on Goofballs
Member
Joined
Jan 6, 2014
Messages
182
Reaction score
39
First Language
Engrish
Primarily Uses

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
oh I forgot that it needs another ?

Code:
 def regain_weaps_lost     @weaps_old.each do |weap|      #basically we iterate each of the old weapons      #then check if that weapon exists right now      #if yes, we add the amounts, else we set the amount      @weapons[weap[0]].nil? ? @weapons[weap[0]] = weap[1] : @weapons[weap[0]] += weap[1]    end  end
btw, once it works, you need to do it for items and armors too...
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

Not sure if it's true (and I won't judge or blame anyone if it is, really), but I heard from confident sources that you guys (and girls) really really like to
How is this new year for everyone? Hope you are well. Still deep in Covid in the US. Its like a vampire and refuses to die with even more strains. I need some holy water to kill it with.
in my game, what's known as HeadSpace is combining with the real world...
oh looks like the forums updated while I wasn't looking and we can put a banner now. Neat!
Treating this as a devlog

Forum statistics

Threads
107,664
Messages
1,031,250
Members
139,789
Latest member
tigraroe
Top