Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # STRING KEEPER
- # By: Ixfuru
- # Released 1/20/13
- ################################################################################
- #
- # This Script does several things. All of which are in regard to handling of
- # strings. Strings, for those of you who don't know, are most often words.
- # Usually strings are difficult to use in projects without the direct use of
- # scripts. As the only source of strings for the eventer is the Name
- # Processing event command. This script can be used in the following ways:
- #
- # 1) Store Strings for random use: The script enables you to allow player
- # input of strings, which you can use in a variety of ways. The strings
- # are stored in an array, and can be accessed through a script call:
- #
- # $game_stringkeeper.strings[string_id]
- #
- # With string_id being the string's index in the array that you want to
- # retrieve. As strings are saved by editting existing strings or by adding
- # new ones, the strings are either pushed into the array, extending the
- # list of strings, or if editting, they replace the string at the given
- # index. For example, if you allowed the player to randomly put in a bunch
- # of strings, and they wrote "Hat" for one, "Juice" for one, "Block" for
- # another. The array of strings when stored would look like this:
- #
- # ["Hat", "Juice", "Block"]
- #
- # Knowing that arrays operate on a 0-index basis, you would then access them
- # like this:
- #
- # $game_stringkeeper.strings[0] for "Hat"
- # $game_stringkeeper.strings[1] for "Juice"
- # $game_stringkeeper.strings[2] for "Block"
- #
- # You can delete strings with the script call:
- #
- # $game_stringkeeper.delete_string(string_id)
- #
- # 2) The script comes with a new scene, much like the Name Processing scene,
- # which allows the player to input the string at runtime. You, as the
- # creator, have complete control over the way the input string is handled
- # when calling the scene. There are two ways to handle the scene when
- # calling it. You can call it at any time using a script call from the
- # event commands 'script' feature. The two ways are this:
- #
- # If you want to call the script for a new string, they you place:
- #
- # $scene = Scene_StringKeeper.new(character_limit)
- #
- # The character_limit should be replaced with the amount of characters
- # (or letters) you wish for the player to be able to input. When called this
- # way, the string is saved as a NEW STRING. It is added onto the strings
- # already created.
- #
- # However, if you wish to edit an existing string, which is ideal for
- # passwords and such, you can use this command instead.
- #
- # $scene = Scene_StringKeeper.new(character_limit, true, string_id)
- #
- # This will tell the system that you are overwriting an existing string, and
- # will subsequently replace the old string in 'string_id' location with the
- # new string.
- #
- # So, if you were creating a password, you can edit an existing string, and
- # then immediately following the scene, check to see if the string matches
- # the PASSWORDS, which you've set up in the settings of the script below.
- # Just use the following script in a conditional branch.
- #
- # $game_stringkeeper.password_match(string, password_id)
- #
- # This will return true if the password matches, and false if it does not.
- #
- # 3) In addition to these ways, the script has another tool which can be used
- # to replace the Name Processing. You can use the script call below to
- # name an actor one of the existing strings:
- #
- # $game_stringkeeper.string_to_name(actor_id, string_id)
- #
- # Replace the actor_id part with the database ID of the actor you wish to
- # change, and the string_id, with the string you wish to become the actor's
- # name.
- #
- # 4) Finally, for those game makers out there, the script offers a stringlist
- # debug tool which can be used during playtesting, to see what the existing
- # scripts are. This debugger can be opened via Input from the map scene.
- # You can define which button to press in the settings below.
- #
- ################################################################################
- # INSTRUCTIONS
- # Besides what we covered above, the script can be used plug and play if you
- # stick it in the script editor below materials and above main. However, without
- # proper use of the script calls, you won't get much besides a bunch of randomly
- # input strings and the ability to check them during playtest.
- #
- # During the input scene, you can use these inputs:
- #
- # C (action button): enters letters
- # B (back button) : backs out of scene or from input to commands
- # Y (S on your keyboard): deletes a character
- # L (Q on your keyboard): jumps one space left
- # R (W on your keyboard): jumps one space right
- #
- ################################################################################
- ################################################################################
- # CREDITS
- # Use this script in your project. Just make sure you give credit to Ixfuru. If
- # you wish to use commercially, you'll have to contact me via the RPGMakerVX.net
- # forums.
- ################################################################################
- module Ixfuru
- module StringKeeper
- ############################################################################
- # SETTINGS START
- ############################################################################
- # This is a hash storing passwords you may want to compare with input
- # strings later on. Place them like this:
- #
- # password_id => password
- #
- # The password_ids must be in numerical order starting from 0. The passwords
- # can be anything you want them to be. Just make sure you don't forget the
- # commas after each one.
- PASSWORDS = {#<<<Don't delete this!
- 0 => "Ralph",
- 1 => "Swords",
- 2 => "Potions",
- 3 => "Enemies",
- }#<<<Don't delete this!
- # This is the settings for the debugger during playtest. Make sure you set
- # this to false if you don't want the player having access to the strings.
- VIEW_STRINGS = true
- VIEW_STRINGS_INPUT = Input::F5
- # This is the default string character. It is the character placed inside
- # the string at each empty position in the string or at the beginning of the
- # StringKeeper input scene.
- DEFAULT_STRING = " "
- # This is the default character limit. I'm not sure what will happen if you
- # go above 12. But 12 fits nicely.
- DEFAULT_STRING_LIMIT = 12
- # These are the sound effects for the Input scene.
- ENTER_SE = "Switch2"
- ERASE_SE = "Stare"
- LETTERJUMP_SE = "Saint3"
- end
- end
- ################################################################################
- #*******************************************************************************
- # GAME STRING KEEPER
- ################################################################################
- class Game_StringKeeper
- attr_accessor :strings
- attr_accessor :passwords
- def initialize
- @strings = []
- @passwords = Ixfuru::StringKeeper::PASSWORDS
- end
- def add_string(string)
- @strings.push(string)
- end
- def password_match(string, key)
- return true if string == Ixfuru::StringKeeper::PASSWORDS[key]
- return false
- end
- def string_to_name(actor_id, string_id)
- actor = $game_actors[actor_id]
- string = @strings[string_id]
- actor.name = string
- end
- def delete_string(string_id)
- @strings.delete(string_id)
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE TITLE
- ################################################################################
- class Scene_Title < Scene_Base
- #--------------------------------------------------------------------------
- # * Create Game Objects
- #--------------------------------------------------------------------------
- alias ix_skeeper_sctitle_create_game_objects create_game_objects unless $@
- def create_game_objects
- ix_skeeper_sctitle_create_game_objects
- $game_stringkeeper = Game_StringKeeper.new
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE FILE
- ################################################################################
- class Scene_File < Scene_Base
- #--------------------------------------------------------------------------
- # * Write Save Data
- # file : write file object (opened)
- #--------------------------------------------------------------------------
- alias ix_skeeper_write_save_data write_save_data unless $@
- def write_save_data(file)
- ix_skeeper_write_save_data(file)
- Marshal.dump($game_stringkeeper, file)
- end
- #--------------------------------------------------------------------------
- # * Read Save Data
- # file : file object for reading (opened)
- #--------------------------------------------------------------------------
- alias ix_skeeper_read_save_data read_save_data unless $@
- def read_save_data(file)
- $game_stringkeeper = Marshal.load(file)
- ix_skeeper_read_save_data(file)
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW STRING COMMANDS
- ################################################################################
- class Window_StringCommands < Window_Selectable
- STRINGCENTER_X = 544 / 2 - 80
- def initialize
- super(STRINGCENTER_X, 336, 160, 80)
- # enter string, finished
- c1 = "Enter String"
- c2 = "Finished"
- @commands = [c1, c2]
- @item_max = @commands.size
- refresh
- self.index = 0
- end
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_items(i)
- end
- end
- def draw_items(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- self.contents.clear_rect(rect)
- self.contents.draw_text(rect, @commands[index], 1)
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW STRING STATUS
- ################################################################################
- class Window_StringStatus < Window_Selectable
- STATUSCENTER_X = 544 / 2 - 172
- attr_accessor :characters
- attr_accessor :string
- def initialize(limit = Ixfuru::StringKeeper::DEFAULT_STRING_LIMIT)
- super(STATUSCENTER_X, 0, 344, 64)
- @string_limit = limit
- @characters = []
- for i in 0...@string_limit
- @characters.push(Ixfuru::StringKeeper::DEFAULT_STRING)
- end
- @column_max = @string_limit
- refresh
- self.index = 0
- self.active = false
- end
- def refresh
- self.contents.clear
- for i in 0...@string_limit
- draw_characters(i)
- end
- get_string
- end
- def draw_characters(index)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- self.contents.draw_text(rect, @characters[index])
- end
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- rect.width = contents.width / @column_max
- rect.height = WLH
- rect.x = index % @column_max * rect.width
- rect.y = index / @column_max * WLH
- return rect
- end
- def get_string
- @string = @characters.to_s
- end
- end
- ################################################################################
- #*******************************************************************************
- # Window String Input
- ################################################################################
- class Window_StringInput < Window_Selectable
- INPUTCENTER_X = 544 / 2 - 172
- attr_accessor :letters
- def initialize
- super(INPUTCENTER_X, 65, 344, 272)
- @letters = ["A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G",
- "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n",
- "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V",
- "v", "W", "w", "X", "x", "Y", "y", "Z", "z", "1", "2", "3", "4", "5", "6",
- "7", "8", "9", "0", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-",
- "_", "=", "+", "~", "<", ">"]
- @item_max = @letters.size
- @column_max = 9
- refresh
- self.index = 0
- self.active = false
- end
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_letters(i)
- end
- end
- def draw_letters(index)
- rect = item_rect(index)
- self.contents.draw_text(rect, @letters[index])
- end
- #--------------------------------------------------------------------------
- # * Get rectangle for displaying items
- # index : item number
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- @spacing = 24
- rect.width = (contents.width + @spacing) / @column_max - @spacing
- rect.height = WLH
- rect.x = index % @column_max * (rect.width + @spacing)
- rect.y = index / @column_max * WLH
- return rect
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE STRINGKEEPER
- ################################################################################
- class Scene_StringKeeper < Scene_Base
- def initialize(limit, edit = false, id = 0)
- @limit = limit
- @edit = edit
- @id = id
- end
- def start
- super
- @win_commands = Window_StringCommands.new
- @win_status = Window_StringStatus.new(@limit)
- @win_input = Window_StringInput.new
- end
- def update
- super
- if @win_commands.active
- update_commands
- elsif @win_input.active
- update_input
- end
- end
- def update_commands
- @win_commands.update
- if Input.trigger?(Input::C)
- case @win_commands.index
- when 0
- Sound.play_decision
- activate_input
- when 1
- Sound.play_decision
- store_new_string
- $scene = Scene_Map.new
- end
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- end
- def activate_input
- @win_input.active = true
- @win_commands.active = false
- end
- def update_input
- @win_input.update
- if Input.trigger?(Input::C)
- RPG::SE.new(Ixfuru::StringKeeper::ENTER_SE, 80, 100).play
- @win_status.characters[@win_status.index] = @win_input.letters[@win_input.index]
- if @win_status.index < @limit - 1
- @win_status.index += 1
- end
- @win_status.refresh
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- @win_status.refresh
- back_to_commands
- elsif Input.trigger?(Input::Y)
- RPG::SE.new(Ixfuru::StringKeeper::ERASE_SE, 80, 100).play
- if @win_status.index == @limit - 1
- @win_status.characters[@win_status.index] = Ixfuru::StringKeeper::DEFAULT_STRING
- end
- @win_status.index -= 1 if @win_status.index > 0
- @win_status.characters[@win_status.index] = Ixfuru::StringKeeper::DEFAULT_STRING
- @win_status.refresh
- elsif Input.trigger?(Input::L)
- RPG::SE.new(Ixfuru::StringKeeper::LETTERJUMP_SE, 80, 100).play
- @win_status.index -= 1 if @win_status.index > 0
- elsif Input.trigger?(Input::R)
- RPG::SE.new(Ixfuru::StringKeeper::LETTERJUMP_SE, 80, 100).play
- @win_status.index += 1 if @win_status.index < @limit - 1
- end
- end
- def store_new_string
- string = @win_status.string
- if @edit
- $game_stringkeeper.strings[@id] = string
- else
- $game_stringkeeper.add_string(string)
- end
- end
- def back_to_commands
- @win_commands.active = true
- @win_input.active = false
- end
- def terminate
- @win_commands.dispose
- @win_status.dispose
- @win_input.dispose
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW STRINGSLIST
- ################################################################################
- class Window_Stringslist < Window_Selectable
- def initialize
- super(142, 0, 220, 416)
- @item_max = $game_stringkeeper.strings.size
- refresh
- self.index = 0
- end
- def refresh
- self.contents.clear
- create_contents
- for i in 0...@item_max
- draw_items(i)
- end
- end
- def draw_items(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- self.contents.clear_rect(rect)
- self.contents.draw_text(rect.x, rect.y, self.width, WLH, index.to_s)
- self.contents.draw_text(rect.x + 30, rect.y, self.width - 30, WLH, $game_stringkeeper.strings[index])
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE STRINGSLIST
- ################################################################################
- class Scene_Stringslist < Scene_Base
- def start
- super
- @win_strings = Window_Stringslist.new
- @win_strings.active = true
- end
- def update
- super
- @win_strings.update
- if Input.trigger?(Input::C) or Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- end
- def terminate
- @win_strings.dispose
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE MAP
- ################################################################################
- class Scene_Map < Scene_Base
- alias ix_skeeper_scmap_update update unless $@
- def update
- ix_skeeper_scmap_update
- update_call_stringslist
- end
- def update_call_stringslist
- if Input.trigger?(Ixfuru::StringKeeper::VIEW_STRINGS_INPUT)
- Sound.play_decision
- $scene = Scene_Stringslist.new
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment