The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on August 03, 2008, 12:36:06 AM

Title: Evidence Locker
Post by: modern algebra on August 03, 2008, 12:36:06 AM
Evidence Locker
Version: 1.1
Author: modern algebra
Date: November 11, 2010

Version History



Description


This script allows the player to choose an evidence item from his or her inventory and set conditions depending on which item is chosen. This allows for an interactive exchange, particularly in games where the presentation of evidence is necessary, such as detective games or minigames. In addition, you can have multiple different evidence lockers, allowing for different functions. Maybe some items you'll want to use this script to create a trading features, while others you'd like to use for detective purposes. This is now possible. As well, the same item can belong to multiple different evidence lockers.

Features


Screenshots

Should look exactly the same as your Scene_Item

Instructions

Place this script into its own slot in the Script Editor (F11), somewhere above Main and below Materials.

See the instructions in the header of the script for more instruction on how to use the script in your game.

Script


Code: [Select]
#==============================================================================
#  Evidence Locker
#  Version 1.1
#  Author: modern algebra (rmrk.net)
#  Date: November 11, 2010
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Description:
#   
#    This script allows the player to choose an evidence item from his or her
#  inventory and set conditions depending on which item is chosen. It also
#  allows you to have multiple evidence lockers, in case you only want to
#  choose from a limited subsection of items in your possession in one case and
#  a different subsection in another case.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#
#    To set an item so that it will show up in an evidence locker, you need
#   only type the following into the note box of an item
#     \evidence[locker_id]
#        locker_id : the ID of the locker you want this item to be in. If
#          excluded entirely (ie. just \evidence ) then it's in locker 0.
#
#  To call the Evidence scene, use this code:
#
#    call_evidence (locker_id)
#      locker_id : the ID of the locker you want to open. If excluded, (ie.
#        just call_evidence ) then it opens locker 0.
#     
#  To access the item the player has chosen in the scene, you have four codes:
#
#    $game_temp.evidence_name      the name of the item chosen
#    $game_temp.evidence_amount    the amount of item in the party's possession
#    $game_temp.evidence_type      0 => Item, 1 => Weapon, 2 => Armor
#    $game_temp.evidence_id        the ID of the item chosen
#
#  You can use any of these in a conditional branch by utilizing the script
#  condition and typing in this:
#
#    $game_temp.evidence_name == 'name'
#    $game_temp.evidence_amount == positive integer
#    $game_temp.evidence_type == integer between 0 and 2, inclusive
#    $game_temp.evidence_id == positive integer
#   
#  If necessary, type and id will only return true for the exact item wanted.
#  In general, name will be sufficient and probably easier, though confusion
#  may arise if you have more than one piece of evidence with the same name.
#  The amount is in case you want a number restriction on the evidence, so if
#  you need two instead of just one or something. You can join conditions with
#  &&, so this would be legitimate:
#
#    $game_temp.evidence_type == 2 && $game_temp.evidence_id == 24
#==============================================================================

#==============================================================================
# ** RPG::BaseItem
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    new method - evidence?
#==============================================================================

