Help - Search - Members - Calendar
Full Version: Item Popup / Item Found (Includes Demo)
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
Eccid
Item Popup / Item Found
v.1.0
OriginalWij / Khai / Eccid


INTRO
I got both of these scripts a long time ago and really liked them, but they had a good deal of conflicts with each other, and a few of my other scripts. I riginally was just going to mod them for my game, but decided to clean them up and re-release them as a completed script here. Enjoy! Make sure to give credit to all three authors!!

[Show/Hide] Screenshots:
I wasn't sure the best way to show how the script works, so here's just what it looks like.



All information is at the top of the "Definitions" script below:

Definitions:
Insert this script above "main", and above the second part of the script.
[Show/Hide] Definitions
CODE
#==============================================================================
# Script   : Item Popup / Item Found
#------------------------------------------------------------------------------
# Authors  : OriginalWij - Item Pop-Up
#          : Khai        - Item Found (http://ktbanh.wordpress.com/)
#          : Eccid       - Item Popup/Item Found Integration and Modification
#------------------------------------------------------------------------------
# Versions : 1.0         - Item Pop-Up (Inital Release)
#          : 1.3         - Item Found  (Final Release of Version Used)
#          : 1.0         - Item Popup/Item Found Integration and Modification
#                          (Initial Release)
#==============================================================================
# Description :
#  - This script (when both scripts are activated) makes the item icon pop out
#    from the chest and calls a box containing the item icon (when activated)
#    along with the number recieved and name of an item, when a chest is
#    specified by a comment box containing the "CHEST_WORD"
#------------------------------------------------------------------------------
# Features :
#  - Easy to use
#  - No call scripts needed to add items, uses the program default commands
#  - Customizable call word used to specify chests
#  - Almost completely customizable
#  - Works when adding or subtracting items
#------------------------------------------------------------------------------
# How to Install :
#  - Place both parts of the script in the "Materials" section above main
#  - If you already have either script, it is reccomended you delete them
#    or they could cause compatability issues
#------------------------------------------------------------------------------
# How to Use :
#  - Make a comment at the beginning of your chest event containing what is
#    set as the CHEST_WORD without the quotations around it ("CHEST" by
#    default)
#  - Use the add item, weapon, armor or gold commands from the event commands
#    menu in the editor
#  - When adding multiple items, insert a WAIT(1) between them
#  - To make a message stating the chest is empty, make a comment containing
#    the EMPTY_CHEST_WORD ("EMPTY" by default)
#    NOTE: This is useful to put in the last page of a chest event (after
#            the chest has been opened)
#------------------------------------------------------------------------------
#  - As well, you may use the item found window on its own by using the
#    script command "chest(type, index, amount, true)" (without quotations)
#    - type   (0-3)
#       0 = Gold
#       1 = Item
#       2 = Weapon
#       3 = Armor
#
#    - index  (Item Number)
#
#    - amount (Number Recieved)
#
#    - true   (leave it true, it specifies the script called by an event)
#
#  - Note: Using the call script also puts the item in your inventory,
#          so there is no need to add it manually
#------------------------------------------------------------------------------
# Compatability Issues :
#  - Anaryu's Particle Engine VX no longer seems to be affected by nor affects
#    either of these script
#------------------------------------------------------------------------------
# Terms and Conditions :
#  - Free to use as long as authors are credited
#------------------------------------------------------------------------------
# Credits :
#  - OriginalWij (Item Pop-Up)
#  - Khai        (Item Found)(http://ktbanh.wordpress.com/)
#  - Eccid       (Item Popup/Item Found Integration and Modification)
#==============================================================================
#  - PM me if you can think of more ways to make this customizable
#==============================================================================
#------------------------------------------------------------------------------
#==============================================================================
# �–� CUSTOMIZATION AREA �–�
#------------------------------------------------------------------------------
# Which scripts to use
USE_ITEM_POPUP = true
USE_ITEM_FOUND = true # You could set them both to false... but why?
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#[ITEM POPUP DEFINITIONS]
# "Gold" icon index
GOLD_ICON = 205
# Word used in a comment to specify an event is a chest
CHEST_WORD = "CHEST"
# Word used in a comment to specify an event is an empty chest
EMPTY_CHEST_WORD = "EMPTY"
# Choose if an icon pops-up for each multiple of the same item
MULTIPLE_ITEMS = false
# Choose to play sound on item popup
PLAY_POP_UP_SOUND = false
# Item Popup sound Settings
POPUP_SOUND = "Chime2"
POPUP_SOUND_VOLUME = 100
POPUP_SOUND_PITCH = 150  
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#[ITEM FOUND WINDOW DEFINITIONS]
# Message to be shown when an item is gained
# (String states: [number recieved] [item name] MSG_ADD ex. 3 Potions Recieved)
MSG_ADD = "Recieved"
# Message to be shown when an item is lost
# (String states: [number removed] [item name] MSG_REMOVE ex. 25 Cards Lost)
MSG_REMOVE = "Lost"
# Message to be shown when a chest is empty
MSG_EMPTY = "The chest is empty"
# Windowskin to be used for the item found window
MSG_WINDOWSKIN = "Window_Classic"
# Text color number (0-31) corresponding to the color library in the
# bottom right-hand corner of the windowskin used
MSG_COLOR = 14
# Use an icon for gold in the icon window instead of a symbol("G" by default)
USE_GOLD_ICON = true
# Icon to use if above is true
GOLD_ICON = 205
# Don't show the icon window next to the item found window
NO_ICON_WINDOW = false
# Choose to play sound on item found window
PLAY_FOUND_WINDOW_SOUND = true
# Item Found sound settings
ITEM_GAIN = "Saint5"
GOLD_GAIN = "Saint5"
ITEM_REMOVE = "Saint5"
GOLD_REMOVE = "Saint5"
FOUND_SOUND_VOLUME = 100
FOUND_SOUND_PITCH = 100
#------------------------------------------------------------------------------
# �–� END OF CUSTOMIZATION AREA �–�
#==============================================================================
CHEST_DATA = []#<-DO NOT ALTER OR DELETE!(Or you'll regret it. HINT:Papa Smurf)
#==============================================================================


Item Popup / Item Found:
Insert Below "Definitions" and above "Main"
[Show/Hide] Item Pop-up/Item Found
CODE
#==============================================================================
# Chest Item Pop-Up
#------------------------------------------------------------------------------
# Original Author  : OriginalWij
# Version          : 1.0
#==============================================================================
# Game_Interpreter
#==============================================================================
class Game_Event < Game_Character
alias chest_update update
def update
chest_update
$event = @event
end
end

class Game_Interpreter
  #--------------------------------------------------------------------------
  # Get X
  #--------------------------------------------------------------------------
  def get_x
    events = $game_map.events
    x_coord = events[@event_id]
    return x_coord.screen_x
  end
  #--------------------------------------------------------------------------
  # Get Y
  #--------------------------------------------------------------------------
  def get_y
    events = $game_map.events
    y_coord = events[@event_id]
    return y_coord.screen_y
  end
  #--------------------------------------------------------------------------
  # Change Gold
  #--------------------------------------------------------------------------
  def command_125
    value = operate_value(@params[0], @params[1], @params[2])
    $game_party.gain_gold(value)
    x_value = get_x
    y_value = get_y
    for i in 0...@list.size
    $scene = Chest_Popup.new(x_value, y_value, 0, value, 1) if @list[i].code == 108 and @list[i].parameters == [CHEST_WORD]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # Change Items
  #--------------------------------------------------------------------------
  def command_126
    value = operate_value(@params[1], @params[2], @params[3])
    $game_party.gain_item($data_items[@params[0]], value)
    $game_map.need_refresh = true
    x_value = get_x
    y_value = get_y
    for i in 0...@list.size
    $scene = Chest_Popup.new(x_value, y_value, 1, value, @params[0]) if @list[i].code == 108 and @list[i].parameters == [CHEST_WORD]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # Change Weapons
  #--------------------------------------------------------------------------
  def command_127
    value = operate_value(@params[1], @params[2], @params[3])
    $game_party.gain_item($data_weapons[@params[0]], value, @params[4])
    x_value = get_x
    y_value = get_y
    for i in 0...@list.size
    $scene = Chest_Popup.new(x_value, y_value, 2, value, @params[0]) if @list[i].code == 108 and @list[i].parameters == [CHEST_WORD]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # Change Armor
  #--------------------------------------------------------------------------
  def command_128
    value = operate_value(@params[1], @params[2], @params[3])
    $game_party.gain_item($data_armors[@params[0]], value, @params[4])
    x_value = get_x
    y_value = get_y
    for i in 0...@list.size
    $scene = Chest_Popup.new(x_value, y_value, 3, value, @params[0]) if @list[i].code == 108 and @list[i].parameters == [CHEST_WORD]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # Empty Chest
  #--------------------------------------------------------------------------
  alias empty_chest_execute_command execute_command
  def execute_command
    for i in 0...@list.size
    chest(-1,0,0,false) if @list[i].code == 108 and @list[i].parameters == [EMPTY_CHEST_WORD]
    end
    empty_chest_execute_command
  end

end
#==============================================================================
# Item Popup Window
#==============================================================================

class Item_Popup_Window < Window_Base
  #--------------------------------------------------------------------------
  # Initialize
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(0, 0, 544, 416)
    self.opacity = 0
    @x = x - 26
    @y = y - 56
  end
  #--------------------------------------------------------------------------
  # Pop-Up
  #--------------------------------------------------------------------------
  def pop_up(icon_index, x, y)
    self.contents.clear
    draw_icon(icon_index, x, y, true)
  end
end

#==============================================================================
# Chest_Popup
#==============================================================================

class Chest_Popup < Scene_Base
  #--------------------------------------------------------------------------
  # Initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, type, amount, index)
    @x = x
    @y = y
    @amount = amount
    $iftype=type;$ifamount=amount;$ifindex=index
    case type
    when 0 # gold
      @amount = 1
      @icon_index = GOLD_ICON
    when 1 # items
      @icon_index = $data_items[index].icon_index
    when 2 # weapons
      @icon_index = $data_weapons[index].icon_index
    when 3 # armors
      @icon_index = $data_armors[index].icon_index
    end
  end
  #--------------------------------------------------------------------------
  # Start
  #--------------------------------------------------------------------------
  def start
    create_background
    @popup_window = Item_Popup_window.new(@x, @y)
  end
  #--------------------------------------------------------------------------
  # Terminate
  #--------------------------------------------------------------------------
  def terminate
    @popup_window.dispose
    @menuback_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # Return Scene
  #--------------------------------------------------------------------------
  def return_scene(type,index,amount,popup)
    $scene = Scene_Map.new
    if USE_ITEM_FOUND;chest(type,index,amount,popup);end
  end
  #--------------------------------------------------------------------------
  # Update
  #--------------------------------------------------------------------------
  def update
    super
    @popup_window.update
    @menuback_sprite.update
    if USE_ITEM_POPUP;do_popup;else;return_scene($iftype,$ifindex,$ifamount,false);end
  end
  #--------------------------------------------------------------------------
  # Update Basic
  #--------------------------------------------------------------------------
  def update_basic
    Graphics.update              
    Input.update                  
    $game_map.update              
  end
  #--------------------------------------------------------------------------
  # Wait
  #--------------------------------------------------------------------------
  def wait(duration)
    for i in 0...duration
      update_basic
    end
  end
  #--------------------------------------------------------------------------
  # Create Background
  #--------------------------------------------------------------------------
  def create_background
    @menuback_sprite = Sprite.new
    @menuback_sprite.bitmap = $game_temp.background_bitmap
    @menuback_sprite.update
  end
  #--------------------------------------------------------------------------
  # Do Pop-Up
  #--------------------------------------------------------------------------
  def do_popup
    Audio.se_play("Audio/SE/#{POPUP_SOUND}", POPUP_SOUND_VOLUME, POPUP_SOUND_PITCH) if PLAY_POP_UP_SOUND
    if MULTIPLE_ITEMS
    for i in 1..@amount
      for i in 0..4
        @popup_window.pop_up(@icon_index, @x - 26, @y - (i * 4) - 48)
        @popup_window.update
        wait(2)
      end
      wait(5) if i != @amount
    end
    else
      for i in 0..4
        @popup_window.pop_up(@icon_index, @x - 26, @y - (i * 4) - 48)
        @popup_window.update
        wait(2)
      end
      wait(5) if i != @amount
    end
    return_scene($iftype,$ifindex,$ifamount,false)
  end
end
#==============================================================================
#------------------------------------------------------------------------------
#==============================================================================
# Item_Found
#------------------------------------------------------------------------------
# Original Author  : Khai(http://ktbanh.wordpress.com/)
# Version          : 1.3
#==============================================================================
class Chest_Window_Base < Window_Base
  def initialize
    super(0, 0, CHEST_DATA[0], WLH + 32)
    self.windowskin = Cache.system(MSG_WINDOWSKIN)
  end
#------------------------------------------------------------------------------
  def set_text(text, align = 1)
    if text != @text
      @text = text
      self.contents.clear
      self.contents.font.color = text_color(MSG_COLOR)
      self.contents.draw_text(0, 0, self.width - 32, WLH, text, align)
    end
  end
end
#------------------------------------------------------------------------------
class Chest_Window_Addon < Window_Base
  def initialize(index,type)
    super(0, 0, CHEST_DATA[1], WLH + 32)
    self.windowskin = Cache.system(MSG_WINDOWSKIN)
    if USE_GOLD_ICON and type==3;type=4;end
    self.draw_icon($data_items[index].icon_index, 0, 0, true)if type == 0
    self.draw_icon($data_armors[index].icon_index, 0, 0, true)if type == 1
    self.draw_icon($data_weapons[index].icon_index, 0, 0, true)if type == 2
    self.draw_icon(GOLD_ICON, 0, 0, true) if type == 4
    self.contents.font.color = text_color(MSG_COLOR)
    self.contents.draw_text(6, 0, CHEST_DATA[1], WLH, $data_system.terms.gold) if type == 3
  end
end
#------------------------------------------------------------------------------
def chest(type,index,value,mapcall)
case type;when 0;type=3;when 1;type=0;when 2;type=2;when 3;type=1;end
if mapcall==true;case type;when 0;$game_party.gain_item($data_items[index],value)
when 1;$game_party.gain_item($data_armors[index],value)
when 2;$game_party.gain_item($data_weapons[index],value)
when 3;$game_party.gain_gold(value);end;end
$scene = Scene_Chest.new(type,index,value)
end
#------------------------------------------------------------------------------
class Scene_Chest < Scene_Base
  def initialize(type,index,num)
    @index = index;@setting = type;@num = num;@spriteset = Spriteset_Map.new
    CHEST_DATA[1] = 56
    if USE_GOLD_ICON;if type == 3; CHEST_DATA[1] = 56;end
    else;if type == 3; CHEST_DATA[1] = width_set($data_system.terms.gold);end;end
    @khai_icon_window = Chest_Window_Addon.new(index, type)
    case type;when 0;@type=$data_items[@index].name
    when 1;@type=$data_armors[@index].name
    when 2;@type=$data_weapons[@index].name
    when 3;@type=Vocab::gold;else;@text=MSG_EMPTY;@khai_icon_window.width=0;end
    #Add Type(0-2) item/armors/weapons
    @text = "#{num} #{@type}s #{MSG_ADD}" if type<3&&type>-1&&num>=0
    #Add Type(3) gold
    @text = "#{num} #{@type} #{MSG_ADD}" if type==3&&num>=0
    #Remove Type(0-2) item/armors/weapons
    @text = "#{num*-1} #{@type}s #{MSG_REMOVE}" if type<3&&type>-1&&num<0&&num!=-1
    #Remove Type(3) Gold
    @text = "#{num*-1} #{@type} #{MSG_REMOVE}" if type==3&&num<0
    #Remove Single
    @text = "#{@type} #{MSG_REMOVE}" if type<3&&type>-1&&num==-1
    #Add Single
    @text = "#{@type} #{MSG_ADD}" if type<3&&type>-1&&num==1
    CHEST_DATA[0] = width_set(@text)
    #Window Properties
    @khai_icon_window.width=0 if NO_ICON_WINDOW
    @khai_info_window=Chest_Window_Base.new
    @khai_info_window.width=width_set(@text)
    @khai_info_window.set_text(@text)
    @khai_info_window.x=(544-(@khai_info_window.width-@khai_icon_window.width))/2
    @khai_icon_window.x=(544-(@khai_info_window.width+@khai_icon_window.width))/2
    @khai_icon_window.y=(416-@khai_icon_window.height)/2
    @khai_info_window.y=(416-@khai_info_window.height)/2
    play_se
  end
#------------------------------------------------------------------------------
  def width_set(n)
    self.width_set_bitmap.text_size(n).width + 42
  end
#------------------------------------------------------------------------------
   def width_set_bitmap
     Bitmap.new(32,32)
   end
#------------------------------------------------------------------------------
  def play_se
    #Item Gain SE
    Audio.se_play("Audio/SE/#{ITEM_GAIN}", FOUND_SOUND_VOLUME, FOUND_SOUND_PITCH)if@setting<3&&@setting>-1&&@num>0&&ITEM_GAIN != "" if PLAY_FOUND_WINDOW_SOUND
    #Gold Gain SE
    Audio.se_play("Audio/SE/#{GOLD_GAIN}", FOUND_SOUND_VOLUME, FOUND_SOUND_PITCH)if@setting==3&&@num>=0&&GOLD_GAIN != "" if PLAY_FOUND_WINDOW_SOUND
    #Item Remove SE
    Audio.se_play("Audio/SE/#{ITEM_REMOVE}", FOUND_SOUND_VOLUME, FOUND_SOUND_PITCH)if@setting<3&&@setting>-1&&@num<0&&ITEM_REMOVE != "" if PLAY_FOUND_WINDOW_SOUND
    #Gold Remove SE
    Audio.se_play("Audio/SE/#{GOLD_REMOVE}", FOUND_SOUND_VOLUME, FOUND_SOUND_PITCH)if@setting==3&&@num<0&&GOLD_REMOVE != "" if PLAY_FOUND_WINDOW_SOUND
  end
#------------------------------------------------------------------------------
  def terminate
    @spriteset.dispose
    @khai_icon_window.dispose
    @khai_info_window.dispose
  end
#------------------------------------------------------------------------------  
  def update
    @khai_info_window.update
    @khai_icon_window.update
    @spriteset.update # enables sprite update (weather)
    $game_map.update # enables event update (event movement)
    $scene = Scene_Map.new if Input.trigger?(Input::B) or Input.trigger?(Input::C)
  end
#------------------------------------------------------------------------------
end
#==============================================================================


DEMO!!!

Sorry for taking so long to upload the demo, been hectic lately ENJOY.
I'm glad you guys like the integration.
icecold49
Well this is kinda cool. Thanks for combining these. I suggest you put both scripts in spoiler buttons so the page isn't so big. I was gonna use one of these scripts for my project but i guess two is even better. I'm a little confused though. What does each script do individually? Do they both do the same thing or are there differences? Oh and do you have permission from the authors to do this?
platipus
when will the demo arrive? this script sounds really good.
Ziosin
QUOTE (icecold49 @ Sep 3 2009, 09:48 PM) *
Oh and do you have permission from the authors to do this?

Due credit was given in the respective scripts.

QUOTE (platipus @ Sep 16 2009, 07:20 PM) *
when will the demo arrive? this script sounds really good.

This is easy enough to do without a demo. It's only changing the stuff in the quotation marks. The Item Popup is plug'n'play.


It works perfectly for me. Thanks tons Eccid. Very nice job.
Locke
This script is very useful to me and others thanks!
Eccid
UPDATED!
Speed@
Awesome. I have been using something like this for some time, but it was buggy, this one is good, exept there's one error:
CODE
@popup_window = Item_Popup_window.new(@x, @y)

change to
CODE
@popup_window = Item_Popup_Window.new(@x, @y)

if it's written with small w it gives an error.
Locke
Nice demo but some of the sprites from Invader Zim!! LOL!! laugh.gif laugh.gif
Eccid
QUOTE (Locke @ Sep 20 2009, 07:45 PM) *
Nice demo but some of the sprites from Invader Zim!! LOL!! laugh.gif laugh.gif


I love invader zim tongue.gif

UPDATED!
DinShambles
I'm having big problem with this script, in my game i have vehicle up-grades called from common events with conditional branches that require you to be in the vehicle to use them but there consumable items you use them there gone. so when your not in the vehicle and you use the item it tells you you can't and re-adds the item to your inventory. but when the event re-adds the item i'm getting an error on line 24, i have no idea why as i can't script. all i know is i have a bunch of conditional branch items that re-add the item if it can't be used and that's the only why i know to event consumable items with requirements. and i've only tested a few but when i remove this script they work. but i really love this script and want to keep both.

Any ideas are greatly appreciated thanks.
ThugLifeWhyteboi
Everything is great I love the script its freaking awesome, but I'm having just one small tiny error, when it says chest empty the window goes from non transparent to transparent and it looks pretty wierd cause when you get gold or items its just transparent the whole time the windwo appears but not one it says empty if you could help me better understand the opacity or transparency coding to the "Chest is empty" windwo i would love you forever and ever no homo im trying to learn scripting as i make my frist game on VX, Thanks for the AMAZING script Please help me with this little issue...

Oh and I'm referring to the Item Pop Up Script... thanks
Helios
Great script. I'll use this with a little modification of my own.

@ThugLifeWhyteboi
Already opened chest? Honestly, just put an empty event page there. A pop-up is not really necessary.
Sarith
Great Script. Took minimal effort to get it working for my Project. Thank you! biggrin.gif
luigi400000
I love it! Great work! At first i tought it be hard to install, but it so easy! Now I gotta put comments in all my chest's!

Over all, Great work!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.