Looting System
#1
Looting System
by Thieffer
version 1.1
Jun 18 2009

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Introduction
This script allows your hero to choose, which items does he need and just take them (from any chest, for example).
How to use? The explanation is in comments. Unless you read it, you will not be able to use it in your project.


The script
Code:
#------------------------------------------------------------------
# Looting System version 1.1
# Made by Thieffer
# 12.04.2009
#------------------------------------------------------------------
# How to use?
# Make a new event on a map (for example: a chest), call script:
# $scene.loot(x, y, contents, amount)
# Instead of x:
#   $left   <--- window on the left side
#   or
#   $right  <--- window on the right side
#   or any number
# Instead of y:
#   $up     <--- window at the top
#   lub
#   $down   <--- window at the bottom
#   or any number
# Instad of contents:
#   [ID 1st thing, ID 2nd thing, etc.]
#    e.g. [001,003,012]
#    LOOK OUT! Max 6 things!
# Instead of amount:
#   [amount of 1st thing, amount of 2nd thing, etc.]
#    e.g. [3,5,13]
#     Then hero might get 3 things ID 001, 5 things ID 003, etc.
#------------------------------------------------------------------

# ...:CONFIG:...
# Window opacity. From 0 to 255.
    $LW_OPAC = 255
# Positions of window:
    $left = 100
    $right = 380
    $up = 50
    $down = 240
# END OF CONFIG

#===================================================================
# Window_LootNumber
#===================================================================
class Window_LootNumber < Window_Base
  def initialize(x, y, w, h, max)
    super(x, y, w, h)
    self.contents = Bitmap.new(width - 32, height - 32)
    @max=max
# Initial amount of each thing:
    @number=max
  end
#-------------------------------  
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 32, 32, @number.to_s, 1)
    self.cursor_rect.set(0, 0, 32, 32)
  end
  
  def number
    return @number
  end
#-------------------------------------
# ("Borrowed from Window_ShopNumber" =)
#-------------------------------------
  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
      # Cursdr 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
end

#===================================================================
# Window_LootNumber
#===================================================================
class Scene_Map
  
  alias oldupdate update
#-------------------------------
  def update
    if @loot_mode == true
      @loot_window.update
      if @loot_window.active
        update_loot
        return
      end
    end
    if @lootnumber_mode == true
        @lootnumber_window.update
        if @lootnumber_window.active
          update_lootnumber
          return
        end
    end
    oldupdate
  end
#-------------------------------
  def update_loot
    if Input.trigger?(Input::B)
      @loot_mode = false
      @gained_item0 = false
      @gained_item1 = false
      @gained_item2 = false
      @gained_item3 = false
      @gained_item4 = false
      @gained_item5 = false
      @loot_window.active = false
      @loot_window.visible = false
      return
    end
    if Input.trigger?(Input::C)
      case @loot_window.index
      when 0
        if @gained_item0 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y,64,64,@amount[0])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      when 1
        if @gained_item1 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y+32,64,64,@amount[1])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      when 2
        if @gained_item2 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y+2*32,64,64,@amount[2])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      when 3
        if @gained_item3 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y+3*32,64,64,@amount[3])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      when 4
        if @gained_item4 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y+4*32,64,64,@amount[4])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      when 5
        if @gained_item5 == true
          $game_system.se_play($data_system.buzzer_se)
        else
          @lootnumber_window = Window_LootNumber.new(@loot_window.width+@loot_window.x,@loot_window.y+5*32,64,64,@amount[5])
          @lootnumber_window.refresh
          @loot_window.active = false
          @lootnumber_window.active = true
          @lootnumber_mode = true
          $game_system.se_play($data_system.decision_se)
        end
      end
      return
    end
  end
#-------------------------------  
  def update_lootnumber
    if Input.trigger?(Input::B)
      @lootnumber_window.active = false
      @lootnumber_window.visible = false
      @loot_window.active = true
      @lootnumber_mode = false
    end
    if Input.trigger?(Input::C)
      case @loot_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[0],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[0] = @amount[0] - @lootnumber_window.number
        if @amount[0] == 0
          @gained_item0 = true
          @loot_window.disable_item(0)
        end
      when 1
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[1],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[1] = @amount[1] - @lootnumber_window.number
        if @amount[1] == 0
          @gained_item1 = true
          @loot_window.disable_item(1)
        end    
      when 2
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[2],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[2] = @amount[2] - @lootnumber_window.number
        if @amount[2] == 0
          @gained_item2 = true
          @loot_window.disable_item(2)
        end
      when 3
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[3],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[3] = @amount[3] - @lootnumber_window.number
        if @amount[3] == 0
          @gained_item3 = true
          @loot_window.disable_item(3)
        end
      when 4
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[4],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[4] = @amount[4] - @lootnumber_window.number
        if @amount[4] == 0
          @gained_item1 = true
          @loot_window.disable_item(4)
        end
      when 5
        $game_system.se_play($data_system.decision_se)
        $game_party.gain_item(@loot_items[5],@lootnumber_window.number)
        @lootnumber_mode = false
        @lootnumber_window.visible = false
        @lootnumber_window.active = false
        @loot_window.active = true
        @amount[5] = @amount[5] - @lootnumber_window.number
        if @amount[5] == 0
          @gained_item1 = true
          @loot_window.disable_item(5)
        end
      end
      return
    end
  end
  
#-----------------------------------------------------------------
# Displaying a window on a map
# x - X-coordinate
# y - Y-coordinate
# loot_items - an array which contains items' IDs
# amount - an array which contains an amount of items
#-----------------------------------------------------------------
  def loot(x,y,loot_items,amount)
    @amount = amount
    @loot_items = loot_items
    @itemss = []
    for i in 0..(@loot_items.size-1)
      @itemss << $data_items[@loot_items[i]].name
    end
    @loot_window = Window_Command.new(160, @itemss)
    @loot_window.x = x
    @loot_window.y = y
    @loot_window.active = true
    @loot_window.visible = true
    @loot_mode = true
    @loot_window.back_opacity = $LW_OPAC
  end
end  
#-----------------------------------------------------------------


I hope you enjoy it ;)
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Difficulity Level System Ekhart 0 2,637 03-14-2008, 01:00 PM
Last Post: Ekhart
  Dragon Quest VII Class Changing System Sephirothtds 0 2,760 11-15-2007, 01:00 PM
Last Post: Sephirothtds
  Map Stats and Info System Dubealex 0 2,796 10-19-2007, 01:00 PM
Last Post: Dubealex
  Spell Tablet System GubiD 0 2,891 08-25-2007, 01:00 PM
Last Post: GubiD
  Orb Based Skill System El Conductor 0 2,603 07-29-2007, 01:00 PM
Last Post: El Conductor
  Party Deleting System Ekhart 0 2,640 07-05-2007, 01:00 PM
Last Post: Ekhart
  Class Stat Bonus System Shinami 0 2,544 05-20-2007, 01:00 PM
Last Post: Shinami
  MATERIA SYSTEM with AP illustrationism 0 2,887 05-06-2007, 01:00 PM
Last Post: illustrationism
  MMORPG Leveling System Lettuce 0 2,682 12-23-2006, 01:00 PM
Last Post: Lettuce
  Skill Level System Leon Westbrooke 0 2,505 09-16-2006, 01:00 PM
Last Post: Leon Westbrooke



Users browsing this thread: 2 Guest(s)