class RPG::BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Evidence?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def evidence?
    locker_id = $game_temp ? $game_temp.e_locker_id : 0
    return true if self.note[/\\evidence\[#{locker_id}\]/i] != nil
    return true if locker_id == 0 && self.note[/\\evidence([^\[]|$)/i] != nil
    return false
  end
end

#==============================================================================
# ** Game_Temp
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    new public instance variables - evidence_name; evidence_type; evidence_id;
#      evidence_amount; e_locker_id
#==============================================================================

class Game_Temp
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :evidence_type   # 0 => Item, 1 => Weapon, 2 => Armor
  attr_accessor :evidence_id     # Item ID
  attr_accessor :evidence_name   # The name of the evidence
  attr_accessor :evidence_amount # The amount of that evidence in possession
  attr_writer   :e_locker_id     # The scene ID of the evidence locker called
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Evidence Scene ID
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def e_locker_id
    return @e_locker_id if @e_locker_id
    return 0
  end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - call_evidence
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Call Evidence
  #    locker_id : the ID of the evidence scene to call
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def call_evidence (locker_id = 0)
    $game_temp.e_locker_id = locker_id
    $scene = Scene_Evidence.new
    @wait_count = 1
  end
end

#==============================================================================
# ** Window_Item
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods - include?, enable?
#==============================================================================

class Window_Item
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Include?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_dragon9_request_evince_selct_incl_8b4s include?
  def include?(item)
    return (item == nil ? false : item.evidence?) if $scene.is_a? (Scene_Evidence)
    modalg_dragon9_request_evince_selct_incl_8b4s (item)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Enable?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_drgdd9_req_evidnc_954n  enable?
  def enable? (item)
    return true if $scene.is_a? (Scene_Evidence)
    return modalg_drgdd9_req_evidnc_954n (item)
  end
end

#==============================================================================
# ** Scene_Evidence
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  This class is a subclass of Scene_Item. Instead of using a selected item,
#  this script reserves it in a variable to be used in an event.
#==============================================================================

class Scene_Evidence < Scene_Item
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Return Scene
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def return_scene
    $scene = Scene_Map.new
    $game_temp.e_locker_id = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Item Selection
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def update_item_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      # Clear evidence variables
      $game_temp.evidence_type = nil
      $game_temp.evidence_id = nil
      $game_temp.evidence_name = nil
      $game_temp.evidence_amount = nil
      return_scene
    elsif Input.trigger?(Input::C)
      @item = @item_window.item
      if @item == nil
        Sound.play_buzzer
      else
        Sound.play_decision
        # Set evidence variables to the item chosen
        $game_temp.evidence_type = @item.is_a? (RPG::Item) ? 0 : @item.is_a? (RPG::Weapon) ? 1 : 2
        $game_temp.evidence_id = @item.id
        $game_temp.evidence_name = @item.name
        $game_temp.evidence_amount = $game_party.item_number (@item)
        return_scene
      end
    end
  end
end

Credit



Thanks


Support


Please post here at rmrk.net for the swiftest response

Demo


See attached (http://rmrk.net/index.php?action=dlattach;topic=28722.0;attach=21738).


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Evidence Locker
Post by: Charbel on October 17, 2008, 06:37:05 PM
Its really very useful, thank you!  :D
Title: Re: Evidence Locker
Post by: Devlin on November 09, 2008, 11:28:07 AM
I don't know if it's possible...

How can I subtract the item after the player presents it to the person?

Other than using the conditional branch that checks if he presents it, and then using the event command to subtract the said item. But in my game, there are a lot items and I don't want to use like many conditional branches. That would get messy. Also, in some cases I'm using the 'or' feature. Like $game_temp.evidence_id == 1 || $game_temp.evidence_id == 2. How can I subtract that since I don't know which one the player will present the item #1 or item #2?

So I'm here, wondering if it's possible to do something like this in easier way?

Other than that, this script is really useful. Nice work.
Title: Re: Evidence Locker
Post by: modern algebra on November 09, 2008, 05:15:51 PM
Well, you can do it like this - underneath these three lines:

Code: [Select]
        $game_temp.evidence_id = @item.id
        $game_temp.evidence_name = @item.name
        $game_temp.evidence_amount = $game_party.item_number (@item)

Place this:

Code: [Select]
$game_party.lose_item (@item, 1)

So that section of the script would look like:


Code: [Select]
      else
        # Set evidence variables to the item chosen
        $game_temp.evidence_type = @item.is_a? (RPG::Item) ? 0 : @item.is_a? (RPG::Weapon) ? 1 : 2
        $game_temp.evidence_id = @item.id
        $game_temp.evidence_name = @item.name
        $game_temp.evidence_amount = $game_party.item_number (@item)
        $game_party.lose_item (@item, 1)
        return_scene
      end

But it will only and always remove 1 instance of that item. I personally think the method you've suggested would work better.
Title: Re: Evidence Locker
Post by: Devlin on February 22, 2009, 07:34:07 PM
I don't know if I should necropost but it seems you're still around so...

If you're in mood for scripting, maybe you can create a skill add-on or update for Evidence Locker? So I would have both items and skills evidence locker? (Note: I don't mean having both items and skills in one window. It would be nice to be able to summon the item window when I call for it, and later summon the skill window when I call for it)

If you're looking for specifics, I want the player to be able to 'present' his skills. Now I'm not sure how it all works out for the multiple members in party... Pressing a specific key to go through different members' skill-list, or using the script call to get a specific member's skill-list? 

I'm only really interested into the presented skill's ID but if you want, you can make additional features like skill's name, etc, for others.

Your Evidence Locker is incredibly amazing. I've been working with it for months and loving it so far. I admit that I'm not using your Evidence Locker to present the evidences. Instead I have been using it for the gift system, and other things relating to the presented items.

I want to be able to 'present' a skill to the guy so he can upgrade it (via my event system)
Title: Re: Evidence Locker
Post by: the_mantic on February 22, 2009, 09:11:59 PM
I'm glad Devlin did necropost. This is really cool, modern. It makes me want to add a storyline detour just to use it.
Title: Re: Evidence Locker
Post by: Kokowam on February 25, 2009, 02:22:40 AM
I wish this had a demo so I could see the script in action as it should be. D:

To me, the instructions are a little unclear because I don't know what goes where and ?_? I also don't really get what happens when all the conditions are met and stuff.. XP I'm just dumb? Idk.
Title: Re: Evidence Locker
Post by: DNZGames on November 07, 2010, 05:21:13 PM
Is there any way (or an alternate/modified script) to create multiple Evidence lists? (eg So when calling for Evidence, you could number lists so items with /evidence1 show up in one list, and /evidence2 show up in another) I haven't tried to experiment to find out if there is, as I have no ability to script whatsoever. I know this is a necropost, but I really need to know!
Title: Re: Evidence Locker
Post by: modern algebra on November 09, 2010, 01:45:15 AM
it wouldn't be terribly hard to modify it to include a feature like that, but currently there is none that I know of.
Title: Re: Evidence Locker
Post by: DNZGames on November 10, 2010, 07:33:22 AM
would anyone be willing to spare any time to try this for me? i have no idea how to script, and don't want to ruin the script for my game. it would be much appreciated?
Title: Re: Evidence Locker
Post by: DNZGames on November 11, 2010, 04:37:48 PM
thank you so much!
Title: Re: Evidence Locker
Post by: modern algebra on November 11, 2010, 05:41:18 PM
No problem. And yeah, updated to 1.1 everybody.
Title: Re: Evidence Locker
Post by: Mitsarugi on May 07, 2011, 04:45:28 PM
so Modern Algebra if i'm correct this in a condition branch "$game_temp.evidence_amount == 2" should check if the player has 2 or more of the item
before going on with the rest of the event?
(sorry for the necropost)

Title: Re: Evidence Locker
Post by: modern algebra on May 07, 2011, 10:24:51 PM
That would check if they had exactly 2. If you wanted 2 or more, you would use:

Code: [Select]
$game_temp.evidence_amount >= 2

or just:

Code: [Select]
$game_temp.evidence_amount > 1
Title: Re: Evidence Locker
Post by: pacdiggity on May 07, 2011, 11:41:51 PM
Unless they somehow got 1.6 of the item.
*mind explodes*
Title: Re: Evidence Locker
Post by: thomasbradley on March 30, 2012, 08:08:41 AM
Sorry for the necropost...
But I need to know if there's any chance of you making this compatible with the Simple Sort Inventory script that cozziekuns made?
I really need it for my project.