I need a RMVX script rewritten for RMVX Ace.

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I found a script i want to use for my Rpg maker VX Ace game but it's written in VX. I need someone to rewrite it for Ace for me. 


The script is a crafting script that uses a 3x3 grid to mix items like Minecraft.

#==============================================================================#
#                              • CRAFTING SYSTEM •                             #
#==============================================================================#
# Autor: Sidhenidon                                                            #
# Versão: 1.1                                                                  #
#==============================================================================#
module Craft
  
  Vocab = {}
  Vocab['remove'] = '< Remover >' #texto que aparece na opção de remover.
  Vocab['result'] = 'Resultado'
  
  Results = []  #Não altere nem apague.
  Comb = []     #Não altere nem apague.
  
  ShowResult = true #Mostrar o que a combinação atual gera antes de confirmar?
    Smoothness = 10 #Suavidade do movimento do grid ao formar um item
  
  StackX = 29 #Quando mais de um item for criado, qual distância X entre cada ícone
  StackY = 0 #                                                   Y
  
#==============================================================================#
#                        LISTA DE COMBINAÇõES                                  #
#==============================================================================#
  # Machado #
  altura  = 3              #altura do item. modifique à vontade.
  largura = 2              #largura do item. modifique à vontade.
  combinacao = ['i2','i2', #forme um retângulo ou quadrado com a
                 nil,'i8', #altura e largura acima.
                 nil,'i8'] 
  Results.push(['w1'])     #itens que são recebidos. Separe por vírgulas.
  Comb.push([largura,altura,combinacao]) #não altere nem apague.
  
  # VARETA #
  altura  = 2              #altura do item. modifique à vontade.
  largura = 1              #largura do item. modifique à vontade.
  combinacao = ['i1',      #forme um retângulo ou quadrado com a
                'i1']      #altura e largura acima.
  Results.push(['i8','i8'])
  Comb.push([largura,altura,combinacao]) #não altere nem apague.
  
  # CORTAR ALOE #
  altura  = 1              
  largura = 2              
  combinacao = ['i10','w2'] 
  Results.push(['w2','i11','i12'])
  Comb.push([largura,altura,combinacao])
  
  # CORTAR ALOE INVERTIDO #
  altura  = 1              
  largura = 2              
  combinacao = ['w2','i10'] 
  Results.push(['w2','i11','i12'])
  Comb.push([largura,altura,combinacao])
  
  # POÇÃO COM RAIZ DE ALOE #
  altura  = 2              
  largura = 1              
  combinacao = ['i11','i14'] 
  Results.push(['i15'])
  Comb.push([largura,altura,combinacao])
  
  # POÇÃO ERRADA #
  altura  = 2              
  largura = 1              
  combinacao = ['i12','i14'] 
  Results.push(['i16'])
  Comb.push([largura,altura,combinacao])
  
  # VARA #
  altura  = 3              
  largura = 3              
  combinacao = ['i8', nil,nil ,
                'i5','i8',nil ,
                'i5',nil ,'i8',
  ] 
  Results.push(['w3'])
  Comb.push([largura,altura,combinacao])
  
  # DECOMPOSIÇÃO DE ROUPA #
  altura  = 1              
  largura = 1              
  combinacao = ['a14'] 
  Results.push(['i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5'])
  Comb.push([largura,altura,combinacao])
  
  # POÇÃO ERRADA #
  altura  = 2              
  largura = 1              
  combinacao = ['i17','i14'] 
  Results.push(['i16'])
  Comb.push([largura,altura,combinacao])
  
  # PÃO #
  altura  = 2              
  largura = 1              
  combinacao = ['i18','i14'] 
  Results.push(['i19'])
  Comb.push([largura,altura,combinacao])
  
  # POÇÃO ERRADA #
  altura  = 2              
  largura = 1              
  combinacao = ['i19','i14'] 
  Results.push(['i16'])
  Comb.push([largura,altura,combinacao])
  
  
#==============================================================================#
#                       FIM DA LISTA DE COMBINAÇõES                            #
#==============================================================================#
end


class Scene_Crafting < Scene_Base
  
  def initialize(gridsize=3)
    @grid = gridsize
    @in_use = {}
  end
  
  def start
    super
    @item_window = Window_CraftItem.new(0, 416, 544, 136)
    @item_window.active = false
    @item_window.opacity = 0
    @craft_window = Window_Craft.new(@grid)
    @craft_window.opacity = 0
    @step = 0
    @pop = nil
    @pop_sprite = Sprite.new
    @pop_sprite2 = Sprite.new
    @preview = Sprite.new if Craft::ShowResult
    update_showresult if Craft::ShowResult
    create_menu_background
  end
  
  def refresh_in_use
    @in_use = {}
    @craft_window.craft.each{|item|
    @in_use[item] = 0 if @in_use[item] == nil
    @in_use[item] += 1}
  end
  
  def create_menu_background
    @menuback_sprite = Sprite.new
    @menuback_sprite.bitmap = $game_temp.background_bitmap
    @menuback_sprite.bitmap.blt(0,0,Cache.system('Craft_BG'),Rect.new(0,0,544,416))
    @menuback_sprite.z = @craft_window.z-1
    update_menu_background
  end
  
  def terminate
    super
    dispose_menu_background
    @item_window.dispose
    @craft_window.dispose
    @pop_sprite.dispose
    @pop_sprite2.dispose
    @preview.dispose if Craft::ShowResult
  end


  def create_pop_sprites
    @pop_sprite.bitmap = Bitmap.new(@craft_window.width-32,@craft_window.height-32)
    @pop_sprite.bitmap.blt(0,0,Graphics.snap_to_bitmap,Rect.new(@craft_window.x+16,@craft_window.y+16,@craft_window.width-32,@craft_window.height-32))
    @pop_sprite.ox = (@pop_sprite.width)/2
    @pop_sprite.oy = (@pop_sprite.height)/2
    @pop_sprite.x,@pop_sprite.y = (@craft_window.x+16)+(@craft_window.width-32)/2,(@craft_window.y+16)+(@craft_window.height-32)/2
    @pop_sprite.z = 9998
    
    @pop_sprite2.bitmap = Bitmap.new(29+(@pop.size-1)*Craft::StackX,28+(@pop.size-1)*Craft::StackY)
    idx = 0
    for item in @pop
    @pop_sprite2.bitmap.blt(0+idx*Craft::StackX,0+idx*Craft::StackY,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
    @pop_sprite2.bitmap.blt(2+idx*Craft::StackX,2+idx*Craft::StackY,Cache.system('Iconset'),Rect.new(item.icon_index % 16 * 24, item.icon_index / 16 * 24, 24, 24))
    idx += 1
    end
    @pop_sprite2.ox = @pop_sprite2.width/2
    @pop_sprite2.oy = @pop_sprite2.height/2
    @pop_sprite2.x = @pop_sprite.x
    @pop_sprite2.y = @pop_sprite.y
    @pop_sprite2.z = 9999
    @pop_sprite2.opacity = 0
  end
  
  def update
    super
    update_menu_background
    update_inventory_position
    @craft_window.update
    if @item_window.active
      @item_window.update
      update_item_selection
    elsif @craft_window.active
      update_craft_selection
    elsif @pop != nil
      case @step
      when 0
        shine ? @step = 1 : @step = 0
      when 1
        reduce ? @step = 2 : @step = 1
      when 2
        appear ? @step = 3 : @step = 2
      when 3
        Graphics.wait(60)
        $scene = Scene_Map.new
      end
    end
  end
  
  def update_inventory_position
    if @item_window.active
      @item_window.y = [@item_window.y-[(280-@item_window.x).abs/Craft::Smoothness,1].max,280].max
    else
      @item_window.y = [@item_window.y+[(416-@item_window.y).abs/Craft::Smoothness,1].max,416].min
    end
  end
  
  def shine
     @pop_sprite.tone = Tone.new(@pop_sprite.tone.red+2,@pop_sprite.tone.green+2,@pop_sprite.tone.blue+2)
     @preview.opacity -= 4 if Craft::ShowResult
     @pop_sprite.x = [@pop_sprite.x+[(@pop_sprite.x-272).abs/Craft::Smoothness,1].max,272].min
     @pop_sprite2.x = @pop_sprite.x
     return true if @pop_sprite.tone.red == 255
     return false
   end
   
  def reduce
     sizex = @pop_sprite.zoom_x
     sizey = @pop_sprite.zoom_y
     if @pop_sprite.width*@pop_sprite.zoom_x > @pop_sprite2.width
       @pop_sprite.zoom_x  = (@pop_sprite.zoom_x-0.05)
     end
     if @pop_sprite.width*@pop_sprite.zoom_x < @pop_sprite2.width
       @pop_sprite.zoom_x  = (@pop_sprite.zoom_x+0.05)
     end
     if @pop_sprite.height*@pop_sprite.zoom_y > @pop_sprite2.height
       @pop_sprite.zoom_y  = (@pop_sprite.zoom_y-0.05)
     end
     if @pop_sprite.height*@pop_sprite.zoom_y < @pop_sprite2.height
       @pop_sprite.zoom_y  = (@pop_sprite.zoom_y+0.05)
     end
     return true if sizex == @pop_sprite.zoom_x and sizey == @pop_sprite.zoom_y
     return false
   end
   
  def appear
    @pop_sprite2.opacity += 3
    @pop_sprite.opacity -= 3
    return true if @pop_sprite2.opacity == 255
    return false
  end
  
  def update_craft_selection
    if Input.trigger?(Input::B)
      if compare_crafting(@grid)
        Sound.play_decision
        create_pop_sprites
        @item_window.active = false
        @craft_window.active = false
        @craft_window.visible = false
      else
        Sound.play_cancel
        $scene = Scene_Map.new
      end
    elsif Input.trigger?(Input::C)
      Sound.play_decision
      @item_window.active = true
      @craft_window.active = false
    end
  end
  
  def update_item_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @craft_window.active = true
      @item_window.active = false
    elsif Input.trigger?(Input::C)
      refresh_in_use
      @in_use[@item_window.item] = 0 if @in_use[@item_window.item] == nil
      if ($game_party.item_number(@item_window.item)-@in_use[@item_window.item] > 0) or @item_window.item == nil
        Sound.play_decision
        @craft_window.craft[@craft_window.index] = @item_window.item
        @craft_window.refresh
        update_showresult if Craft::ShowResult
      else
        Sound.play_cancel
      end
        @craft_window.active = true
        @item_window.active = false
    end
  end
  
  def update_showresult
    preview = compare_crafting(@grid,true)
    case preview
    when false
      draw_preview(nil)
    when Integer
      draw_preview(preview)
    end
  end
  
  def draw_preview(idx)
    @preview.dispose if !@preview.disposed?
    if idx == nil
      @preview = Sprite.new
      @preview.bitmap = Bitmap.new(29,28)
      @preview.bitmap.blt(0,0,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
      @preview.x = 257+@craft_window.width/2
      @preview.y = (@craft_window.y+@craft_window.height/2)-(@preview.height/2)
      @preview.z = 9999
      return
    end
    itemlist = []
      for item in Craft::Results[idx]
        type = item.scan(/[iwa]/)[0]
        case type
        when 'i'
          itemlist.push($data_items[item.scan(/[0-9]+/)[0].to_i])
        when 'a'
          itemlist.push($data_armors[item.scan(/[0-9]+/)[0].to_i])
        when 'w'
          itemlist.push($data_weapons[item.scan(/[0-9]+/)[0].to_i])
        end
      end
      @preview = Sprite.new
      @preview.bitmap = Bitmap.new(29+(itemlist.size-1)*Craft::StackX,28+(itemlist.size-1)*Craft::StackY)
      index = 0
      for item in itemlist
        @preview.bitmap.blt(0+index*Craft::StackX,0+index*Craft::StackY,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
        @preview.bitmap.blt(2+index*Craft::StackX,2+index*Craft::StackY,Cache.system('Iconset'),Rect.new(item.icon_index % 16 * 24, item.icon_index / 16 * 24, 24, 24))
        index += 1
      end
    @preview.x = 257+@craft_window.width/2
    @preview.y = (@craft_window.y+@craft_window.height/2)-(@preview.height/2)
    @preview.z = 9999
  end
  
  def compare_crafting(gridsize,preview=false)
    @result = Array.new
    @craft_window.craft.each{|item|
    case item
    when RPG::Item
      @result.push("i#{item.id}")
    when RPG::Armor
      @result.push("a#{item.id}")
    when RPG::Weapon
      @result.push("w#{item.id}")
    else
      @result.push(nil)
    end
    }
    for combination in Craft::Comb
      next if combination[0] > @grid or combination[1] > @grid
      table = []
      for x in 0..@grid-1
        array = []
        for y in 0..@grid-1
          array.push(@result[x*@grid+y])
        end
        table.push(array)
      end
      check = []
      for x in 0..combination[1]-1
        array = []
        for y in 0..combination[0]-1
          array.push(combination[2][x*combination[0]+y])
        end
        check.push(array)
      end
      checkline = 0
      checkitem = 0
      for line in 0..table.size-1
        for itam in 0..table[line].size-1
          if table[line][itam] == (check[checkline].is_a?(Array) ? check[checkline][checkitem] : nil)
            next if check[checkline] == nil or table[line] == nil
            next if check.size > table.size-line
            next if check[checkline].size > table[line].size-itam
            successcomb = Array.new
            y = line
            x = itam
            checkline = 0
            checkitem = 0
            loop do
              if (table[y].is_a?(Array) ? table[y][x] : nil) == (check[checkline].is_a?(Array) ? check[checkline][checkitem] : nil)                 
                if x >= @grid-1
                  if y >= @grid-1
                    successcomb.push([y,x])
                    for y1 in 0..@grid-1
                      for x1 in 0..@grid-1
                        if !successcomb.include?([y1,x1])
                          if table[y1][x1] != nil
                            return false
                          end
                        end
                      end
                    end
                    if preview
                      return Craft::Comb.index(combination)
                    else
                      return craftit(Craft::Comb.index(combination))
                    end
                    break
                  else
                    successcomb.push([y,x])# unless (y > check.size-1 or x > check[checkline].size-1)
                    y += 1 ; x = itam
                    checkline += 1 ; checkitem = 0
                  end
                else
                  successcomb.push([y,x])# unless (y > check.size-1 or x > check[checkline].size-1)
                  x += 1 ; checkitem += 1
                end
              else
                break
              end
            end
          end
        end
      end
    end
      return false
  end
  
  def craftit(idx)
    @pop = []
      for item in Craft::Results[idx]
        type = item.scan(/[iwa]/)[0]
        case type
        when 'i'
          $game_party.gain_item($data_items[item.scan(/[0-9]+/)[0].to_i],1)
          @pop.push($data_items[item.scan(/[0-9]+/)[0].to_i])
        when 'a'
          $game_party.gain_item($data_armors[item.scan(/[0-9]+/)[0].to_i],1)
          @pop.push($data_armors[item.scan(/[0-9]+/)[0].to_i])
        when 'w'
          $game_party.gain_item($data_weapons[item.scan(/[0-9]+/)[0].to_i],1)
          @pop.push($data_weapons[item.scan(/[0-9]+/)[0].to_i])
        end
      end
      for item in @craft_window.craft
        $game_party.lose_item(item,1)  
      end
      return true
  end
end


class Window_Craft < Window_Selectable
  attr_accessor :craft


  def initialize(gridsize)
    super(272-(gridsize*29+32)/2-(Craft::ShowResult ? (gridsize*29+32)/2 : 0), 203-(gridsize*29*3/4), gridsize*29+32, gridsize*29+32)
    @column_max = gridsize
    self.index = 0
    @craft = Array.new
    for i in 1..(gridsize*gridsize)
      @craft.push(nil)
    end
    refresh
  end


  def item
    return @data[self.index]
  end


  def refresh
    @data = []
    for item in @craft
      @data.push(item)
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  
  def item_rect(index)
    rect = Rect.new(0, 0, 0, 0)
    rect.width = 29
    rect.height = 28
    rect.x = index % @column_max * (rect.width)
    rect.y = index / @column_max * 28
    return rect
  end


  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    self.contents.blt(rect.x,rect.y,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
    if item != nil
      rect.width -= 4
      draw_icon(item.icon_index, rect.x+2, rect.y+2, true)
    end
  end
end


class Window_CraftItem < Window_Selectable
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @column_max = 2
    self.index = 0
    refresh
  end
  def item
    return @data[self.index]
  end
  def include?(item)
    return false if item == nil
    if $game_temp.in_battle
      return false unless item.is_a?(RPG::Item)
    end
    return true
  end
  def enable?(item)
    return true
  end
  def refresh
    self.contents.fill_rect(0,0,self.width,self.height, Color.new(0,0,0,130))
    @data = []
    @data.push(nil)
    for item in $game_party.items
      @data.push(item)
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      number = $game_party.item_number(item)
      enabled = enable?(item)
      rect.width -= 4
      #self.contents.fill_rect(rect.x+2,rect.y+2,rect.width-4,rect.height-4, Color.new(0,0,0,180))
      draw_item_name(item, rect.x, rect.y, enabled)
      self.contents.draw_text(rect, sprintf(":%2d", number), 2)
    else
      #self.contents.fill_rect(rect.x+2,rect.y+2,rect.width-4,rect.height-4, Color.new(0,0,0,180))
      self.contents.draw_text(rect, Craft::Vocab['remove'], 1)
    end
  end
  def update_help
    @help_window.set_text(item == nil ? "" : item.description)
  end
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

So trying our Ultra Mode 7 was a bad idea. How do I not include this in my game? XD
Stumbled upon an RPG Maker game on Steam called 'Boobs vs Zombies' while looking for a zombie themed fantasy RTS. lol
There's a new born faction in my country called "Sunda Empire" claiming they have right to rule over the earth and sun... I don't know what to feel...
Quon is watching you
Quon blessed your good efforts
I have tried, several times to understand how Markiplier is popular. You can't deny his popularity. I can only get through a few minutes of his vids, though. He's cringier than ANY cringe comp I've ever watched. When I was a kid, if you acted like that, 0 friends and 100% no dates for you. Times have changed XD

Forum statistics

Threads
93,545
Messages
913,375
Members
123,077
Latest member
Zetheir
Top