Advertisement
neonblack

Event Names Pop-up Script V0.2

Jul 20th, 2012
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.53 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Event Names Pop-up script                                                   #
  3. #  Version 0.2                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #  Requested by: Kilim                                                         #
  9. #                                                                              #
  10. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  11. #  3.0 Unported License. To view a copy of this license, visit                 #
  12. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  13. #  Permissions beyond the scope of this license are available at               #
  14. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  15. #                                                                              #
  16. #      Contact:                                                                #
  17. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  18. ###--------------------------------------------------------------------------###
  19.  
  20. ###--------------------------------------------------------------------------###
  21. #      Revision information:                                                   #
  22. #  V0.2 - 7.20.2012                                                            #
  23. #   Debug                                                                      #
  24. #  V0.1 - 7.20.2012                                                            #
  25. #   Wrote main script                                                          #
  26. ###--------------------------------------------------------------------------###
  27.  
  28. ###--------------------------------------------------------------------------###
  29. #      Compatibility:                                                          #
  30. #  Alias       - Game_Map: update                                              #
  31. #  New Objects - Game_Map: update_events_pop_check                             #
  32. #                Game_Event: check_player_over, get_tp_name,                   #
  33. #                            display_pop_name, hide_pop_name                   #
  34. ###--------------------------------------------------------------------------###
  35.  
  36. ###--------------------------------------------------------------------------###
  37. #      Instructions:                                                           #
  38. #  Place this script in the "Materials" section of the scripts above main.     #
  39. #  This allows you to make a name pop up above an event while the player is    #
  40. #  standing on top of it.  To do this, place a comment inside the event with   #
  41. #  the following tag:                                                          #
  42. #                                                                              #
  43. #      tp name<text> - Simply change "text" to the text you would like to      #
  44. #                      display.  For example, to display "Dark Forest" you     #
  45. #                      would use "tp name<Dark Forest>".                       #
  46. ###--------------------------------------------------------------------------###
  47.  
  48. ###--------------------------------------------------------------------------###
  49. #      Config:                                                                 #
  50. #  These are the default values used by several of the functions in the        #
  51. #  script.  You may change these values as you find your game requires in      #
  52. #  order to give the player a better playing experience based on your game.    #
  53. #                                                                              #
  54. module CP             # Do not                                                 #
  55. module TRANSFER_NAMES #  change these.                                         #
  56. #                                                                              #
  57. ###-----                                                                -----###
  58. # Settings for the pop-up text.                                                #
  59. BOLD = false # Default = false                                                 #
  60. SIZE = 28 # Default = 28                                                       #
  61. #                                                                              #
  62. # The number of pixels the pop-up appears over the event.                      #
  63. Y_OFFSET = 40 # Default = 40                                                   #
  64. #                                                                              #
  65. ###-----                                                                -----###
  66.  
  67.  
  68. ###--------------------------------------------------------------------------###
  69. #  The following lines are the actual core code of the script.  While you are  #
  70. #  certainly invited to look, modifying it may result in undesirable results.  #
  71. #  Modify at your own risk!                                                    #
  72. ###--------------------------------------------------------------------------###
  73.  
  74.  
  75. EXP_NAME = /tp[ ]name\<([\d\s\w]+)\>/i  ## The REGEXP check thing....
  76.  
  77. end
  78. end
  79.  
  80. $imported = {} if $imported.nil?
  81. $imported["CP_TRANSFER_NAMES"] = 0.2
  82.  
  83. class Game_Event < Game_Character
  84.   def check_player_over  ## Check if the player is on the event.
  85.     $game_player.pos?(@x, @y)
  86.   end
  87.  
  88.   def get_tp_name
  89.     return nil if (@list.nil? || @list.empty?)
  90.     @list.each do |line|  ## Looks for the name in the code.
  91.       next unless (line.code == 108 || line.code == 408)
  92.       case line.parameters[0]
  93.       when CP::TRANSFER_NAMES::EXP_NAME
  94.         tn = $1.to_s
  95.         return tn
  96.       end
  97.     end
  98.     return nil
  99.   end
  100. end
  101.  
  102. class Sprite_Character < Sprite_Base
  103.   alias cp_ct_update update unless $@
  104.   def update  ## Alias update.
  105.     cp_ct_update
  106.     display_pop_name
  107.   end
  108.  
  109.   alias cp_ct_dispose dispose unless $@
  110.   def dispose  ## Alias dispose.
  111.     hide_pop_name
  112.     cp_ct_dispose
  113.   end
  114.  
  115.   def display_pop_name  ## Creates the pop-up.
  116.     return unless @character.is_a?(Game_Event)
  117.     return hide_pop_name unless @character.check_player_over
  118.     tn = @character.get_tp_name
  119.     return if tn.nil?
  120.     if @pop_sprite.nil?
  121.       display = ::Sprite.new
  122.       temp = Bitmap.new(Graphics.width, 32)
  123.       temp.font.bold = CP::TRANSFER_NAMES::BOLD
  124.       temp.font.size = CP::TRANSFER_NAMES::SIZE
  125.       bw = temp.text_size(tn).width + 4
  126.       bh = temp.text_size(tn).height + 4
  127.       display.bitmap = Bitmap.new(bw, bh)
  128.       display.bitmap.font.bold = CP::TRANSFER_NAMES::BOLD
  129.       display.bitmap.font.size = CP::TRANSFER_NAMES::SIZE
  130.       display.bitmap.draw_text(0, 0, bw, bh, tn)
  131.       display.z = 301
  132.       display.ox = display.width / 2
  133.       display.oy = display.height
  134.       @pop_sprite = display
  135.     end
  136.     @pop_sprite.x = @character.screen_x
  137.     @pop_sprite.y = @character.screen_y - CP::TRANSFER_NAMES::Y_OFFSET
  138.   end
  139.  
  140.   def hide_pop_name  ## Hides the pop-up.
  141.     return if @pop_sprite.nil?
  142.     @pop_sprite.dispose
  143.     @pop_sprite = nil
  144.   end
  145. end
  146.  
  147.  
  148. ###--------------------------------------------------------------------------###
  149. #  End of script.                                                              #
  150. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement