Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Easily Memorize, Remove, and Replace Player's Items, Great for Jail sequences
BigEd781
post Aug 28 2008, 10:58 PM
Post #1


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Game_Party Addition for Item Memorization

Game_Party Addition for Item Memorization


Introduction

This is an addition to Game_Party that will allow you to easily memorize, remove, and restore the player's items, gold, and equipment.
This script should be fully compatible with other scripts that are well written (i.e., they alias the initialize method instead of overwriting it), but for one case that I can think of.
This script will be incompatible with the KGC large party script when memorizing equipped items. I will get around to fixing this soon enough.

Usage

Place the script in the materials section.

[Show/Hide] Memorizing and Restoring Items

When you want to take away the player's items, use a "Script" event command and this code:
CODE
$game_party.backup_items
$game_party.clear_items

$game_party.backup_items - Makes a copy of all currently held items and saves it to be restored later.
$game_party.clear_items - Removes all items from the player's inventory. Don't worry, you made a copy first, right?

Next, when you want to give the items back to the player, use another "Script" event command (inside a treasure chest or something) and use this single line:
CODE
$game_party.restore_items

That will replace all of the items that were saved when you last used the backup_items method and add them to the inventory.


[Show/Hide] Memorizing and Restoring Gold


This is very similar to the last operation. We have two commands to use when taking away the player's gold:
CODE
$game_party.backup_gold
$game_party.clear_gold

$game_party.backup_gold - Makes a copy of the current gold total.
$game_party.clear_gold - Removes all of the player's gold. Be sure to make the backup first!

When you wish to give the player's gold back to the party, use this in a "Script" event command:
CODE
$game_party.restore_gold

This will add the saved gold to the current total.


[Show/Hide] Memorizing and Restoring Player's Equipment


Again this process is familiar. Two command to clear and save the entire party's currently equipped items.
CODE
$game_party.backup_all_equips
$game_party.unequip_all

$game_party.backup_all_equips - Makes a copy of the current equipment for every member of the party.
$game_party.unequip_all - Removes all equipment from every party member. The equipment is not saved! It will be lost if you do not perform a backup first.

When you wish to give the party's equipment back, use the following line in a "Script" event command:
CODE
$game_party.restore_all_equips

This will unequip whatever the players are currently equipped with and place the saved equipment where it was previously. Nothing will be lost by performing this operation.

There is one more feature to mention involving equipment. You do not have to use only these three functions to change the equipment of the entire party.
You can save, clear, and restore the equipment of individual actors by calling similar methods of the Game_Actor class, like so:
CODE
$game_actors[id].backup_equips
$game_actors[id].clear_equips
$game_actors[id].restore_equips

id refers to the id of the actor that you wish to perform these actions on.



Script
Remember, just place it in the Materials section above "Main".

CODE
#==============================================================================
# ** Game_Party implementation
#------------------------------------------------------------------------------
#    aliased methods : initialize
#==============================================================================
class Game_Party
  alias :biged_old_init :initialize
  def initialize
    biged_old_init
    @temp_items = {}        # temp items hash
    @temp_weapons = {}      # temp weapons hash
    @temp_armors = {}       # temp armors hash
    @temp_gold = nil        # temp gold variable
  end
  #--------------------------------------------------------------------------
  # * if the player has picked up some items since their's were wiped
  #   and backed up, we need to combine the totals of any common items
  #--------------------------------------------------------------------------
  def merge_like_key_values(dest, src)
    return if dest == {}        
    for key in dest.keys          
      src[key] += dest[key] if src.has_key?(key)      
    end          
  end
  #--------------------------------------------------------------------------
  # * Make a copy of the current inventory
  #--------------------------------------------------------------------------
  def backup_items
    @temp_items   = Marshal::load(Marshal::dump(@items))
    @temp_weapons = Marshal::load(Marshal::dump(@weapons))
    @temp_armors  = Marshal::load(Marshal::dump(@armors))
  end
  #--------------------------------------------------------------------------
  # * Clear the current inventory
  #--------------------------------------------------------------------------
  def clear_items
    @items.clear
    @weapons.clear
    @armors.clear
  end
  #--------------------------------------------------------------------------
  # * Restore the backed up inventory if a backup exists
  #--------------------------------------------------------------------------
  def restore_items
    unless @temp_items == {}
      merge_like_key_values(@items, @temp_items)
      @items = @items.merge(@temp_items)
    end
    unless @temp_weapons == {}
      merge_like_key_values(@weapons, @temp_weapons)
      @weapons = @weapons.merge(@temp_weapons)
    end
    unless @temp_armors == {}  
      merge_like_key_values(@armors, @temp_armors)
      @armors = @armors.merge(@temp_armors)
    end
    @temp_items = @temp_weapons = @temp_armors = {}
  end  
  #--------------------------------------------------------------------------
  # * Backup All mparty member's equipment
  #--------------------------------------------------------------------------
  def backup_all_equips
    for i in @actors
      $game_actors[i].backup_equips
    end
  end
  #--------------------------------------------------------------------------
  # * unequip all party member
  #   THE EQUIPMENT WILL BE LOST FOREVER
  #   IF YOU DO NOT FIRST MAKE A BACKUP!
  #--------------------------------------------------------------------------
  def unequip_all
    for i in @actors
      $game_actors[i].clear_equips
    end
  end
  #--------------------------------------------------------------------------
  # * Backup All mparty member's equipment
  #--------------------------------------------------------------------------
  def restore_all_equips
    for i in @actors
      $game_actors[i].restore_equips
    end
  end
  #--------------------------------------------------------------------------
  # * Make a copy of the current gold total
  #--------------------------------------------------------------------------
  def backup_gold
    @temp_gold = @gold  
  end
  #--------------------------------------------------------------------------
  # * Clear the current gold total
  #--------------------------------------------------------------------------
  def clear_gold
    @gold = 0
  end
  #--------------------------------------------------------------------------
  # * Restore the saved gold total if one exists
  #--------------------------------------------------------------------------
  def restore_gold
    unless @temp_gold == nil
      @gold += @temp_gold
      @temp_gold = nil
    end
  end
  
end
#==============================================================================
# ** Game_Actor implementation
#------------------------------------------------------------------------------
#    aliased methods : initialize
#==============================================================================
class Game_Actor < Game_Battler
  alias :biged_old_init :initialize
  def initialize(actor_id)
    biged_old_init(actor_id)  
    @temp_weapons = []  #temporary store for weapons
    @temp_armors = []   #temporary store for armor
  end
  #--------------------------------------------------------------------------
  # * Make a copy of the currently equiped items
  #--------------------------------------------------------------------------
  def backup_equips    
    @temp_weapons = weapons
    @temp_armors = armors      
  end
  #--------------------------------------------------------------------------
  # * Restore back up equipment if it exists
  #--------------------------------------------------------------------------
  def restore_equips
    #un-equip the current equipment and place it in the inventory
    unless @temp_weapons == [] && @temp_armors == []  #no backup made
      for i in 0...5 do
        change_equip(i, nil)
      end
    end
    #-------------------------------------------------------------#
    #we check each one individually here because if any slot      #  
    #is set to nil, a default value is used (not nil).  This      #
    #default value does actually correspond to an item, and we    #
    #don't want that, so we check.                                #
    #-------------------------------------------------------------#
    #the incrementor is there because the armor array size will be#
    #different depending on whether the player is using 2 swords  #
    #-------------------------------------------------------------#
    @weapon_id = @temp_weapons[0].id if @temp_weapons[0] != nil    
    if two_swords_style
      @armor1_id = @temp_weapons[1].id if @temp_weapons[1] != nil      
      i = 0
    else
      @armor1_id = @temp_armors[0].id if @temp_armors[0] != nil  
      i = 1
    end
    @armor2_id = @temp_armors[i].id if @temp_armors[i] != nil
    @armor3_id = @temp_armors[i+1].id if @temp_armors[i+1] != nil
    @armor4_id = @temp_armors[i+2].id if @temp_armors[i+2] != nil
    @temp_weapons = @temp_armors = []    
  end
  #--------------------------------------------------------------------------
  # * Clear the currently equipped item set.
  #   THIS DOES NOT PLACE THE ITEMS IN INVENTORY!
  #   THEY WILL BE GONE FOREVER UNLESS YOU MAKE A BACKUP FIRST!
  #--------------------------------------------------------------------------  
  def clear_equips
    @weapon_id = 0
    @armor1_id = 0
    @armor2_id = 0
    @armor3_id = 0
    @armor4_id = 0
  end
end



__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
VerifyedRasta
post Aug 28 2008, 11:01 PM
Post #2


Level 20
Group Icon

Group: Revolutionary
Posts: 407
Type: Musician
RM Skill: Advanced




Great job Ed! ... I might use this in my game as well and credit you of course


__________________________
Go to the top of the page
 
+Quote Post
   
webbo227
post Aug 29 2008, 02:10 AM
Post #3


Level 7
Group Icon

Group: Revolutionary
Posts: 100
Type: Event Designer
RM Skill: Intermediate




Amazing, just what I need! Thanks! happy.gif


__________________________
"Oh c'mon Church. They say you're not completely dead as long as someone still remembers you."
"Yeah, but look who's left to remember me. It sure feels like being dead. Like all the way dead. Like being encased in cement and fired at the sun dead."


Red vs Blue - Recreation

[Show/Hide] Most Epic Forum Quote Ever Conceived
Homunculus - "It would be awesome to kill everyone by throwing the moon at earth. NO ONE WOULD EXPECT IT. AND EVEN IF THEY DID. WHAT CAN THEY DO? IT'S THE FUCKING MOON. " [Link]
Adriantepes313 - Agreed. But damn, the moon? Brilliant. But I have a better idea. if we have superpowers, why not throw the fucking sun? [Link]

Bow down to your new lords and masters.


-- Webbo
Go to the top of the page
 
+Quote Post
   
maker2008
post Aug 29 2008, 10:52 AM
Post #4


Level 1
Group Icon

Group: Member
Posts: 11
Type: Event Designer
RM Skill: Advanced




great script, thank you very much!
I really want a similar operation on gold
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 29 2008, 11:00 AM
Post #5


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




OK, I'll update it with a gold function tonight. I will also change it a bit so that it only appends the saved items to the player's inventory instead of completely replacing it. This is would be good if you removed the player's items, but then they gained an item before having their full inventory restored.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 29 2008, 11:05 AM
Post #6


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




Wow, BigED, this is an excellent script! Thanks for sharing it! Just one question...
Say I save&remove my items and go through this "test". During this test I obtain "Elixir". After I complete the test, I use the "replace" command to get back the items.

Would I have just the "saved" items in my inventory now, or "saved+elixir" items?


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 29 2008, 11:28 AM
Post #7


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




...

Read the previous post. I am fixing that problem when I get home tonight. It is a quick fix, but I can't test it at work.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 29 2008, 04:30 PM
Post #8


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




*Only bumping because the script has been updated*

Currently held items are no longer blown away when the back up items are restored. The two items sets are merged instead.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
VerifyedRasta
post Aug 29 2008, 05:05 PM
Post #9


Level 20
Group Icon

Group: Revolutionary
Posts: 407
Type: Musician
RM Skill: Advanced




QUOTE (BigEd781 @ Aug 29 2008, 04:52 PM) *
*Only bumping because the script has been updated*

Currently held items are no longer blown away when the back up items are restored. The two items sets are merged instead.


Excellent! This will go perfectly with my game now, thanks!


__________________________
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 29 2008, 05:38 PM
Post #10


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




QUOTE (BigEd781 @ Aug 29 2008, 07:52 PM) *
*Only bumping because the script has been updated*

Currently held items are no longer blown away when the back up items are restored. The two items sets are merged instead.



Oooh, I found an error n_n. Okay, this is my setup; a very small trial/dungeon. You enter this "area". It's one-spaced so you're forced to step on the tile which "takes away" your equipment. I had Item A, so that's gone. I continue and get item B and then proceed to leave the small dungeon, again a forced tile spot which gives you back the items. It worked, I had items A and B. However, if I repeat the same procedure (from the starting point to the ending, not going backwards first), I end up with Item A x1 and Item Bx1; and not Item Ax1 and Item Bx2.

EDIT: The entrance is one-spaced, and that calls the script command, same as the ending.

Understand? (There was another error where walking over it repeatedly ended up in losing all the items, but am still testing that one)


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   
Lukedevoux
post Aug 29 2008, 05:44 PM
Post #11


Level 11
Group Icon

Group: Revolutionary
Posts: 181
Type: Developer
RM Skill: Beginner




Well I just tested out your script VERY COOL! thumbsup.gif So you just need to fix remove of equipped items as well. Since I still had equipped items, when I called the script.


__________________________
[Show/Hide] Knights of the old Republic Joke

There are two Mandalorians are out in the woods. One of them collapses. He doesn't seem to be breathing and his eyes are glazed. The other Mandalorian takes out his communicator and contacts his commander. He gasps: "My partner has collapsed! I don't know what to do!" After a moment, the commander responds: "Calm down. I can help. First let's make sure your partner is dead." There is a silence then a blaster shot is heard. Back on the communicator, the Mandalorian says: "Okay, now what?"

Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 29 2008, 08:27 PM
Post #12


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




QUOTE (Twilight27 @ Aug 29 2008, 06:00 PM) *
QUOTE (BigEd781 @ Aug 29 2008, 07:52 PM) *
*Only bumping because the script has been updated*

Currently held items are no longer blown away when the back up items are restored. The two items sets are merged instead.



Oooh, I found an error n_n. Okay, this is my setup; a very small trial/dungeon. You enter this "area". It's one-spaced so you're forced to step on the tile which "takes away" your equipment. I had Item A, so that's gone. I continue and get item B and then proceed to leave the small dungeon, again a forced tile spot which gives you back the items. It worked, I had items A and B. However, if I repeat the same procedure (from the starting point to the ending, not going backwards first), I end up with Item A x1 and Item Bx1; and not Item Ax1 and Item Bx2.

EDIT: The entrance is one-spaced, and that calls the script command, same as the ending.

Understand? (There was another error where walking over it repeatedly ended up in losing all the items, but am still testing that one)



I will look into it. If that is true, that is a good bug find, thanks! It is happening because I am simply merging the two hashes, but that will not combine equal key values. I can fix it, but probably not until tomorrow.
@Luke: I forgot about those tongue.gif I'll fix that.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 29 2008, 09:09 PM
Post #13


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




QUOTE (Lukedevoux @ Aug 29 2008, 09:06 PM) *
Well I just tested out your script VERY COOL! thumbsup.gif So you just need to fix remove of equipped items as well. Since I still had equipped items, when I called the script.


Hey Ed, can you make the removal of equipped items optional?


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 29 2008, 09:11 PM
Post #14


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




It will be.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 30 2008, 01:32 AM
Post #15


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




*UPDATE*

FEATURE - Now possible to perform saving, clearing, and restoring operations on gold.
FEATURE - Now possible to perform saving, clearing, and restoring operations on currently equipped items. You may perform this on the entire party as a whole, or individual actors.
BUG_FIX - Fixed the bug pointed out by Twilight which caused restored items to not merge properly when it shared items in common with the current inventory. Nice catch Twilight, thanks again.

I noted above that this will almost assuredly fail to save all of the currently equipped items if you are using the KGC large party script. This is because I have not taken the time to look at it as to get information on how it keeps track of equipped items. I will fix that eventually.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 30 2008, 07:03 AM
Post #16


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




QUOTE (BigEd781 @ Aug 30 2008, 04:54 AM) *
I noted above that this will almost assuredly fail to save all of the currently equipped items if you are using the KGC large party script. This is because I have not taken the time to look at it as to get information on how it keeps track of equipped items. I will fix that eventually.


I plan to use that large party script, but also plan to disable the removal of equipped items (So far...). Will I experience any other problems then?
And I'll test it out for any more bugs n_n


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 30 2008, 07:39 AM
Post #17


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




**BUG**

Heh, I found more errors (though you can work around it). Here, I'll upload this project for testing

(Removed)

You can check the game to see if I did anything wrong; as you can see, you have to go through the 'fence dungeon' where the "call script" commands activate at the start and end. In the middle you can talk to the crystal to get one item (for more testing).

Okay, simply start the game, talk to the left-most character at the top, who'll give you some items. Go straight down (right path) and after the "script call" space event, go back up (out of the dungeon) and back down (back into it). Proceed to exit the dungeon and you'll have no items.

My guess is, the game recorded the fact that you had no items on the second walk-by, so that is what you get back in the end.

(It works perfectly anyway, and I can still use this. Just prevent the character from going backwards and then back in; which I planned to do somehow anyway...)


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   
maker2008
post Aug 30 2008, 08:56 AM
Post #18


Level 1
Group Icon

Group: Member
Posts: 11
Type: Event Designer
RM Skill: Advanced




Thank you very much!
Go to the top of the page
 
+Quote Post
   
BigEd781
post Aug 30 2008, 11:11 AM
Post #19


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




QUOTE (Twilight27 @ Aug 30 2008, 08:01 AM) *
**BUG**

Heh, I found more errors (though you can work around it). Here, I'll upload this project for testing

http://www.mediafire.com/?ccmyqrs82tl

You can check the game to see if I did anything wrong; as you can see, you have to go through the 'fence dungeon' where the "call script" commands activate at the start and end. In the middle you can talk to the crystal to get one item (for more testing).

Okay, simply start the game, talk to the left-most character at the top, who'll give you some items. Go straight down (right path) and after the "script call" space event, go back up (out of the dungeon) and back down (back into it). Proceed to exit the dungeon and you'll have no items.

My guess is, the game recorded the fact that you had no items on the second walk-by, so that is what you get back in the end.

(It works perfectly anyway, and I can still use this. Just prevent the character from going backwards and then back in; which I planned to do somehow anyway...)


So are are right in thinking that the game recorded the fact that you have no items, but that is really by design. I do not see a reason to disallow making a backup when the player has no items. It is working as it should. You wlso should remember that this is not a likely scenario. When you want to take away a player's items, it will rarely (if ever) be done more than once before the player's items are returned. Also, the player will most likely not have control over when these things take place, as they do in the example.

So there is nothing I could really change here. Having no items is still a valid case. Keep up the testing though!

PS, as long as you are not using the equipped item functions you should have no problems with this and the large party scripts.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Twilight27
post Aug 30 2008, 04:04 PM
Post #20


Level 19
Group Icon

Group: Revolutionary
Posts: 371
Type: Event Designer
RM Skill: Beginner




Well yea, just like I said, it wasn't a problem I would have encountered since the player won't be able to do that. Anyway, you checked out the testing demo right? I'm going to remove the link soon.

Um, now I'm wondering...there are scripts that vary the equipment you have, such as: Arm, Head, Feet, etc.
Does your equipment option work with those scripts perfectly?


__________________________

Fall to the power of the Emo!
We have cookies!


Notice!! Check out my topic (http://www.rpgrevolution.com/forums/index.php?showtopic=45736&st=0#entry454175) if you're interested in helping me make a script that limits the number of characters & items you use in battle AND also an item durability feature! Thanks for any help in advance!
Go to the top of the page
 
+Quote Post
   

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2013 - 04:21 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker