pigu_6

Nelderson| Text pop over events

Nov 24th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.85 KB | None | 0 0
  1. #===============================================================================
  2. # N.A.S.T.Y. Text Pop Over Events
  3. # Nelderson's Awesome Scripts To You
  4. #
  5. # By: Nelderson
  6. # Last Updated: 3/18/20112
  7. #
  8. # Version 1.0 - 3/17/2012
  9. #
  10. #===============================================================================
  11. #
  12. # Update History:
  13. # - Version 1.0 - Initial release, 1st Resource Script for rpgmakervxace.net
  14. #===============================================================================
  15. # *Features:
  16. # - This script creates text above an event or the player on a map
  17. #
  18. # *Initial Setup
  19. # - This script has a small setup section to define a few Defaults when
  20. # text is first put up above an event's head:
  21. #
  22. # DEF_TEXT_COLOR - Is the default text color when not defined in the
  23. # script call. When you pick a color you have to use
  24. # the form:
  25. #
  26. # Color.new(r,g,b,a) - Where r = red, g = green,
  27. # b = blue, and a = alpha
  28. #
  29. # DEF_TEXT_SIZE - This is the default text font size, pretty easy here.
  30. #
  31. # DEF_TEXT_FONT - This is the name of the default font that'll be used
  32. # for text pops that don't specify one in the script call
  33. #
  34. # *Script Call:
  35. #
  36. # - nel_textpop(:attribute => value,
  37. # :attribute2 => value,
  38. # :attribute3: => value,
  39. # )
  40. #
  41. # ** Where :attributes can be any one of the following:
  42. #
  43. # :text => Values will be in "quotes", and displays over event
  44. # (Defaults to "" when not defined)
  45. #
  46. # :event_id => The Event ID that will display text.
  47. # 0 = Current Event ID, -1 = Player,
  48. # -2 1stFollower, -3 2ndFollower, -4 3rdFollower
  49. # (Defaults to 0 when not defined)
  50. #
  51. # :time => This is the time that the text will last in FRAMES.
  52. # 60 FRAMES = 1 second,
  53. # *Note: Set :time => nil for the text to last forever*
  54. # (Defaults to nil when not defined)
  55. #
  56. # :font => This is the name of the font you want for the text.
  57. # Values with be in "quotes"
  58. # (Defaults to DEF_TEXT_FONT when not defined)
  59. #
  60. # :size => This changes the font size on the text displayed
  61. # (Defaults to DEF_TEXT_SIZE when not defined)
  62. #
  63. # :color => This changes the color of the text displayed
  64. # Values need to be => Color.new(r,g,b,a)
  65. # (Defaults to DEF_TEXT_COLOR when not defined)
  66. #
  67. # :bold => This makes the displayed text bold
  68. # Values need to be => true or false
  69. # (Defaults to false when not defined)
  70. #
  71. # :italic => This makes the displayed text italic
  72. # Values need to be => true or false
  73. # (Defaults to false when not defined)
  74. #
  75. # *Instructions
  76. # -You can place the script call nel_textpop in any event
  77. #
  78. # -You don't have to define every attribute, they will automatically
  79. # go to the defaults to make things easier.
  80. #
  81. # *Sample Call
  82. #
  83. # nel_textpop(
  84. # :text => "I hate you!",
  85. # :event_id => -1,
  86. # :bold => true,
  87. # :italic => true,
  88. # :time => 120,
  89. # :font => "Vrinda",
  90. # :size => 64,
  91. # :color => Color.new(220,20,60),
  92. # )
  93. #
  94. #===============================================================================
  95. # Credits:
  96. # -Nelderson, tomoaky, and IceDragon
  97. #===============================================================================
  98. # Based off: RGSS2_namepop Ver0.02
  99. # tomoaky (http://hikimoki.sakura.ne.jp/)
  100. #===============================================================================
  101.  
  102. module NEL
  103. #Default text pop font
  104. DEF_TEXT_FONT = "Myriad"
  105.  
  106. #Default text pop font size
  107. DEF_TEXT_SIZE = 16
  108.  
  109. #Default text pop color
  110. DEF_TEXT_COLOR = Color.new(255,255,255,255)# <== White
  111.  
  112. end #<=== Don't Touch
  113.  
  114. #========#======================#====#================================#========#
  115. #--------# #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  116. #--------# End of Customization #----# Editing will cause death by #--------#
  117. #--------# #----# Zetu Stabbing your heart </3 #--------#
  118. #========#======================#====#================================#========#
  119.  
  120. # // 02/03/2012 [
  121. #Collects the hash keys in order, and then passes the values
  122. class Hash
  123. # // IceDragon <=== *The Ultimate in Awesome OTL
  124. def get_values(*args)
  125. args.collect {|a|self[a]}
  126. end
  127. end
  128. # // 02/03/2012 ]
  129.  
  130. class Game_Interpreter
  131. include NEL
  132. #IceDragon helped make this script call easier with awesomeness...Thanks Icy!
  133. def nel_textpop(*args)
  134. if(args[0].is_a?(Hash))
  135. text, ev_id, time, size, color, font, bold, ital = args[0].get_values(:text,:event_id,:time,:size,:color,:font,:bold,:italic)
  136. else
  137. text, ev_id, time, size, color, font, bold, ital = *args
  138. end
  139. char = nel_get_character(ev_id || 0)
  140. return unless(char)
  141. char.namepop_size = size || DEF_TEXT_SIZE
  142. char.namepop_color= color || DEF_TEXT_COLOR
  143. char.namepop_time = time || nil
  144. char.namepop = text || ""
  145. char.namepop_font = font || DEF_TEXT_FONT
  146. char.namepop_bold = !!bold # // Convert to Bool
  147. char.namepop_ital = !!ital
  148. char.textpop_flag = true #Forces refresh
  149. end
  150.  
  151. #--------------------------------------------------------------------------
  152. # *New Method: nel_get_character
  153. #
  154. # Instead of original get_character, this include Followers in the argument
  155. #--------------------------------------------------------------------------
  156. def nel_get_character(param)
  157.  
  158. if $game_party.in_battle
  159. nil
  160. elsif param < 0
  161. case param
  162. when -1; return $game_player
  163. else; return $game_player.followers[(param + 2) * (-1)]
  164. end
  165. else
  166. events = same_map? ? $game_map.events : {}
  167. events[param > 0 ? param : @event_id]
  168. end
  169. end
  170. #--------------------------------------------------------------------------
  171. end
  172. #==============================================================================
  173. # ¡ Game_Character
  174. #==============================================================================
  175. class Game_Character
  176. #--------------------------------------------------------------------------
  177. # œ œöŠJƒCƒ“ƒXƒ^ƒ“ƒX•ϐ”
  178. #--------------------------------------------------------------------------
  179. attr_accessor :namepop
  180. attr_accessor :namepop_size
  181. attr_accessor :namepop_color
  182. attr_accessor :namepop_time
  183. attr_accessor :namepop_font
  184. attr_accessor :namepop_bold
  185. attr_accessor :namepop_ital
  186. attr_accessor :textpop_flag #Instant update if script call is used
  187.  
  188. #--------------------------------------------------------------------------
  189. alias nel_font_type_init initialize
  190. def initialize
  191. @namepop_font = NEL::DEF_TEXT_FONT
  192. @namepop_bold = false
  193. @namepop_ital = false
  194. @textpop_flag = false
  195. nel_font_type_init
  196. end
  197. end
  198. #==============================================================================
  199. # ¡ Sprite_Character
  200. #==============================================================================
  201. class Sprite_Character < Sprite_Base
  202. alias nel_textx_pop_initi initialize
  203. def initialize(*args)
  204. @timer = 0
  205. nel_textx_pop_initi(*args)
  206. end
  207. #--------------------------------------------------------------------------
  208. # œ ‰ð•ú
  209. #--------------------------------------------------------------------------
  210. alias tnpop_sprite_character_dispose dispose
  211. def dispose
  212. dispose_namepop
  213. tnpop_sprite_character_dispose
  214. end
  215. #--------------------------------------------------------------------------
  216. # œ ƒtƒœ[ƒ€XV
  217. #--------------------------------------------------------------------------
  218. alias tnpop_sprite_character_update update
  219. def update
  220. tnpop_sprite_character_update #Original Update
  221. if @timer > 0 && @character.textpop_flag == false#Skip when script called
  222. @timer -= 1
  223. update_text_pos
  224. if @timer <= 0
  225. @namepop_sprite.visible = false
  226. @namepop_sprite.opacity = 255 #Reset opacity just in case
  227. @namepop_sprite = nil
  228. @character.namepop = nil
  229. @namepop = nil
  230. @tmer_rat = nil #Reset ratio, just to avoid issues
  231. elsif @timer < 60
  232. #Fade out text gradually within the last 60 frames
  233. @tmer_rat ||= 255/@timer
  234. @namepop_sprite.opacity -= @tmer_rat
  235. end
  236. else
  237. update_namepop
  238. if @character.textpop_flag == true #If script call
  239. @namepop = @character.namepop
  240. start_namepop
  241. end
  242. end
  243. end
  244.  
  245. def update_text_pos
  246. @namepop_sprite.x = x
  247. @namepop_sprite.y = y - height
  248. @namepop_sprite.z = z + 200
  249. end
  250.  
  251. #--------------------------------------------------------------------------
  252. # › namepop‚ÌŠJŽn
  253. #--------------------------------------------------------------------------
  254. def start_namepop
  255. dispose_namepop
  256. return if @namepop == "none" or @namepop == nil
  257. @namepop_sprite = ::Sprite.new(viewport)
  258. b_width = @namepop.size * 8
  259. b_height = @character.namepop_size + 20
  260. @namepop_sprite.ox = 80 + (b_width/2)
  261. @namepop_sprite.oy = 16 + (b_height/2) #16
  262. @namepop_sprite.bitmap = Bitmap.new(b_width+160, b_height)
  263. ###Change Font, Font Size, Color, and Time based off Character values##
  264. @namepop_sprite.bitmap.font.color = @character.namepop_color
  265. @namepop_sprite.bitmap.font.size = @character.namepop_size
  266. @namepop_sprite.bitmap.font.name = [@character.namepop_font]
  267. @namepop_sprite.bitmap.font.bold = @character.namepop_bold
  268. @namepop_sprite.bitmap.font.italic = @character.namepop_ital
  269. @namepop_sprite.bitmap.draw_text(0, 0, b_width+160, b_height, @namepop, 1)
  270. @namepop_time = @character.namepop_time
  271. update_namepop(@namepop_time) #Pass a timer variable
  272. @character.textpop_flag = false
  273. end
  274. #--------------------------------------------------------------------------
  275. # › namepop‚̍XV
  276. #--------------------------------------------------------------------------
  277. def update_namepop(time = nil) #Add a timer variable
  278. if @namepop_sprite != nil
  279. @namepop_sprite.x = x
  280. @namepop_sprite.y = y - height
  281. @namepop_sprite.z = z + 200
  282. if time != nil
  283. @timer = time
  284. @namepop_time = 0
  285. end
  286. end
  287. end
  288. #--------------------------------------------------------------------------
  289. # › namepop‚̉ð•ú
  290. #--------------------------------------------------------------------------
  291. def dispose_namepop
  292. if @namepop_sprite != nil
  293. @namepop_sprite.bitmap.dispose
  294. @namepop_sprite.dispose
  295. @namepop_sprite = nil
  296. end
  297. end
  298. end
Advertisement
Add Comment
Please, Sign In to add comment