Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> [SSS] Disassemble Shop, Salvage your items rather than selling them.
Shanghai
post Jun 12 2010, 07:32 PM
Post #1


Level 31
Group Icon

Group: Revolutionary
Posts: 747
Type: Developer
RM Skill: Skilled




Shanghai Simple Script - Disassemble Shop
made by Shanghai



Link/Script
Click here

Introduction
This script creates a new scene where players can disassemble their unwanted items or break them down into something more basic. That broadsword which has been replaced by a mightier broadsword can now be broken down into various components and aid the player one last time rather than just sitting there in the inventory to rust.

How to Use
To load the disassemble shop, use the following evented script call:
CODE
$scene = Scene_Disassemble.new


Inside the shop, it will only list items with the following tag set inside of their noteboxes.
CODE
<disassemble>
weapon 1
armor 2
item 3
</disassemble>

Place this in the notebox of either an item, weapon, or armor and that item can then be disassembled into the materials you've placed in between the disassemble tags.

Compatibility
This script is not compatible with people who don't care about database efficiency.

For more Shanghai Simple Scripts
Visit Here.


__________________________
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
Zeriab
post Aug 11 2010, 12:17 PM
Post #2


Level 12
Group Icon

Group: Revolutionary
Posts: 196
Type: Event Designer
RM Skill: Skilled




Nice script happy.gif

Do only this part deal with finding disassembled items in the note?
CODE
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # disassembled_items
  #--------------------------------------------------------------------------
  def disassembled_items
    return @disassembled_items if @disassembled_items != nil
    @disassembled_items = []
    disassembled = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:DISASSEMBLE|disassmbled)>/i
        disassembled = true
      when /<\/(?:DISASSEMBLE|disassmbled)>/i
        disassembled = false
      when /(.*)[ ](\d+)/i
        next unless disassembled
        case $1.upcase
        when "WEAPON", "W", "WEP"
          @disassembled_items.push($data_weapons[$2.to_i])
        when "ARMOR", "ARMOUR", "A", "ARM"
          @disassembled_items.push($data_armors[$2.to_i])
        when "ITEM", "I"
          @disassembled_items.push($data_items[$2.to_i])
        end
      end
    }
    return @disassembled_items
  end
end


In that case the following edit should hopefully do it: (I haven't tested it)
CODE
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # disassembled_items
  #--------------------------------------------------------------------------
  def disassembled_items
    return @disassembled_items if @disassembled_items != nil
    @disassembled_items = []
    disassembled = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:DISASSEMBLE|disassmbled)>/i
        disassembled = true
      when /<\/(?:DISASSEMBLE|disassmbled)>/i
        disassembled = false
      when /([^\s\d]*)\s*\d/
        next unless disassembled
        case $1.upcase
        when "WEAPON", "W", "WEP"
          item_ids = line.scan(/\d+/)
          items = item_ids.map {|id| $data_weapons[id.to_i]}
          @disassembled_items.push(*items)
        when "ARMOR", "ARMOUR", "A", "ARM"
          item_ids = line.scan(/\d+/)
          items = item_ids.map {|id| $data_armors[id.to_i]}
          @disassembled_items.push(*items)
        when "ITEM", "I"
          item_ids = line.scan(/\d+/)
          items = item_ids.map {|id| $data_items[id.to_i]}
          @disassembled_items.push(*items)
        end
      end
    }
    return @disassembled_items
  end
end


I changed the /(.*)[ ](\d+)/i regular expression to /([^\s\d]*)\s*\d+/. There was no reason to test for case insensitivity so I removed that.
I changed the space requirement to allow for any amount of whitespace before the first digit to reduce potential frustration. I also made it optionally. Discarding whitespace if you are pressured on room in the note is a bonus.
The grouping captures the text until a whitespace character or a digit is met and stores this in $1 which you use to determine type of item. Note that it only checks for the existence of a single digit so the regular expression probably won't check the entire string of a valid match. (Why should it)

In each item type I scan for groups of digits to retrieve an array of numbers. (Remember that they are still strings)
I then map them to their respective objects and use the * operator to expand the array into a list of arguments.

Note that one can add a, say weapon, multiple times. I did not alter this functionality since it may have been intentional. I am just pointing it out in case you hadn't considered it.

*hugs*


__________________________
Go to the top of the page
 
+Quote Post
   



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: 22nd May 2013 - 10:36 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker