07-21-2020, 08:48 PM
(This post was last modified: 07-21-2020, 08:59 PM by DerVVulfman.)
Introduction
The Lily's Librams system permits you to have actual books, scrolls, or other like reading material in your game. However, this add-on allows you to make it possible to easily take a book off the shelf.
Yes, it is already possible to do so with plenty of eventing for each instance. But this gifts you with tools to make it easier whilst bringing up a decision window where you may opt to take or leave the item behind.
Features
- Take the book! Add it to your inventory to read later!
- Make the book vanish from the shelf (if configured)!
Script
Start your library today!
Code:
#==============================================================================
# ** Lily's Taken Librams
# An add-on to Lily's Librams
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 07-21-2020 (mm/dd/yyyy)
# RGSS / RPGMaker XP
#==============================================================================
#
# INTRODUCTION:
#
# The Lily's Librams system permits you to have actual books, scrolls, or
# other like reading material in your game. However, this add-on allows you
# to make it possible to easily take a book off the shelf.
#
# Yes, it is already possible to do so with plenty of eventing for each in-
# stance. But this gifts you with tools to make it easier whilst bringing
# up a decision window where you may opt to take or leave the item behind.
#
#
#------------------------------------------------------------------------------
#
# INSTALLATION:
#
# Place this script below Lily's Librams as it does overwrite one of its
# methods, and configure it within the 'TakenLibrams' module as desired.
#
# Options within the 'TakenLibrams' module are heavily noted.
#
#
#------------------------------------------------------------------------------
#
# VISUALS:
#
# This system generates a basic pop-up display, asking if you wish to take
# or leave the currently read libram behind. No customization for the win-
# dow was added. This by choice as I leave it up to game developers to add
# such touches.
#
#
#------------------------------------------------------------------------------
#
# ADDITIONAL:
#
# This script does save data within the Game_System class. So any saved
# game files made prior to installation of this script will not function
# and game/demo restarts will be needed.
#
#
#------------------------------------------------------------------------------
#
# SCRIPT CALLS:
#
# The script alone does not function by itself. Script calls much like
# the ones within Lily's Librams must be used to identify a libram that
# is to be taken, and run a test to see if the libram was already taken.
#
# In fact, this add-on only has two script calls which are very simple
# in design. This should make it easy for game develoers to use.
#
#
# * * * * *
#
# * TAKE LIBRAM
#
# Syntax: takelibram
# or takelibram(selfswitch)
#
# This simple call, placed above the libram() script call, identifies
# the book/scroll/note as a libram that may be taken by the player.
# It is a very simple call by itself.
#
# If the game developer desires to have the event displaying the book
# to change, the 'takelibram' command does allow you to pass a self-
# switch to be turned on once the libram is taken.
#
# Valid SelfSwitches are the same RMXP switches of "A", "B", "C", "D"
#
#
# * * * * *
#
# * TAKEN LIBRAM ?
#
# Syntax: takenlibram?
#
# Even simpler, this script call looks to see if the libram for the
# event was already taken! When you take a libram, the event and
# the event's map is stored away for this test. So it is quite easy
# to run this test. Unfortunately, this test is only limited to one
# libram per event. So it is not possible to run this test for two
# different event pages of books.
#
#
# * * * * *
#
# EXAMPLE TIME!
#
# Yes, I am giving you examples how thexe can be used.
#
# EX 1: @>ConditionalBranch: Script: takenlibram?
# @>Text: You already took the book!
# : Branch End
# @>Script: takelibram
# @>Script: libram(5)
# @>
# : Branch End
# @>
#
# Some may not know this, but the CONDITIONAL BRANCH event command does
# allow you run a script call. It's the 4th tab in the event command.
#
# Here, I use the takenlibram? script call within a Conditional Branch,
# and if the book is taken, it brings up a SHOW TEXT event command that
# says "You already took the book!"
#
# However, I also made the Conditional Branch perform two script calls
# if the takenlibram? script call showed that the book wasn't taken.
#
# The first call is the 'takelibram' event. This informs the system
# that this book is available to be 'removed' and inaccessible if the
# player 'takes' the book. And the second call is the 'libram' call
# from Lily's Librams itself.
#
# NOTE: This does not make any visible changes on the screen, so you
# will not see if a book was/wasn't removed from any table or shelf.
#
#
# * * * * *
#
# EX 2: @>ConditionalBranch: Script: !takenlibram?
# @>Script: takelibram
# @>Script: libram(5)
# @>
# : Branch End
# @>
#
# Smaller than the previous example, I chose to put an exclamation point
# in front of the name of the takenlibrams? script call, thus making the
# script call... " !takenlibram? ". Instead of telling me if a book was
# taken, it tells me if a book was NOT taken. The 'exclamation point'
# actually symbolizing NOT for those unaware.
#
# SO... unlike the previous example, this one only allows the takelibram
# and libram script calls to function if a libram wasn't taken for this
# particular event. It's quite compact!
#
# NOTE: This does not make any visible changes on the screen, so you
# will not see if a book was/wasn't removed from any table or shelf.
#
# * * * * *
#
# EX 3: @>Script: takelibram('A')
# @>Script: libram(5)
# @>
#
# Quite literally, the shortest of options. This one need not rely upon
# the 'takenlibram?' test. Instead, this call actively changes the self
# switch of the event if the book is taken.
#
# The takenlibram script call above passes the value of 'A' into it, this
# value being the self switch that is turned on for this event. Only if
# the book is taken, will this self switch be turned on. And this does
# assume that the event has a second 'page' that runs when this particu-
# lar self switch is true.
#
# NOTE: This particular combination does affect events and does refresh
# the game screen. This option does, in fact, allow a book or scroll to
# vanish from a table or shelf.
#
#
#------------------------------------------------------------------------------
#
# A BOOK IN AN ITEM:
#
# For those unaware, you can merely set up an item to run a Common Event
# and just have a 'libram' script call from Lily's Librams be the within
# said Common Event.
#
# You probably wouldn't want the item to be used in battle (HAHAH), but
# setting up a book to read from the Item Menu should be no problem. And
# you may have fun selling them off.
#
# One option of note. There is a 'Repeat' option within the TakenLibrams
# module. It determines if you can have more than one of a specific book
# in your inventory. If on, you can find and take five, seven or twenty
# of any given book. But if turned off, you can only have one of a par-
# ticular book until you remove it somehow (selling it or whatever).
#
#
#------------------------------------------------------------------------------
#
# COMPATIBILITY:
#
# Designed specifically for Lily's Librams.
#
#
#------------------------------------------------------------------------------
#
# TERMS OF USE:
#
# Free for use, even in commercial games. Only due credit is required. Mind
# you, due credit for those mentioned within Lily'S Librams is also required.
#
#
#==============================================================================
module TakenLibrams
# Creates the Libram Item hash. Do not remove. ----------------------------
LIBRAM_ITEM = {} # Do not touch --------------------------------------------
# --------------------------------------------------------------------------
# Take Libram Window
# ==================
# Define the height and width of the popup window asking if you want to
# take the libram off the shelf, floor, or wherever event is displaying.
# This also includes what text is shown for 'TAKE' or "LEAVE" options.
#
Y_Pos = 150 # Height of window
Width = 150 # Window Width
Text1 = "Take" # Text for libram being taken
Text2 = "Leave" # Text for libram being left alone
Repeat = true # Permitted to take multiple of same libram
# Librams to Items List
# =====================
# This is a list that determines the ID of an item to be added to the
# game party's inventory after taking a libram. Each LIBRAM_ITEM entry
# is keyed to a Libram Title (TITLES) within "Lily's Librams". And the
# value assigned to each entry is the ID of the item added.
#
# This only functions for libram events properly set up.
#
# Libram Item
# ============== ====
LIBRAM_ITEM[0] = 33 # Assumes TITLE #0 will give you item #33
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :libram_take # Is Libram able to be taken
attr_accessor :takelibram_event # ID of the libram event
attr_accessor :takelibram_mapid # Map Id of the libram event
attr_accessor :takelibram_sswitch # Self Switch of the libram event
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_temp_take_libram_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
game_temp_take_libram_initialize
@libram_take = false
@takelibram_event = nil
@takelibram_mapid = nil
@takelibram_sswitch = nil
end
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias game_system_take_libram_initialize initialize
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :taken_librams # list of event/map librams taken
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
game_system_take_libram_initialize
@taken_librams = []
end
end
#==============================================================================
# ** Window_TakenLibrams
#------------------------------------------------------------------------------
# This window generates a pop-up window.
#==============================================================================
class Window_TakenLibrams < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Compute window height from command quantity
super(0, 0, TakenLibrams::Width, 32 + 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
# text_lines : text string array
#--------------------------------------------------------------------------
def refresh
# Get the texts
text_lines = [ TakenLibrams::Text1, TakenLibrams::Text2 ]
# Get number of lines of text for window size
@item_max = 2
# If we have no timer, using button
# Set window height and contents bitmap with extra 'button' line
self.height = 32 * (@item_max + 1)
self.contents = Bitmap.new(width - 32, (@item_max ) * 32)
# Clear contents
self.contents.clear
# Cycle through and draw the text
for i in 0...@item_max
draw_item(i, text_lines[i], normal_color)
end
# Set index position depending on timer or not
self.index = 0
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# text : rendered text
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, text, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, text,1)
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Set libram for taking
# selfswitch : event's self switch (nil or 'A', 'B', 'C' or 'D' )
#--------------------------------------------------------------------------
def takelibram(selfswitch = nil)
# Prevent invalid selfswitch
unless selfswitch.nil?
if selfswitch.is_a?(String)
# Ensure all capitals
selfswitch = selfswitch.upcase
# Test for legitimate Selfswitches
unless ['A','B','C','D',"A","B","C","D"].include?(selfswitch)
# Set to nil if invalid
selfswitch = nil
end
else
selfswitch = nil
end
end
$game_temp.libram_take = true
$game_temp.takelibram_event = @event_id
$game_temp.takelibram_mapid = $game_map.map_id
$game_temp.takelibram_sswitch = selfswitch
end
#--------------------------------------------------------------------------
# * Determine if libram taken
#--------------------------------------------------------------------------
def takenlibram?
takenlibram_event = @event_id
takenlibram_mapid = $game_map.map_id
test_take = [takenlibram_mapid, takenlibram_event ]
return true if $game_system.taken_librams.include?(test_take)
return false
end
end
#==============================================================================
# ** Scene_Libram
#------------------------------------------------------------------------------
# This class performs libram screen processing.
#==============================================================================
class Scene_Libram
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias taken_librams_main_windows main_windows
alias taken_librams_main_dispose main_dispose
alias taken_librams_update update
#--------------------------------------------------------------------------
# * Main Processing (when creating all window contents)
#--------------------------------------------------------------------------
def main_windows
main_windows_take_pop # Create popup windows
taken_librams_main_windows # The original call
end
#--------------------------------------------------------------------------
# * Main Processing (when disposing of all windows and background contents)
#--------------------------------------------------------------------------
def main_dispose
taken_librams_main_dispose # The original call
main_dispose_take_pop # Dispose the popup window
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update the Hotkey Popup Window if active
@taken_libram_window.update if @taken_libram_window.active == true
# Exit the Hotkey Popup Window if active
return update_take_decision if @taken_libram_window.active == true &&
!$game_temp.message_window_showing
# The original call
taken_librams_update
end
#--------------------------------------------------------------------------
# * Main Processing (when creating the popup window)
#--------------------------------------------------------------------------
def main_windows_take_pop
@taken_libram_window = Window_TakenLibrams.new
@taken_libram_window.visible = false
@taken_libram_window.active = false
@taken_libram_window.x = (640-TakenLibrams::Width)/2
@taken_libram_window.y = TakenLibrams::Y_Pos
@taken_libram_window.z = 1500
end
#--------------------------------------------------------------------------
# * Main Processing (when disposing of the popup window)
#--------------------------------------------------------------------------
def main_dispose_take_pop
# Dispose of the window
@taken_libram_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update Popup Key Testing
#--------------------------------------------------------------------------
def update_take_decision
# Return if Enter isn't pressed
return if !Input.trigger?(Input::C)
# Play decision
$game_system.se_play($data_system.decision_se)
# Hide Hotkey Popup
@taken_libram_window.active = @taken_libram_window.visible = false
# Do not take libram. Close and exit on selection
return update_close_libram if @taken_libram_window.index == 1
# Take libram
update_take_libram
end
#--------------------------------------------------------------------------
# * Take viable libram and flag
#--------------------------------------------------------------------------
def update_take_libram
# Add the event to the taken libram list
set_take = [$game_temp.takelibram_mapid, $game_temp.takelibram_event ]
$game_system.taken_librams.push set_take
# Get the item id of the libram if valid
if TakenLibrams::LIBRAM_ITEM.has_key?(@libram_id)
item_id = TakenLibrams::LIBRAM_ITEM[@libram_id]
# Add the item
$game_party.gain_item(item_id, 1)
end
# If the libram also sets the event's self switch
unless $game_temp.takelibram_sswitch.nil?
key = [$game_temp.takelibram_mapid, $game_temp.takelibram_event,
$game_temp.takelibram_sswitch ]
$game_self_switches[key] = true
# Set refresh
$game_map.need_refresh = true
end
# And finally take libram
update_close_libram
end
#--------------------------------------------------------------------------
# * Frame Update (when initially exiting the libram system)
#--------------------------------------------------------------------------
def update_exit
# Close libram if libram cannot be taken
return update_close_libram unless $game_temp.libram_take == true
# Close libram and exit if you can't take librams repeatedly
return update_close_libram unless test_take_libram? == true
# Make pop window visible and active
@taken_libram_window.active = @taken_libram_window.visible = true
end
#--------------------------------------------------------------------------
# * Frame Update (when testing of existing libram)
#--------------------------------------------------------------------------
def test_take_libram?
# Exit true if you can take more than one of the same libram
return true if TakenLibrams::Repeat == true
effective = false
# Get the item id of the libram if valid
if TakenLibrams::LIBRAM_ITEM.has_key?(@libram_id)
item_id = TakenLibrams::LIBRAM_ITEM[@libram_id]
# Permit removal as party does not have the libram
effective = true if $game_party.item_number(item_id) < 1
end
# Exit effective
return effective
end
#--------------------------------------------------------------------------
# * Frame Update (when closing the libram)
#--------------------------------------------------------------------------
def update_close_libram
# Reset flag
$game_temp.libram_take = false
# If called from event
if $game_temp.libram_calling
# Clear save call flag
$game_temp.libram_calling = false
# Switch to map screen
$scene = Scene_Map.new
return
end
# Switch to menu screen
$scene = Scene_Menu.new(Librams::RETURN_MENU_ID)
end
end
Instructions
Plenty, and all within the demo's instruction page.
FAQ
This does add more data to the Game_System class. So it will have issues with previously made save game files. Adding this into a project will require a fresh game. But that's expected whenever you insert something that adds data to your saves.
Compatibility
Designed solely for Lily's Librams. Um.. duh?
Terms of Use
Free for use, even in commercial games. Only due credit is required. Mind you, due credit for those mentioned within Lily'S Librams is also required.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links