Advertisement
Dekita

$D13x - Character Lanterns v1.0

Mar 13th, 2014
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. if true # << Make true to use this script, false to disable.
  2. #===============================================================================
  3. #
  4. # ☆ $D13x - Character Lanterns
  5. # -- Author : Dekita
  6. # -- Version : 1.0
  7. # -- Level : Easy / Normal
  8. # -- Requires : N/A
  9. # -- Engine : RPG Maker VX Ace.
  10. #
  11. #===============================================================================
  12. # ☆ Import
  13. #-------------------------------------------------------------------------------
  14. $D13x={}if$D13x==nil
  15. $D13x[:Character_Lanterns]=true
  16. #===============================================================================
  17. # ☆ Updates
  18. #-------------------------------------------------------------------------------
  19. # D /M /Y
  20. # 11/o3/2014 - Small Efficieny Update,
  21. # o9/o3/2o14 - Started, Finished
  22. #
  23. #===============================================================================
  24. # ☆ Introduction
  25. #-------------------------------------------------------------------------------
  26. # This script allows for all characters to have a lantern graphic 'attached'
  27. # to their sprite. You can easily show/hide the lantern image using simple
  28. # script calls.
  29. #
  30. # Remember to copy the Graphics/$D13x/Lights folder/images into your project.
  31. #
  32. #===============================================================================
  33. # ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
  34. #===============================================================================
  35. # 1. You MUST give credit to "Dekita" !!
  36. # 2. You are NOT allowed to repost this script.(or modified versions)
  37. # 3. You are NOT allowed to convert this script.
  38. # 4. You are NOT allowed to use this script for Commercial games.
  39. # 5. ENJOY!
  40. #
  41. # "FINE PRINT"
  42. # By using this script you hereby agree to the above terms and conditions,
  43. # if any violation of the above terms occurs "legal action" may be taken.
  44. # Not understanding the above terms and conditions does NOT mean that
  45. # they do not apply to you.
  46. # If you wish to discuss the terms and conditions in further detail you can
  47. # contact me at http://dekitarpg.wordpress.com/
  48. #
  49. #===============================================================================
  50. # ☆ Instructions
  51. #-------------------------------------------------------------------------------
  52. # Place Below " ▼ Materials " and Above " ▼ Main " in your script editor.
  53. #
  54. #===============================================================================
  55. # ☆ Script Calls
  56. #-------------------------------------------------------------------------------
  57. # char.lantern_on?
  58. # returns true / false depending on whether char's lantern is on.
  59. #
  60. #-------------------------------------------------------------------------------
  61. # char.show_lantern
  62. # shows lantern image for char
  63. #
  64. #-------------------------------------------------------------------------------
  65. # char.hide_lantern
  66. # hides lantern image for char
  67. #
  68. #-------------------------------------------------------------------------------
  69. # char.alt_lantern
  70. # alternates show/hide lantern for char
  71. #
  72. #-------------------------------------------------------------------------------
  73. # IMPORTANT:
  74. # char = $game_map.events[x] OR $game_player OR this_Event
  75. #
  76. # eg.
  77. # $game_player.alt_lantern
  78. # will change the lantern visibility, if its on, it will go off and vice versa..
  79. #
  80. # NOTE: this_event can only be used if you have my core script (v2.3+)
  81. # this_event will gain the id of the event using the script call.
  82. #
  83. #===============================================================================
  84. # ☆ HELP
  85. #-------------------------------------------------------------------------------
  86. # N/A
  87. #===============================================================================
  88. module Easy_Lantern
  89. #===============================================================================
  90. #-----------------------------------------------------------------------------
  91. # The folder your lantern graphics are stored in
  92. #-----------------------------------------------------------------------------
  93. Folder = "Graphics/$D13x/Lights/"
  94. #-----------------------------------------------------------------------------
  95. # The graphic settings for your lantern.
  96. #-----------------------------------------------------------------------------
  97. Graphic = ["$lantern_left", 0] # ['image name', hue]
  98. #-----------------------------------------------------------------------------
  99. # The hand your char's hold the lantern in.
  100. #-----------------------------------------------------------------------------
  101. Facing = :left
  102. #####################
  103. # CUSTOMISATION END #
  104. end #####################
  105. #☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#
  106. # #
  107. # http://dekitarpg.wordpress.com/ #
  108. # #
  109. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#
  110. #===============================================================================#
  111. # ARE YOU MODIFYING BEYOND THIS POINT? \.\. #
  112. # YES?\.\. #
  113. # OMG, REALLY? \| #
  114. # WELL SLAP MY FACE AND CALL ME A DRAGONITE.\..\.. #
  115. # I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\.. #
  116. #===============================================================================#
  117. module Cache
  118. #===============================================================================
  119. #-----------------------------------------------------------------------------
  120. #
  121. #-----------------------------------------------------------------------------
  122. def self.lantern(filename, hue = 0)
  123. load_bitmap(Easy_Lantern::Folder, filename, hue)
  124. end
  125. end
  126.  
  127. #===============================================================================
  128. class Game_CharacterBase
  129. #===============================================================================
  130. #-----------------------------------------------------------------------------
  131. #
  132. #-----------------------------------------------------------------------------
  133. alias :init_ezaylantern :initialize
  134. #-----------------------------------------------------------------------------
  135. #
  136. #-----------------------------------------------------------------------------
  137. def initialize
  138. @lantern = false
  139. @lant_in = 0
  140. init_ezaylantern
  141. end
  142. #-----------------------------------------------------------------------------
  143. #
  144. #-----------------------------------------------------------------------------
  145. def lantern_on?
  146. @lantern
  147. end
  148. #-----------------------------------------------------------------------------
  149. #
  150. #-----------------------------------------------------------------------------
  151. def show_lantern
  152. @lantern = true
  153. end
  154. #-----------------------------------------------------------------------------
  155. #
  156. #-----------------------------------------------------------------------------
  157. def hide_lantern
  158. @lantern = false
  159. end
  160. #-----------------------------------------------------------------------------
  161. #
  162. #-----------------------------------------------------------------------------
  163. def alt_lantern
  164. @lantern = !@lantern
  165. end
  166. #-----------------------------------------------------------------------------
  167. #
  168. #-----------------------------------------------------------------------------
  169. def lantern_index
  170. @lant_in
  171. end
  172. end
  173.  
  174. #===============================================================================
  175. class Sprite_Character < Sprite_Base
  176. #===============================================================================
  177. #-----------------------------------------------------------------------------
  178. # Alias List
  179. #-----------------------------------------------------------------------------
  180. alias :init_spr_char_la :initialize
  181. alias :disp_spr_char_la :dispose
  182. alias :updt_spr_char_la :update
  183. alias :set_char_lantern :set_character_bitmap
  184. #-----------------------------------------------------------------------------
  185. # Object Initialization
  186. #-----------------------------------------------------------------------------
  187. def initialize(viewport, character = nil)
  188. @char_viewport = viewport
  189. @char_setup = character
  190. init_spr_char_la(viewport, character)
  191. init_lantern
  192. end
  193. #-----------------------------------------------------------------------------
  194. # Set Char Bitmap
  195. #-----------------------------------------------------------------------------
  196. def set_character_bitmap
  197. set_char_lantern
  198. end
  199. #-----------------------------------------------------------------------------
  200. #
  201. #-----------------------------------------------------------------------------
  202. def init_lantern
  203. disp_lantern
  204. vp = @char_viewport
  205. ch = @char_setup
  206. if ch && ch.lantern_on?
  207. @lantern_image = Sprite_Lantern.new(vp,ch)
  208. end
  209. end
  210. #-----------------------------------------------------------------------------
  211. #
  212. #-----------------------------------------------------------------------------
  213. def dispose
  214. disp_lantern
  215. disp_spr_char_la
  216. end
  217. #-----------------------------------------------------------------------------
  218. #
  219. #-----------------------------------------------------------------------------
  220. def disp_lantern
  221. return unless @lantern_image
  222. return if @lantern_image.disposed?
  223. @lantern_image.dispose
  224. @lantern_image = nil
  225. end
  226. #-----------------------------------------------------------------------------
  227. #
  228. #-----------------------------------------------------------------------------
  229. def update
  230. updt_lantern
  231. updt_spr_char_la
  232. end
  233. #-----------------------------------------------------------------------------
  234. #
  235. #-----------------------------------------------------------------------------
  236. def updt_lantern
  237. return init_lantern unless @lantern_image
  238. return disp_lantern unless @char_setup.lantern_on?
  239. @lantern_image.update unless @lantern_image.disposed?
  240. end
  241. end
  242.  
  243. #===============================================================================
  244. class Sprite_Lantern < Sprite
  245. #===============================================================================
  246. #-----------------------------------------------------------------------------
  247. #
  248. #-----------------------------------------------------------------------------
  249. def initialize(viewport,character = nil)
  250. super(viewport)
  251. @character = character
  252. @character_name = Easy_Lantern::Graphic[0]
  253. @character_hue = Easy_Lantern::Graphic[1]
  254. @character_index = @character.lantern_index
  255. self.bitmap = Cache.lantern(@character_name,@character_hue)
  256. sign = @character_name[/^[\!\$]./]
  257. if sign && sign.include?('$')
  258. @cw = bitmap.width / 3
  259. @ch = bitmap.height / 4
  260. else
  261. @cw = bitmap.width / 12
  262. @ch = bitmap.height / 8
  263. end
  264. self.ox = @cw / 2
  265. self.oy = @ch
  266. update_src_rect
  267. update_position
  268. update_other
  269. update_z
  270. end
  271. #-----------------------------------------------------------------------------
  272. #
  273. #-----------------------------------------------------------------------------
  274. def dispose
  275. super
  276. if self.bitmap != nil
  277. self.bitmap.dispose
  278. end
  279. end
  280. #-----------------------------------------------------------------------------
  281. #
  282. #-----------------------------------------------------------------------------
  283. def update
  284. super
  285. update_src_rect
  286. update_position
  287. update_other
  288. update_z
  289. end
  290. #-----------------------------------------------------------------------------
  291. #
  292. #-----------------------------------------------------------------------------
  293. def update_src_rect
  294. index = @character.character_index
  295. pattern = @character.pattern < 3 ? @character.pattern : 1
  296. sx = (index % 4 * 3 + pattern) * @cw
  297. sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  298. self.src_rect.set(sx, sy, @cw, @ch)
  299. end
  300. #-----------------------------------------------------------------------------
  301. #
  302. #-----------------------------------------------------------------------------
  303. def update_position
  304. self.x = @character.screen_x
  305. self.y = @character.screen_y
  306. end
  307. #-----------------------------------------------------------------------------
  308. #
  309. #-----------------------------------------------------------------------------
  310. def update_other
  311. self.opacity = @character.opacity
  312. self.blend_type = @character.blend_type
  313. self.bush_depth = @character.bush_depth
  314. self.visible = !@character.transparent
  315. end
  316. #-----------------------------------------------------------------------------
  317. #
  318. #-----------------------------------------------------------------------------
  319. def update_z
  320. ch = @character
  321. case Easy_Lantern::Facing
  322. when :left then z = [ch.screen_z,ch.screen_z,ch.screen_z-1,ch.screen_z-1]
  323. when :right then z = [ch.screen_z,ch.screen_z-1,ch.screen_z,ch.screen_z-1]
  324. else ; return self.z = ch.screen_z
  325. end
  326. case ch.direction
  327. when 2 then self.z = z[0]
  328. when 4 then self.z = z[1]
  329. when 6 then self.z = z[2]
  330. when 8 then self.z = z[3]
  331. end
  332. end
  333. end
  334.  
  335. #==============================================================================#
  336. # http://dekitarpg.wordpress.com/ #
  337. #==============================================================================#
  338. end # if true # << Make true to use this script, false to disable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement