Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Memorize Event Positions, Events will always be where you left them
BigEd781
post Dec 6 2008, 04:18 PM
Post #1


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Memorize Event Positions

By Biged781


Intro
For those who do not like that the positions of their events reset when the player exits and enters a map, this script will automatically memorize their positions for you. Just drop it into the materials section and your events will always appear where they left off. You can enable and disable this behavior by turning a switch ON or OFF.

Bug Fixes / Enhancements
-> Added a way to disable the effects of this script for certain events.
-> Fixed a bug that would have occurred with encrypted game files.
-> Ended reliance on the file system, greatly reduces chances of bugs (thanks wora wink.gif)

Configuration / Use
Just plop it into the "Materials" sections, should be no problems. To turn the script on and off, find this part of the script:

CODE
#-----------------------------------------------------------------------
  # * Set this to the switch number that you will
  #   use to turn this script ON or OFF.
  #   ---------  
  #   Set to switch id "1" by default.
  #
  MOVE_EVENTS_SWITCH_ID = 1


You can modify this constant,

CODE
MOVE_EVENTS_SWITCH_ID


to equal the id of the switch that you would like to use. If this switch is ON, the events on each map will memorize their positions at all times. If you turn this switch OFF, they will return to their default positions. Note that only the maps that are loaded after the switch is turned ON or OFF will be affected, i.e., the current map positions will be saved, but the events will not be moved.

--------------------------------
To disable the effects of this script at the event level, add a comment to the event with only the text "no mem", without the quotes.




Script
CODE
#-----------------------------------------------------------------------
#                       Memorize Event Positions
#                               BigEd781
#-----------------------------------------------------------------------
class Game_System
  
  alias :eds_old_pre_mem_intialize :initialize
  def initialize
    eds_old_pre_mem_intialize
    @event_pos_data = {}    
  end
  
  def save_event_position_data(map_id, data)
    @event_pos_data[map_id] = data
  end
  
  def get_event_position_data(map_id)
    return @event_pos_data[map_id].nil? ? [] : @event_pos_data[map_id]
  end
  
end

class Game_Event < Game_Character

  def comment?(comment)
    unless @list.nil?
      @list.each { |line|
        next if line.code != 108                              
        return true if line.parameters[0].upcase == comment.upcase }      
    end    
    return false
  end  
  
end

class Game_Map
  
  alias :eds_old_pre_mem_setup :setup
  def setup(map_id)    
    save_positions if $game_switches[1]
    eds_old_pre_mem_setup(map_id)    
    restore_positions  if $game_switches[1]
  end
  
  def save_positions
    return if @events.nil? || @events == { }        
    data = []
    @events.values.each { |event| data += [[ event.id, event.x, event.y, event.direction ]] }      
    $game_system.save_event_position_data(@map_id, data)    
  end
  
  def restore_positions    
    return if @events.nil? || @events == { }        
    $game_system.get_event_position_data(@map_id).each { |data|  
    event = @events[data[0]]  
      unless event.nil? || event.comment?('no mem')
        x, y, direction = data[1], data[2], data[3]
        event.moveto(x, y) unless event.pos?(x, y)
        event.set_direction(direction)
      end
    }    
  end
  
end


Compatibilty / Issues
I don't not know of any issues currently, but this system writes out the event's locations to a file when maps are left, and reads that file back in to position the events when a map is loaded. Also, there are many edge conditions to yet be found so there will probably be some bugs. I will fix them as soon as they are posted. Compatibility with other scripts should be 100%.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
woratana
post Dec 6 2008, 05:52 PM
Post #2


Looking for scripter to hire? PM me *O*
Group Icon

Group: +Gold Member
Posts: 1,038
Type: Scripter
RM Skill: Undisclosed




Nice~^^ I wrote this in XP half a year ago, and it's my first script! >_>/ Btw, does this script memorize @direction (It seems like it doesn't) ? And have you tested it on encrypted project? The other issues I see are that the process of getting/saving data could make a short pause for big maps, and data in text file can be edited to cheat game easily.


__________________________
Check out my NEW blog!!!



MVP (Most Valuable Poster) Award 2008


Go to the top of the page
 
+Quote Post
   



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 12:32 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker