Advertisement
SSTrihan

HorrorVale map system script

Feb 22nd, 2022
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Don't remove this header!
  3. #-------------------------------------------------------------------------------
  4. # Custom Map System Script
  5. # by Trihan
  6. #
  7. # Version : 1.0
  8. #
  9. # This script is commissioned by Batworks Software.
  10. #-------------------------------------------------------------------------------
  11.  
  12. #-------------------------------------------------------------------------------
  13. # Version History
  14. #-------------------------------------------------------------------------------
  15. # 1.0 - Initial script.
  16. #-------------------------------------------------------------------------------
  17.  
  18. #-------------------------------------------------------------------------------
  19. # All pictures are located in the Graphics/Maps folder.
  20. #
  21. # To call the map scene, use the following script call
  22. #
  23. # SceneManager.call(Scene_MapSystem)
  24. #
  25. # This script runs mostly automatically. All you need to configure is the
  26. # graphic and offset for the cursor, the graphic for the player marker, and
  27. # the regex pattern to use for map filenames.
  28. #
  29. # The filename by default needs to meet the following pattern:
  30. # AreaXMap + name of map + _markerx_markery
  31. #
  32. # For example, Area1MapAbandonedShack_141_198.png
  33. # This will mark the map as belonging to area 1, connect it to the map named
  34. # AbandonedShack, and display the marker at (141, 198) on the screen.
  35. #
  36. # If you change the regex pattern, please ensure that (\d+) still appears in
  37. # it somewhere, otherwise the script won't be able to determine areas.
  38. #-------------------------------------------------------------------------------
  39. module TLBMapSystem
  40. #-------------------------------------------------------------------------------
  41. # Config
  42.  
  43. CursorIcon = "fingerpointer"
  44. PlayerMarker = "alicemarker"
  45. CursorXOffset = 5
  46. CursorYOffset = 0
  47. MapRegex = /Area(\d+)Map.*/
  48.  
  49. # ** End Config **
  50. #
  51. # WARNING: Editing anything beyond this point may result in the script no
  52. # longer functioning as intended.
  53. #-------------------------------------------------------------------------------
  54. end
  55.  
  56. module Cache; def self.maps(filename); load_bitmap("Graphics/Maps/", filename); end; end
  57.  
  58. class Game_System
  59. attr_accessor :mapdata
  60.  
  61. alias :tlb_mapsystem_initialize :initialize
  62. def initialize
  63. tlb_mapsystem_initialize
  64. create_map_data
  65. end
  66.  
  67. def create_map_data
  68. @mapdata = {}
  69. regexpattern = TLBMapSystem::MapRegex
  70. files = Dir.entries("Graphics/Maps")
  71. .select { |file| file =~ regexpattern }
  72. .map { |file| File.basename(file, ".png") }
  73. areas = []
  74. files.each { |file|
  75. area = file.scan(regexpattern)
  76. if area.size > 0 && !areas.include?(area[0][0])
  77. areas.push(area[0][0])
  78. end
  79. }
  80. areas.each { |area|
  81. regexpattern = Regexp.new("Area#{area}Map(.*)")
  82. @mapdata[area] = files
  83. .select { |file| file =~ regexpattern }
  84. .map { |file|
  85. data = file.scan(regexpattern)[0][0].split("_")
  86. {
  87. :name => data[0],
  88. :filename => file,
  89. :cursor_x => data[1].to_i,
  90. :cursor_y => data[2].to_i,
  91. :visited => false
  92. }
  93. }
  94. }
  95. end
  96.  
  97. def get_visited_maps(area)
  98. if @mapdata[area]
  99. @mapdata[area].select { |map| map[:visited] }
  100. else
  101. []
  102. end
  103. end
  104.  
  105. def visit_map(area, mapname)
  106. map = @mapdata[area].select { |map| map[:name] == mapname }
  107. if map.size > 0
  108. map[0][:visited] = true
  109. end
  110. end
  111. end
  112.  
  113. class Game_Map
  114. alias :tlb_mapsystem_setup :setup
  115. def setup(map_id)
  116. tlb_mapsystem_setup(map_id)
  117. mapname = $data_mapinfos[map_id].name
  118. area = get_current_area
  119. if area
  120. $game_system.visit_map(area, mapname)
  121. end
  122. end
  123.  
  124. def get_current_area
  125. area = self.note.scan(/<area: ?(\d+)/)
  126. if area.size > 0
  127. return area[0][0]
  128. else
  129. return nil
  130. end
  131. end
  132.  
  133. def get_map(mapname)
  134. area = get_current_area
  135. if area
  136. map = $game_system.mapdata[area].select { |map| map[:name] == mapname }
  137. if map
  138. map[0]
  139. else
  140. nil
  141. end
  142. end
  143. end
  144.  
  145. def get_current_map
  146. mapname = $data_mapinfos[@map_id].name
  147. get_map(mapname)
  148. end
  149.  
  150. def get_directional_map(start_map, direction)
  151. map_match = $data_mapinfos.select{|key, value| value.name == start_map[:name]}.keys
  152. if map_match
  153. map_id = map_match.first
  154. map = nil
  155. if map_id
  156. mapfile = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  157. case direction
  158. when 2
  159. map = mapfile.note.scan(/<south: ?(.*)>/)
  160. when 4
  161. map = mapfile.note.scan(/<west: ?(.*)>/)
  162. when 6
  163. map = mapfile.note.scan(/<east: ?(.*)>/)
  164. when 8
  165. map = mapfile.note.scan(/<north: ?(.*)>/)
  166. else
  167. map = nil
  168. end
  169. if map && map.size > 0
  170. map_strings = map[0][0].split("/")
  171. map_strings.each{|string|
  172. map_obj = get_map(string)
  173. if map_obj[:visited]
  174. return map_obj
  175. end
  176. }
  177. else
  178. nil
  179. end
  180. end
  181. end
  182. nil
  183. end
  184.  
  185. def get_south_map(start_map)
  186. get_directional_map(start_map, 2)
  187. end
  188.  
  189. def get_west_map(start_map)
  190. get_directional_map(start_map, 4)
  191. end
  192.  
  193. def get_east_map(start_map)
  194. get_directional_map(start_map, 6)
  195. end
  196.  
  197. def get_north_map(start_map)
  198. get_directional_map(start_map, 8)
  199. end
  200. end
  201.  
  202. class Window_MapLabel < Window_Base
  203. def initialize
  204. super(0, 0, Graphics.width, 120)
  205. @text = ""
  206. refresh
  207. end
  208.  
  209. def set_text(text)
  210. @text = text
  211. refresh
  212. end
  213.  
  214. def refresh
  215. create_contents
  216. draw_text(0, 0, 32, line_height, @text)
  217. end
  218. end
  219.  
  220. class Window_Mystery < Window_Base
  221. def initialize
  222. super(0, 0, 100, fitting_height(1))
  223. self.width = text_size("???").width + standard_padding * 2
  224. create_contents
  225. self.x = Graphics.width / 2 - self.width / 2
  226. self.y = Graphics.height / 2 - self.height / 2
  227. self.opacity = 0
  228. draw_text(0, 0, 32, line_height, "???")
  229. end
  230. end
  231.  
  232. class Scene_MapSystem < Scene_Base
  233. def start
  234. super
  235. create_background
  236. create_map
  237. @current_map = $game_map.get_current_map
  238. @selected_map = $game_map.get_current_map
  239. create_player_marker
  240. create_pointer
  241. create_label_window
  242. create_mystery_window
  243. end
  244.  
  245. def terminate
  246. super
  247. dispose_background
  248. dispose_map
  249. dispose_player_marker
  250. dispose_pointer
  251. end
  252.  
  253. def update
  254. super
  255. end
  256.  
  257. def create_background
  258. @sprite = Sprite.new
  259. @sprite.bitmap = Cache.maps("Mapbackground")
  260. center_sprite(@sprite)
  261. end
  262.  
  263. def create_map
  264. maps = $game_system.get_visited_maps($game_map.get_current_area)
  265. if maps.size > 0
  266. @area_sprites = []
  267. maps.each { |map|
  268. sprite = Sprite.new
  269. sprite.bitmap = Cache.maps(map[:filename])
  270. center_sprite(sprite)
  271. @area_sprites.push(sprite)
  272. }
  273. end
  274. end
  275.  
  276. def create_player_marker
  277. @player_marker_sprite = Sprite.new
  278. @player_marker_sprite.bitmap = Cache.maps(TLBMapSystem::PlayerMarker)
  279. if @current_map
  280. x = @current_map[:cursor_x]
  281. y = @current_map[:cursor_y]
  282. @player_marker_sprite.x = x if x
  283. @player_marker_sprite.y = y if y
  284. @player_marker_sprite.z += 100
  285. end
  286. end
  287.  
  288. def create_pointer
  289. @pointer_sprite = Sprite.new
  290. @pointer_sprite.bitmap = Cache.menus(TLBMapSystem::CursorIcon)
  291. if @selected_map
  292. x = @selected_map[:cursor_x] + TLBMapSystem::CursorXOffset
  293. y = @selected_map[:cursor_y] + TLBMapSystem::CursorYOffset
  294. @pointer_sprite.x = x if x
  295. @pointer_sprite.y = y if y
  296. @pointer_sprite.z += 200
  297. end
  298. end
  299.  
  300. def create_label_window
  301. @label_window = Window_MapLabel.new
  302. if @selected_map
  303. refresh_label
  304. end
  305. end
  306.  
  307. def create_mystery_window
  308. @mystery_window = Window_Mystery.new
  309. if @area_sprites && @area_sprites.size > 0
  310. @mystery_window.hide
  311. end
  312. end
  313.  
  314. def refresh_label
  315. map_text = @selected_map[:name].gsub(/([a-z])([A-Z])/, '\1 \2')
  316. @label_window.set_text(map_text)
  317. end
  318.  
  319. def update
  320. super
  321. if Input.trigger?(:B)
  322. return_scene
  323. end
  324. if @area_sprites && @area_sprites.size > 0
  325. if Input.trigger?(:DOWN)
  326. map = $game_map.get_south_map(@selected_map)
  327. end
  328. if Input.trigger?(:LEFT)
  329. map = $game_map.get_west_map(@selected_map)
  330. end
  331. if Input.trigger?(:RIGHT)
  332. map = $game_map.get_east_map(@selected_map)
  333. end
  334. if Input.trigger?(:UP)
  335. map = $game_map.get_north_map(@selected_map)
  336. end
  337. end
  338. if map
  339. x = map[:cursor_x] + TLBMapSystem::CursorXOffset
  340. y = map[:cursor_y] + TLBMapSystem::CursorYOffset
  341. @pointer_sprite.x = x if x
  342. @pointer_sprite.y = y if y
  343. @selected_map = map
  344. refresh_label
  345. end
  346. if Graphics.frame_count % 60 == 0 && @area_sprites
  347. current_sprite = @area_sprites.select { |sprite| sprite.bitmap == Cache.maps(@current_map[:filename]) }
  348. if current_sprite
  349. current_sprite[0].flash(Color.new(255, 255, 255, 255), 60)
  350. end
  351. end
  352. if @area_sprites
  353. @area_sprites.each {|sprite| sprite.update }
  354. end
  355. end
  356.  
  357. def dispose_background
  358. @sprite.bitmap.dispose
  359. @sprite.dispose
  360. end
  361.  
  362. def dispose_map
  363. if @area_sprites
  364. @area_sprites.each { |sprite|
  365. sprite.bitmap.dispose
  366. sprite.dispose
  367. }
  368. end
  369. end
  370.  
  371. def dispose_player_marker
  372. @player_marker_sprite.bitmap.dispose
  373. @player_marker_sprite.dispose
  374. end
  375.  
  376. def dispose_pointer
  377. @pointer_sprite.bitmap.dispose
  378. @pointer_sprite.dispose
  379. end
  380.  
  381. def center_sprite(sprite)
  382. sprite.ox = sprite.bitmap.width / 2
  383. sprite.oy = sprite.bitmap.height / 2
  384. sprite.x = Graphics.width / 2
  385. sprite.y = Graphics.height / 2
  386. end
  387. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement