iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> Item Synthesis+, A new way of fusing items.
mithos
post Aug 9 2010, 01:53 AM
Post #1


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




This script presents a new way of fusing items. Any item can serve as "Item A". Then, any item can be fused into this and have a different effect based on a tag in the notebox. (e.g. if a potion is used as Item B then Item A will restore 10 extra hp, no matter the original effect). Currently only numeric effects are supported. In the future any change to an item will be possible. Item B may also be cursed (i.e. have a negative effect). No matter what order items are fused in, the same base item A and combination of item Bs will produce the same product, and use the same slot in the items page.

Note that, when using this script, loading a previous save will not work if the database has been changed - you will have to start a new game.

Instructions/description also included in the script.
Spoiler:
CODE
#=============================================================================
# Item Synthesis v1.0.2
# by Mithos
#=============================================================================
# Description
# This script presents a new way of fusing items. Any item can serve as "Item A"
# Then, and item can be fused into this and have a different effect based on
# a tag in the notebox. (e.g. if a potion is used as Item B then Item A will
# restore 10 extra hp, no matter the original effect)
# Currently only numeric effects are supported. In the future any change to an
# item will be possible. Item B may also be cursed (i.e. have a negative effect)
# No matter what order items are fused in, the same base item A and combination
# of item Bs will produce the same product, and use the same slot in the items
# page.

# Instructions
# Any item may be used as item A. To make an item usable as Item B, place into
# it's notebox the tag <synth xyz>

# x is the stat to be affected (note if the item does not have this stat, e.g.
# hp for a weapon, the fusion will take place but will have no effect)
# y is either + or -. pretty obvious what this does
# z is a number. Yup it's the amount to change x by

# possible values for x

#for when item A is item
# hp
# hprate
# mp
# mprate
# dmg
# var
# atk_f
# spi_f

#for when item A is Weapon/Armor
# atk
# def
# spi
# agi

# a synthesis shop can be started with the event script command:
# $scene = Scene_Synth.new

#WARNING - this script is still largely untested and may contain bugs,
# conflicts with other scripts, or other problems I have not noticed.
# Please report them in the thread if you find one so I can fix it

#Note - Currently item names may get confusing, as i have not implemented a
# full naming system.
#=============================================================================
# RPG::BaseItem
#=============================================================================

class RPG::BaseItem
  
  attr_accessor :synth_type
  attr_accessor :idlist
  
  def set_synth_type #run when game loads
    @idlist = [@id]
    can_synth = (@note =~ /<synth (\S+)>/ ? true : false) #does a synth tag exist?
    @synth_type = @note.scan(/<synth (\S+)>/)[0][0] if can_synth #read tag
  end
  
end

#=============================================================================
# Scene_Title - load synth tags
#=============================================================================

class Scene_Title
  alias :synth_load :load_database unless $@
  def load_database
    synth_load
    $data_items.each {|x| x.set_synth_type unless x == nil}
    $data_weapons.each {|x| x.set_synth_type unless x == nil}
    $data_armors.each {|x| x.set_synth_type unless x == nil}
  end
end

#=============================================================================
# Scene_File - allow saving of created items
#=============================================================================

class Scene_File
  alias :save_synth :write_save_data unless $@
  def write_save_data(file)
    save_synth(file)
    Marshal.dump($data_items, file)
    Marshal.dump($data_weapons, file)
    Marshal.dump($data_armors, file)
  end
  
  alias :load_synth :read_save_data unless $@
  def read_save_data(file)
    load_synth(file)
    $data_items = Marshal.load(file)
    $data_weapons = Marshal.load(file)
    $data_armors = Marshal.load(file)
  end
end

#=============================================================================  
# Window_SynthA  && Window_SynthB
#=============================================================================

class Window_SynthA < Window_Item
  #--------------------------------------------------------------------------
  # * Whether or not to include in item list
  #     item : item
  #--------------------------------------------------------------------------
  def initialize(*x)
    super(*x)
    @column_max = 1
  end
  
  def include?(item)
    return false if item == nil
    return true
  end
  #--------------------------------------------------------------------------
  # * Whether or not to display in enabled state
  #     item : item
  #--------------------------------------------------------------------------
  def enable?(item)
    return true
  end
  
  #--------------------------------------------------------------------------
  # Fix display for new width
  #--------------------------------------------------------------------------
  
  def item_rect(index)
    rect = Rect.new(0, 0, 0, 0)
    rect.width = (contents.width + @spacing) / @column_max - @spacing
    rect.width *= 2
    rect.height = WLH
    rect.x = 0
    rect.y = index * WLH
    return rect
  end
end


class Window_SynthB < Window_SynthA
  #--------------------------------------------------------------------------
  # * Whether or not to include in item list
  #     item : item
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item == nil
    return false if item.synth_type == nil
    return true
  end
end

#============================================================================
# Scene Synth
#============================================================================

class Scene_Synth < Scene_Base
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @viewport = Viewport.new(0, 0, 544, 416)
    @help_window = Window_Help.new
    @help_window.viewport = @viewport
    @synthA_window = Window_SynthA.new(0, 56, 272, 360)
    @synthB_window = Window_SynthB.new(272, 56, 272, 360)
    @synthA_window.viewport = @viewport
    @synthB_window.viewport = @viewport
    @synthA_window.help_window = @help_window
    @synthB_window.help_window = @help_window
    @synthA_window.active = true
    @synthB_window.active = false
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    @viewport.dispose
    @help_window.dispose
    @synthA_window.dispose
    @synthB_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Frame
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @help_window.update
    @synthA_window.update
    @synthB_window.update
    if @synthA_window.active
      update_item_selection_A
    elsif @synthB_window.active
      update_item_selection_B
    end
  end
  #--------------------------------------------------------------------------
  # * Update Item Selection
  #--------------------------------------------------------------------------
  def update_item_selection_A
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      @itemA = @synthA_window.item
      if @itemA != nil
        $game_party.last_item_id = @itemA.id
      end
      Sound.play_decision
      @synthA_window.active = false
      @synthB_window.active = true
    end
  end
  
  def update_item_selection_B
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @synthA_window.active = true
      @synthB_window.active = false
    elsif Input.trigger?(Input::C)
      @itemB = @synthB_window.item
      if @itemB != nil
        $game_party.last_item_id = @itemB.id
      end
      Sound.play_decision
      $game_party.lose_item(@itemA, 1)
      $game_party.lose_item(@itemB, 1)
      make_item(@itemA, @itemB)
      $scene = Scene_Synth.new   #refresh scene
    end
  end
  
  
  #-----------------------------------------
  # Making the new items
  #-----------------------------------------
  
  def make_item(itemA, itemB)
      item = Marshal.load(Marshal.dump(itemA)) #clone itemA
      
      item.idlist.push(itemB.id) # adds new item id into array
      item.id = 0
      
      #make id number
      #the number will be unique for a given combination of ids (think
      # like on a number grid, but with 3+ dimensions =S)
      for i in item.idlist
        item.id += item.idlist[i]*(999**i)
      end
      item.id = item.id.to_i
      item.id = item.id.to_i
      
      @synth_type = nil  #make this an "A" only item
      
      attrib = itemB.synth_type.scan(/(\w+)(\S)(\d+)/)[0][0]
      amount = itemB.synth_type.scan(/(\w+)(\S)(\d+)/)[0][2].to_i
      amount *= -1 if itemB.synth_type.scan(/(\w+)(\S)(\d+)/)[0][1] == "-"
      
      
    case itemA.class.to_s
    when "RPG::Item"
      case attrib
      when "hp"
        item.hp_recovery += amount
      when "hprate"
        item.hp_recovery_rate += amount
      when "mp"
        item.mp_recovery += amount
      when "mprate"
        item.mp_recovery_rate += amount
      when "dmg"
        item.base_damage += amount
      when "var"
        item.variance += amount
      when "atk_f"
        item.atk_f += amount
      when "spi_f"
        item.spi_f += amount
      end
      
      item.name = "Enhanced " + item.name
      
      $data_items[item.id] = item #create item in "database"
      $game_party.gain_item($data_items[item.id], 1) #give party the item
      
      
    when "RPG::Weapon"
      case attrib
      when "atk"
        item.atk += amount # temporary effect
      when "def"
        item.def += amount
      when "spi"
        item.spi += amount
      when "agi"
        item.agi += amount
      end
      
      $data_weapons[item.id] = item #create item in "database"
      $game_party.gain_item($data_weapons[item.id], 1) #give party the item
      
      #make equipable
      for class_type in $data_classes[1..$data_classes.size]
        class_type.weapon_set.push(item.id) if class_type.weapon_set.include?(itemA.id)
      end
      
    when "RPG::Armor"
      
      case attrib
      when "atk"
        item.atk += amount # temporary effect
      when "def"
        item.def += amount
      when "spi"
        item.spi += amount
      when "agi"
        item.agi += amount
      end

      $data_armors[item.id] = item #create item in "database"
      $game_party.gain_item($data_armors[item.id], 1) #give party the item
      
      #make equipable
      for class_type in $data_classes[1..$data_classes.size]
        class_type.armor_set.push(item.id) if class_type.armor_set.include?(itemA.id)
      end
    end
    
  end
    
    
end
#==============================================================================
# END OF FILE
#==============================================================================

Feel free to use (with credit) in free projects. If anyone ever bothers with a commercial project pm me and we'll talk.

This post has been edited by mithos: Aug 25 2010, 12:40 AM


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





Go to the top of the page
 
+Quote Post
   
Mithran
post Aug 9 2010, 08:27 AM
Post #2


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Currently, the synthed items are not saved with the game data, so simply saving and loading the game will break the script. You could dump all of the $data_xxx arrays dealing with items when the file is saved, but I recommend instead saving the uniquely created items into a hash within a class that is saved already (eg., Game_System, as sort of a 'backup') and, when the save data is loaded, simply change the $data_xxx arrays at that point to reflect the items.


--------------------
Go to the top of the page
 
+Quote Post
   
mithos
post Aug 9 2010, 09:55 AM
Post #3


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




Thanks for that - knew I'd miss something, and I never tested saving dry.gif
Thanks Mithran I'll get on that tonight.


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





Go to the top of the page
 
+Quote Post
   
SowS
post Aug 9 2010, 02:55 PM
Post #4


I'm still smiling. My jaw hurts now.
Group Icon


Type: Coder
Alignment: Neutral Good




i'm just wondering why are there some lines that are commented out?

also, good thing this thread was approved even with just the script... biggrin.gif


--------------------
Go to the top of the page
 
+Quote Post
   
mithos
post Aug 9 2010, 05:25 PM
Post #5


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




The commented lines are the beginning of a naming system for created items.
Also I found a bug while testing for the one Mithran noticed - just a display error in the synthesis windows - my fault. should fix both of those today.


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





Go to the top of the page
 
+Quote Post
   
mithos
post Aug 9 2010, 05:44 PM
Post #6


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




Update: bugs all fixed - this is now usable.


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





Go to the top of the page
 
+Quote Post
   
Mithran
post Aug 11 2010, 09:44 AM
Post #7


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




I would actually perfer this to be a bit closer to the completed scripts format. The main point is that it should have some kind of unspoiler'd description at the top for everyone to read as soon as they click in, even if its only a sentence or two.

I see you fixed the saving issue by Marshalling all the data arrays dealing with items. This works, but it opens up the issue that any time you alter or add an item in the database, you'd have to start a new save in order to use the updated items. Not much of an issue, but could get annoying.

Also, you might want to double-check your probability function. Before you even hit 10, the numbers are so small that not even multiplying them by ten million will get you a whole integer to use for an id, they are so insiginficant as to become 0.0 before the multiplication even takes place. You also might want to rethink the approach of using the default database and integer ids - if you can resynth items, you essintally have an unlimited number of possible combinations and a finite number of possible ids, you will overlap at some point.


--------------------
Go to the top of the page
 
+Quote Post
   
mithos
post Aug 11 2010, 07:27 PM
Post #8


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




dry.gif sorry, forgot that completed scripts needed a description (as it's in the script tongue.gif)

awwwwwwwwww! I spent ages trying to find a method of making unique ID numbers without heading off out of range but still making the same combinations give the same number (the hardest bit of this script). I'd have sworn this worked in irb - will check the script version, or just come up with a new system (again) tongue.gif

In response to the point about starting a new save I'm in the habit of starting new every time I change something (normally as I change scripts) and didn't even consider this. I'll put a note in the description.

EDIT: just checked in irb - and you're right about the npdf. new system on its way dry.gif

This post has been edited by mithos: Aug 11 2010, 08:03 PM


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





Go to the top of the page
 
+Quote Post
   
mithos
post Aug 24 2010, 05:08 PM
Post #9


Meowthos the zombie cat!!
Group Icon


Type: Coder
Alignment: Lawful Good




well, after much thought and mucking about I suddenly got a flash of insight and remembered high school maths. So I have fixed all of the major bugs, and simplified that horrid function to do with the id's smile.gif all in all, v1.0.2 is now usable.

P.S. I know the cursor doesn't quite look right in the scene. I'm working on it tongue.gif but that isn't a major game breaker like the other bugs were.


--------------------
I've been away for a while. Here's my really quite old stuff
Spoiler:


If it's in one of my threads you can use it so long as you read this, and give me a link to any derivatives (i.e. works based off mine). Credit Mithos.
Full legal bit
(Click image for human-readable version :P )
My Stuff:
My Games:
Spoiler:

Story <60%> Mapping<20%> Art<80%> Scripts<97%> Database<50%>
The Legend of Zelda: Restoration of Time Story<20%> Mapping<0%> Art<2%> Scripts<70%> Database<0%>
Absolute Power Story<21%> Mapping<0%> Art<2%> Scripts<0%> Database<0%>

My Sprites:
My Scripts:
I support:
Spoiler:





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: 26th July 2014 - 02:19 PM

RPGMakerVX.net is an Privacy Policy, Legal.