Aldeia RPG

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Suporte ao desenvolvimento de jogos


2 participantes

    AvilaMn Simple Craft System

    avatar
    AvilaMn
    Novato
    Novato


    Mensagens : 4
    Créditos : 2

    AvilaMn Simple Craft System Empty AvilaMn Simple Craft System

    Mensagem por AvilaMn Qua Mar 09, 2022 5:17 pm

    Olá pessoal da Aldeia, hoje eu veio compartilhar um pequeno script que fiz pra treinar um pouco criação de menus.

    Simple Craft System

    Descrição: 
    O sistema serve para criar items mediante receitas.

    Instruções: 
    As configurações principais estão dentro do script mas vou explicar como criar receitas e associar os items necessários para craftar o resultado da receita.


    Criar Receitas:
    Dentro do script na secção DATA BASE poderá criar novas receitas seguindo os seguintes passos.
    Dentro de RECIPES preencha os dados necessários:

    Código:
    RECIPES = {
    # ID => [Item ID, Quantidade, Tipo, Aprendida]
      1 => [34, 3, 1, true],
    }
    ID = ID da receita
    Item ID = ID do item resultado da receita
    Quantidade = Quantidade de items resultado da receita
    Tipo = 1 : Item | 2 : Arma | 3 : Armadura
    Aprendida = true : Aprendida | false : Nao aprendida

    Craft da Receita:
    Para poder configurar quais items são necessários para a criação
    da receita dentro de CRAFT preencha os dados necesarios:
    Código:
    CRAFT = {
    # ID => [[Item ID, Quantidade, Tipo], ... Maximo 8],
      1 => [[1,2,1], [32,5,1]],
    }
    ID = ID da receita
    Item ID = ID do item necessário
    Quantidade = Quantidade do item necessário
    Tipo = 1 : Item | 2 : Arma | 3 : Armadura

    O máximo de items necessário para um Craft e 8

    Abrir o Menu Craft:
    Para abrir o menu craft, dentro de um evento crie um novo Script Call e escreva:
    open_craft_menu 

    Aprender uma Receita:
    Para aprender uma nova receita, dentro de um evento crie um novo Script Call e escreva:
    learn_recipe(ID) | ID = ID da receita

    Imagens:
    Spoiler:

    Script:
    Código:
    #==============================================================================
    # Simple Crafting System
    # Autor: AvilaMn
    # Version: 0.7
    #==============================================================================
    # Descrição:
    # Este sistema permite que os jogadores aprendam receitas e criem items com
    # as receitas aprendidas.
    #==============================================================================
    # Instruções:
    # Cole o script em cima de Main.
    # Use em uma script call de um evento:
    # open_craft_menu - Para abrir o menu de Craft
    # learn_recipe(id) - Para aprender uma receita
    #==============================================================================
    # CONFIGURAÇÃO:
    module Craft_System
      # Nome do Menu de Craft
      WINDOW_NAME = "Craft"
      # Texto da janela Result
      RESULT_WINDOW_TEXT = "Craft Result"
      # Texto de necessário para craftar
      NEEDS_TEXT = "Need to Craft"
      # Texto de quanto vai craftar
      AMOUNT_TEXT = "Amount to Craft:"
      # Texto do resultado do craft
      RESULT_TEXT = "You Crafted:"
      # Texto para quanto Nao tem receitas
      NO_RECIPES = "You don't have any recipe"
      # Ícone para o Craft Menu
      WINDOW_ICON = "038-Item07"
      # Som para craft
      CRAFT_SOUND = "044-chest01"
      #----------------------------------------------------------------------------
      # DATA BASE
      #----------------------------------------------------------------------------
      RECIPES = {
      # RECIPE_ID => [RESULT_ITEM_ID, RESULT_QUANTITY, TYPE, LEARNED]
      # TYPE : 1 = ITEM | 2 = WEAPON | 3 = ARMOR
      1 => [34, 3, 1, true],
      2 => [36, 3, 1, true],
      3 => [2, 1, 2, true],
      4 => [3, 1, 3, true],
      }
      CRAFT = {
      # RECIPE_ID => [[ITEM_NEEDED, QUANTITY, TYPE], ...] MAX 8
      1 => [[1,2,1], [32,5,1]],
      2 => [[4,2,1], [28,5,1]],
      3 => [[1,1,2], [30,5,1], [28,10,1]],
      4 => [[2,1,3], [28,10,1], [30,5,1]]
      }
      #----------------------------------------------------------------------------
      # METHODS
      #----------------------------------------------------------------------------
      # Return the item id
      def self.result_item(recipe)
        recipe = $game_party.recipes[recipe]
        return recipe[0]
      end
      # Return the result quantity of the item
      def self.result_quantity(recipe)
        recipe = $game_party.recipes[recipe]
        return recipe[1]
      end
      # Return the type of the result item
      def self.result_type(recipe)
        recipe = $game_party.recipes[recipe]
        return recipe[2]
      end
      # Return the name of the result item
      def self.name(recipe)
        type = result_type(recipe)
        case type
        when 1
          item = $data_items[Craft_System.result_item(recipe)]
        when 2
          item = $data_weapons[Craft_System.result_item(recipe)]
        when 3
          item = $data_armors[Craft_System.result_item(recipe)]
        end
        return item.name
      end
      # Return the icon name of the result item
      def self.icon(recipe)
        type = result_type(recipe)
        case type
        when 1
          item = $data_items[Craft_System.result_item(recipe)]
        when 2
          item = $data_weapons[Craft_System.result_item(recipe)]
        when 3
          item = $data_armors[Craft_System.result_item(recipe)]
        end
        return item.icon_name
      end
      # Return true if the recipe is learned or false if not
      def self.learned?(recipe)
        recipe = $game_party.recipes[recipe]
        return recipe[3]
      end
      # Return the amount of items needed to craft the recipe
      def self.how_many_to_craft?(id)
        return $game_party.craft[id].size
      end
      # Return true if the player has all the items needed to craft
      def self.has_the_items?(id, number = 1)
        items_needed = how_many_to_craft?(id)
        items_checked = 0
        craft = $game_party.craft[id]
        craft.each do |data|
          item = data[0]
          need = data[1] * number
          type = data[2]
          case type
          when 1
            have = $game_party.item_number(item)
          when 2
            have = $game_party.weapon_number(item)
          when 3
            have = $game_party.armor_number(item)
          end
          if have < need
            return false
          end
        end
        return true
      end
      # Change the learn state of the recipe to true
      def self.learn_recipe(recipe)
        $game_party.recipes[recipe][3] = true
      end
      # Craft a number of items from the recipe
      def self.craft_item(number, recipe)
        return unless has_the_items?(recipe)
        craft = $game_party.craft[recipe]
        items_needed = how_many_to_craft?(recipe)
        items_used = 0
        craft.each do |data|
          item = data[0]
          need = data[1] * number
          type = data[2]
          # Remove the items from inventory
          case type
          when 1
            $game_party.lose_item(item, need)
            items_used += 1
          when 2
            $game_party.lose_weapon(item, need)
            items_used += 1
          when 3
            $game_party.lose_armor(item, need)
            items_used += 1
          end
        end
        # Gain items crafted
        if items_used == items_needed
          r_type = result_type(recipe)
          r_quantity = result_quantity(recipe) * number
          r_item = result_item(recipe)
          case r_type
          when 1
            $game_party.gain_item(r_item, r_quantity)
          when 2
            $game_party.gain_weapon(r_item, r_quantity)
          when 3
            $game_party.gain_armor(r_item, r_quantity)
          end
        end
      end
    end
    #----------------------------------------------------------------------------
    # GAME PARTY || To include recipes learned in the saves
    #----------------------------------------------------------------------------
    class Game_Party
      # Variables
      attr_accessor :recipes
      attr_accessor :craft
      # Aliasing
      alias cs_initialize initialize
      # Constructor
      def initialize
        @recipes = Craft_System::RECIPES
        @craft = Craft_System::CRAFT
        # Initialize the rest of Game_Party
        cs_initialize
      end    
    end
    #----------------------------------------------------------------------------
    # INTERPRETER || To use just learn_recipe(id) on event calls
    #----------------------------------------------------------------------------
    class Interpreter
      def open_craft_menu
        $scene = Scene_Craft.new
      end
      def learn_recipe(id)
        Craft_System.learn_recipe(id)
      end
    end
    #----------------------------------------------------------------------------
    # Window Craft Title || Craft System Interface
    #----------------------------------------------------------------------------
    class Window_Craft_Title < Window_Base
      def initialize
        super(50, 50, 540, 50)
        @title = Craft_System::WINDOW_NAME
        @icon = Craft_System::WINDOW_ICON
        draw_title
      end
      # Draw the title on the window
      def draw_title
        if @title == nil || @title == ""
          return
        end
        bitmap = RPG::Cache.icon(@icon)      
        self.contents = Bitmap.new(self.width - 32, self.height - 32)
        self.contents.blt(6, -4, bitmap, Rect.new(0, 0, 24, 24))
        self.contents.font.color = normal_color
        self.contents.font.size = 24
        self.contents.draw_text(0, -4, 480, 24, @title, 1)
      end
    end
    #----------------------------------------------------------------------------
    # Window Craft List || Craft System Interface
    #----------------------------------------------------------------------------
    class Window_Craft_List < Window_Selectable
      def initialize
        super(50, 100, 270, 330)
        refresh
        self.index = 0
        @column_max = 1
      end
      # Return the selected recipe in the list
      def rec
        return @data[self.index]
      end
      # Refresh the window
      def refresh
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
        @data = []
        temp = []
        recipes = $game_party.recipes
        for i in 0..recipes.keys.size
          recipe = recipes[i]
          if recipe != nil && Craft_System.learned?(i)
            temp = [i, recipe]
            @data.push(temp)
          end
        end
        @item_max = @data.size
        if @item_max > 0
          self.contents = Bitmap.new(width - 32, row_max * 32)
          for i in 0...@item_max
            draw_recipe_name(i)
          end
        end
      end
      # Draw the recipe names and icons on the list
      def draw_recipe_name(index)
        recipe = @data[index][0]
        name = Craft_System.name(recipe)
        if @data.empty? == true
          name = Craft_System::NO_RECIPES
        end
        icon = Craft_System.icon(recipe)
        x = 4
        y = index * 32
        rect = Rect.new(x, y, self.width - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        bitmap = RPG::Cache.icon(icon)
        self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), 255)
        self.contents.font.size = 16
        self.contents.draw_text(x + 30, y, 212, 32, name, 0)
      end
      # Update the window result for the selected recipe in the list
      def update_help
        @help_window.draw_recipe_result(self.rec == nil ? nil : self.rec)
      end
    end
    #----------------------------------------------------------------------------
    # Window Craft Result || Craft System Interface
    #----------------------------------------------------------------------------
    class Window_Craft_Result < Window_Base
      def initialize
        super(320, 100, 270, 240)
        @number = 1
        @rec = nil
      end
      # Edit the number of craft to do
      def number(edit)
        @number = edit
      end
      # Return the recipe id
      def recipe
        return @recipe
      end
      # Refresh the window
      def refresh
        draw_recipe_result(@rec)
      end
      # Draw each item need for the recipe in a different slot
      def draw_slot(craft, slot_number)
        if slot_number > 7 || craft == nil
          return
        end
        slot = craft[slot_number]
        item_id = slot[0]
        quantity = slot[1]
        if @number > 0
          quantity = quantity * @number
        end
        type = slot[2]    
        case type
        when 1
          item = $data_items[item_id]
          have = $game_party.item_number(item_id)
        when 2
          item = $data_weapons[item_id]
          have = $game_party.weapon_number(item_id)
        when 3
          item = $data_armors[item_id]
          have = $game_party.armor_number(item_id)
        end
        bitmap = RPG::Cache.icon(item.icon_name)
        self.contents.font.size = 14
        x = slot_number % 2 * 128
        y = 84 + (slot_number / 2 * 30)
        self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24), 255)
        self.contents.draw_text(x + 28, y + 2, 102, 24, item.name + " : " + have.to_s + " / " + quantity.to_s, 0)
      end  
      # Draw the recipe result and needs on the window
      def draw_recipe_result(rec)
        if rec == nil
          return
        end
        @rec = rec
        @recipe = rec[0]
        # Title
        self.contents = Bitmap.new(self.width - 32, self.height - 32)
        self.contents.font.color = normal_color
        self.contents.font.size = 24
        self.contents.draw_text(0, 0, 238, 24, Craft_System::RESULT_WINDOW_TEXT, 1)
        # Result
        if @recipe != nil
          name = Craft_System.name(@recipe)
          type = Craft_System.result_type(@recipe)
          case type
          when 1
            item = $data_items[Craft_System.result_item(@recipe)]
          when 2
            item = $data_weapons[Craft_System.result_item(@recipe)]
          when 3
            item = $data_armors[Craft_System.result_item(@recipe)]
          end
          icon = item.icon_name
          quantity = Craft_System.result_quantity(@recipe)
          if @number > 0
            quantity = quantity * @number
          end
          bitmap = RPG::Cache.icon(icon)
          self.contents.blt(0, 28, bitmap, Rect.new(0, 0, 24, 24), 255)
          self.contents.font.size = 18
          self.contents.draw_text(32, 28, 206, 24, name + "   x " + quantity.to_s, 0)      
        end
        # Needs
        self.contents.font.size = 22
        self.contents.draw_text(0, 58, 238, 24, Craft_System::NEEDS_TEXT, 1)
        if @recipe != nil
          slots = Craft_System.how_many_to_craft?(@recipe)
          craft = $game_party.craft[@recipe]
          slots.times do |i|
            draw_slot(craft, i)
          end
        end
      end
    end
    #----------------------------------------------------------------------------
    # Window Craft Choice || Craft System Interface
    #----------------------------------------------------------------------------
    class Window_Craft_Choice < Window_Base
      def initialize
        super(320, 340, 270, 90)
        self.contents = Bitmap.new(self.width - 32, self.height - 32)
        @max = 99
        @number = 1
        refresh
      end
      # Return the number of crafts
      def number
        return @number
      end
      # Update the window
      def update
        super
        if self.active
          # Cursor right (+1)
          if Input.repeat?(Input::RIGHT) and @number < @max
            $game_system.se_play($data_system.cursor_se)
            @number += 1
            refresh
          end
          # Cursor left (-1)
          if Input.repeat?(Input::LEFT) and @number > 1
            $game_system.se_play($data_system.cursor_se)
            @number -= 1
            refresh
          end
          # Cursor up (+10)
          if Input.repeat?(Input::UP) and @number < @max
            $game_system.se_play($data_system.cursor_se)
            @number = [@number + 10, @max].min
            refresh
          end
          # Cursor down (-10)
          if Input.repeat?(Input::DOWN) and @number > 1
            $game_system.se_play($data_system.cursor_se)
            @number = [@number - 10, 1].max
            refresh
          end
        end
      end
      # Refresh the window
      def refresh
        self.contents.clear
        self.contents.font.color = normal_color
        self.contents.font.size = 24
        self.contents.draw_text(0, 0, 228, 24, Craft_System::AMOUNT_TEXT, 1)
        self.contents.draw_text(109, 32, 24, 32, @number.to_s, 2)
        self.contents.draw_text(78, 36, 24, 24, "<", 2)
        self.contents.draw_text(128, 36, 24, 24, ">", 2)
        self.cursor_rect.set(105, 32, 32, 32)
      end
    end
    #----------------------------------------------------------------------------
    # Window Craft Show Result || Craft System Interface
    #----------------------------------------------------------------------------
    class Window_Craft_SR < Window_Base
      def initialize(item, type, number, recipe)
        super(320, 340, 270, 90)
        @item = item
        @type = type
        @number = number
        @recipe = recipe
      end
      # Draw the result of the craft in the window
      def draw_result
        quantity = Craft_System.result_quantity(@recipe) * @number
        self.contents = Bitmap.new(self.width - 32, self.height - 32)
        case @type
        when 1
          item = $data_items[@item]
        when 2
          item = $data_weapons[@item]
        when 3
          item = $data_armors[@item]
        end
        bitmap = RPG::Cache.icon(item.icon_name)      
        self.contents = Bitmap.new(self.width - 32, self.height - 32)
        self.contents.blt(0, 28, bitmap, Rect.new(0, 0, 24, 24))
        self.contents.font.color = normal_color
        self.contents.font.size = 24
        self.contents.draw_text(0, 0, 228, 24, Craft_System::RESULT_TEXT, 1)
        self.contents.font.size = 24
        self.contents.draw_text(28, 28, 228, 32, item.name + "   x " + quantity.to_s, 0)
      end    
    end
    #----------------------------------------------------------------------------
    # Scene Craft || Craft System Interface
    #----------------------------------------------------------------------------
    class Scene_Craft
      # Start all windows
      def start
        @spriteset = Spriteset_Map.new
        @window_craft_title = Window_Craft_Title.new
        @window_craft_list = Window_Craft_List.new
        @window_craft_result = Window_Craft_Result.new
        @window_craft_choice = Window_Craft_Choice.new
        @window_craft_list.help_window = @window_craft_result
        @window_craft_list.active = true
        @window_craft_choice.active = false
      end
      # Main loop
      def main
        start
        Graphics.transition
        loop do
          Graphics.update
          Input.update
          update
          if $scene != self
            break
          end
        end
        Graphics.freeze
        @spriteset.dispose
        @window_craft_title.dispose
        @window_craft_list.dispose
        @window_craft_result.dispose
        @window_craft_choice.dispose
      end
      # Main update
      def update
        @window_craft_list.update
        @window_craft_result.update
        @window_craft_choice.update
        if @window_craft_list.active == true
          update_list
          return
        end
        if @window_craft_choice.active == true
          update_choice
          return
        end
        if @window_result.active == true
          update_result
          return
        end
      end
      # Window List active update
      def update_list
        if Input.trigger?(Input::B)
          $game_system.se_play($data_system.cancel_se)
          $scene = Scene_Map.new
          return
        end
        if Input.trigger?(Input::C)
          $game_system.se_play($data_system.decision_se)
          @window_craft_list.active = false
          @window_craft_choice.active = true
        end
        return
      end
      # Window Choice active update
      def update_choice
        if Input.trigger?(Input::B)
          $game_system.se_play($data_system.cancel_se)
          @window_craft_list.active = true
          @window_craft_choice.active = false
        end
        # Cursor right (+1)
        if Input.repeat?(Input::RIGHT)
          number = @window_craft_choice.number
          @window_craft_result.number(number)
          @window_craft_result.refresh
        end
        # Cursor left (-1)
        if Input.repeat?(Input::LEFT)
          number = @window_craft_choice.number
          @window_craft_result.number(number)
          @window_craft_result.refresh
        end
        # Cursdr up (+10)
        if Input.repeat?(Input::UP)
          number = @window_craft_choice.number
          @window_craft_result.number(number)
          @window_craft_result.refresh
        end
        # Cursor down (-10)
        if Input.repeat?(Input::DOWN)
          number = @window_craft_choice.number
          @window_craft_result.number(number)
          @window_craft_result.refresh
        end
        # Try to craft the items
        if Input.trigger?(Input::C)
          recipe = @window_craft_result.recipe
          number = @window_craft_choice.number
          check = Craft_System.has_the_items?(recipe, number)
          if check == true
            Craft_System.craft_item(number, recipe)
            item = Craft_System.result_item(recipe)
            type = Craft_System.result_type(recipe)
            @window_result = Window_Craft_SR.new(item, type, number, recipe)
            if Craft_System::CRAFT_SOUND != "" && Craft_System::CRAFT_SOUND != nil
              craft_se = RPG::AudioFile.new(Craft_System::CRAFT_SOUND, 80)
              $game_system.se_play(craft_se)
            end
            @window_craft_choice.active = false
            @window_craft_choice.visible = false
            @window_result.draw_result
            @window_result.active = true
            @window_craft_result.refresh
          else
            $game_system.se_play($data_system.cancel_se)
            @window_craft_choice.visible = true
          end
        end
        return
      end
      # Window Result active update
      def update_result
        if Input.trigger?(Input::C)
          $game_system.se_play($data_system.decision_se)
          @window_result.dispose
          @window_craft_choice.active = true
          @window_craft_choice.visible = true
        end
        return
      end
    end

    Traduzi só a primeira parte do script porque acredito que não e necessário traduzir o resto dele.

    Nao esqueça de botar os créditos caso usar o script.

    Espero o meu script seja de ajuda, qualquer duvida responderei nesse post.

    Valentine, Myzhuk e Sonart gostam desta mensagem

    Myzhuk
    Myzhuk
    Novato
    Novato


    Mensagens : 12
    Créditos : 0

    AvilaMn Simple Craft System Empty Re: AvilaMn Simple Craft System

    Mensagem por Myzhuk Qua Mar 23, 2022 1:25 am

    Parabéns pelo Script mano, ficou show de bola!!! Muito bacana ver coisa nova para o RPG Maker XP!!!

      Data/hora atual: Sáb Abr 27, 2024 5:32 pm