DarkShadow44

RPGMaker script - Remember Event Positions

Mar 22nd, 2015
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.94 KB | None | 0 0
  1. =begin
  2.  
  3. Name: Remember Event Position
  4. Author: DarkShadow44
  5. Description: Saves additional information for events that RPGMaker normally doesn't save
  6.  
  7. Instructions: Just Copy the script into your script editor, under "Materials".
  8. For convenience the door events are skipped during save, so you don't need to reset them manually.
  9.  
  10. Copyright (c) 2015 DarkShadow44
  11.  
  12. Permission is hereby granted, free of charge, to any person obtaining a copy
  13. of this software and associated documentation files (the "Software"), to deal
  14. in the Software without restriction, including without limitation the rights
  15. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. copies of the Software, and to permit persons to whom the Software is
  17. furnished to do so, subject to the following conditions:
  18.  
  19. The above copyright notice and this permission notice shall be included in
  20. all copies or substantial portions of the Software.
  21.  
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. THE SOFTWARE.
  29.  
  30. =end
  31.  
  32.  
  33. #=begin
  34.  
  35. class Game_Event < Game_Character
  36.     attr_reader :event
  37. end
  38.  
  39.  
  40. class Game_CharacterBase
  41.     def setData(eventDataSave)
  42.         moveto(eventDataSave[0], eventDataSave[1])
  43.         set_direction(eventDataSave[2])
  44.  
  45.         @transparent = eventDataSave[3]
  46.         @through = eventDataSave[4]
  47.         @step_anime = eventDataSave[5]
  48.         @walk_anime = eventDataSave[6]
  49.         @move_frequency = eventDataSave[7]
  50.         @move_speed = eventDataSave[8]
  51.        
  52.         if(eventDataSave[9] == true)
  53.             erase
  54.         end
  55.        
  56.         @direction_fix = eventDataSave[10]
  57.     end
  58.    
  59.     def getData()
  60.         eventDataSave = []
  61.         eventDataSave[0] = @x
  62.         eventDataSave[1] = @y
  63.         eventDataSave[2] = @direction
  64.        
  65.         eventDataSave[3] = @transparent
  66.         eventDataSave[4] = @through
  67.         eventDataSave[5] = @step_anime
  68.         eventDataSave[6] = @walk_anime
  69.         eventDataSave[7] = @move_frequency
  70.         eventDataSave[8] = @move_speed
  71.        
  72.         eventDataSave[9] = @erased
  73.        
  74.         eventDataSave[10]= @direction_fix;
  75.        
  76.         return eventDataSave
  77.     end
  78. end
  79.  
  80. class Game_Map
  81.    
  82.     attr_accessor:eventData
  83.     alias initialize_super initialize
  84.     def initialize()
  85.         @eventData = []
  86.         @lastMap = -1
  87.         initialize_super()
  88.     end
  89.    
  90.     def log(data)
  91.         print(data)
  92.     end
  93.    
  94.     def isDoor(event)
  95.         return event.event.name =~ /door/i
  96.     end
  97.    
  98.     def saveMap(map_id, mapEvents)
  99.         log("Trying to save map ")
  100.         log(map_id)
  101.         log("\n")
  102.         if mapEvents == nil
  103.             if(mapEvents == nil)
  104.                 log("save: mapEvents nil\n")
  105.             end
  106.         else
  107.             if eventData[map_id] == nil
  108.                 eventData[map_id] = []
  109.             end
  110.             currentMap = eventData[map_id]
  111.            
  112.             #save additional event data
  113.             mapEvents.each_value do |event|
  114.                 if(not isDoor(event))
  115.                     currentMap[event.id] = event.getData()
  116.                 end
  117.             end
  118.             log("Saved data for map ")
  119.             log(map_id)
  120.             log("\n")
  121.         end
  122.     end
  123.    
  124.     def loadMap(map_id, mapEvents)
  125.         log("Trying to load map ")
  126.         log(map_id)
  127.         log("\n")
  128.         if mapEvents == nil
  129.             if(mapEvents == nil)
  130.                 log("load: mapEvents nil\n")
  131.             end
  132.         else
  133.             if eventData[map_id] == nil
  134.                 eventData[map_id] = []
  135.             end
  136.             currentMap = eventData[map_id]
  137.            
  138.             #load additional event data
  139.             mapEvents.each_value do |event|
  140.                 if(not isDoor(event))
  141.                     eventDataSave = currentMap[event.id]
  142.                     if(eventDataSave != nil)
  143.                         event.setData(eventDataSave)
  144.                     end
  145.                 end
  146.             end
  147.            
  148.             log("Loaded data for map ")
  149.             log(map_id)
  150.             log("\n")
  151.         end
  152.     end
  153.  
  154.     alias setup_super setup
  155.  
  156.     def setup(map_id)
  157.         if(@lastMap != -1)
  158.             saveMap(@lastMap, @events)
  159.         end
  160.         @lastMap = map_id
  161.            
  162.         #setup map
  163.         setup_super(map_id)
  164.            
  165.         loadMap(map_id, @events)
  166.     end
  167.  
  168. end
  169. #=end
Advertisement
Add Comment
Please, Sign In to add comment