EmilyAnnCoons 7 Report post Posted January 14, 2007 Ok...I know nothing about this script...I just use it :lol: anyway...I'll let dubealex explain everything himself. This is the first script I do alone, it's not an edit, I coded it entirely. So here's what it do: Basic Features: - Store the location of the player - Store the location of any events on the map - Store as many locations in memory as you want - Recall an event to a location (new in release 2) - A warp feature to teleport at specific location with script (new in release 2) What data does it stores ? -> Map ID -> Map Name -> X and Y coordinates on the map -> Screen X and Screen Y viewed on screen -> Facing Direction -> Terrain ID of the tile where the location is -> A keyname to name each location and refer to them -> A full name for use in your story line if you want it (optional). Extra features in the demo: - An "Exit Warp" item that allows you to exit from a maze, warping you at the entrance you took to enter the maze. - An item "Location Warp" used to memorize any location the player wants... It memorize the location where the player is when using the item; and when used again, the player is warped back at that location. (Aka like diablo.) - A Rock that you can pull, and if you exit the map and come back, it will stays where you left it. (New in release 2) Be sure to read the instructions on this post entirely. The scripts you need: PART 1/2: Adding the save/load lines in order to save the location you did when saving a game. Search for this line using the Search tool in the script editor in the class "Scene_Save": Marshal.dump($game_system, file) This is the first line of a group of Marshal.dump lines; those that actually saves data in the save file. Under the last one, paste that new line for my script: Marshal.dump($MemLocation, file) Then, go in the class "Scene_Load" and do the same trick, but search for the line: $game_system = Marshal.load(file) This is once again the first line of a group of Marshal.load, that load data from the save files. So, once again, right under the last Marshal.load line, paste that one: $MemLocation = Marshal.load(file) PART 2/2: Adding the new Memorize Location code in the script editor. All you need to do is add a new class before main named Memorize_Location. (Use "insert" or right click then "insert" to add a class.) And paste that code in it: #=================================================== # ■ Memorize Location Script R2 - created by dubealex #=================================================== # For more infos and update, visit: # asylum.dubealex.com # # -> Real/Screen coordinates fixed. # -> Screen X/Y added. # # November 26, 2004 #=================================================== #=================================================== # ▼ CLASS Store_Location Begins #=================================================== class Store_Location attr_accessor :x attr_accessor :y attr_accessor :rx attr_accessor :ry attr_accessor :sx attr_accessor :sy attr_accessor :facing attr_accessor :mapID attr_accessor :mapName attr_accessor :name attr_accessor :keyname attr_accessor :terrain def initialize(x, y, rx, ry, sx, sy, facing, mapID, mapName, name, keyname, terrain) @x= x @y= y @rx= rx @ry= ry @sx=sx @sy=sy @facing= facing @mapID= mapID @mapName= mapName @name= name @keyname= keyname @terrain= terrain end end #=================================================== # ▲ CLASS Store_Location Ends #=================================================== #=================================================== # ▼ CLASS MemLocation Begins #=================================================== class MemLocation def initialize(keyname, name, event) @name= name @keyname= keyname @event = event if event <= 0 x= $game_player.x y= $game_player.y rx= $game_player.real_x ry= $game_player.real_y sx= $game_player.screen_x sy=$game_player.screen_y facing= $game_player.direction mapID= $game_map.map_id mapName= $game_map.name terrain= $game_map.terrain_tag(x, y) $MemLocation[@keyname] = Store_Location.new(x, y, rx, ry,sx,sy, facing, mapID, mapName, name, keyname, terrain) self elsif event >= 0 x= $game_map.events[event].x y= $game_map.events[event].y rx= $game_map.events[event].real_x ry= $game_map.events[event].real_y sx= $game_map.events[event].screen_x sy=$game_map.events[event].screen_y facing= $game_map.events[event].direction mapID= $game_map.map_id mapName= $game_map.name terrain= $game_map.terrain_tag(x, y) $MemLocation[@keyname] = Store_Location.new(x, y, rx, ry,sx,sy, facing, mapID, mapName, name, keyname, terrain) self end end def [](name) $MemLocation[keyname] end end #=================================================== # ▲ CLASS MemLocation Ends #=================================================== #=================================================== # ▼ CLASS RecallLocation Begins #=================================================== class RecallLocation def initialize(keyname, facing) if $MemLocation.has_key?(keyname) $game_map.setup($MemLocation[keyname].mapID) $game_player.moveto($MemLocation[keyname].x, $MemLocation[keyname].y) case facing when -1 case $MemLocation[keyname].facing when 2 $game_player.turn_down when 4 $game_player.turn_left when 6 $game_player.turn_right when 8 $game_player.turn_up end when 2 $game_player.turn_down when 4 $game_player.turn_left when 6 $game_player.turn_right when 8 $game_player.turn_up end Graphics.freeze $game_temp.transition_processing = true $game_map.autoplay $scene = Scene_Map.new $game_temp.transition_processing = false Graphics.frame_reset else print "This location does not exist yet in memory." print "Use 'Conditional Branches' in your event to bypass this error." print "Read the full instruction manual on RMXP.DUBEALEX.COM" end end end #=================================================== # ▲ CLASS RecallLocation Ends #=================================================== #=================================================== # ▼ CLASS Warp Begins #=================================================== class Warp def initialize(mapID, x, y, facing) $game_map.setup(mapID) $game_player.moveto(x, y) case facing when 2 $game_player.turn_down when 4 $game_player.turn_left when 6 $game_player.turn_right when 8 $game_player.turn_up end Graphics.freeze $game_temp.transition_processing = true $game_map.autoplay $scene = Scene_Map.new $game_temp.transition_processing = false Graphics.frame_reset end end #=================================================== # ▲ CLASS Warp Ends #=================================================== #=================================================== # ▼ CLASS RecallEvent Begins #=================================================== class RecallEvent def initialize(keyname, event) if $MemLocation.has_key?(keyname) $game_map.events[event].moveto($MemLocation[keyname].x, $MemLocation[keyname].y) else print "This location does not exist yet in memory." print "Use 'Conditional Branches' in your event to bypass this error." print "Read the full instruction manual on RMXP.DUBEALEX.COM" end end end #=================================================== # ▲ CLASS RecallEvent Ends #=================================================== #=================================================== # ▼ CLASS Game_Map Additional Code Begins #=================================================== class Game_Map #Dubealex Addition (from XRXS) to show Map Name on screen def name $map_infos[@map_id] end end #=================================================== # ▲ CLASS Game_Map Additional Code Ends #=================================================== #=================================================== # ▼ CLASS Scene_Title Additional Code Begins #=================================================== class Scene_Title $MemLocation = Hash.new #Dubealex Addition (from XRXS) to show Map Name on screen $map_infos = load_data("Data/MapInfos.rxdata") for key in $map_infos.keys $map_infos[key] = $map_infos[key].name end end #=================================================== # ▲ CLASS Scene_Title Additional Code Ends #=================================================== Instruction Manual below: Memorize a new or overwrite a Location: MemLocation.new("keyname", "story name", event_id) keyname is the actual name for the location you want to create. This keyname will be used to recall that location back (meaning going back there), you can use words between " " or simple numbers, as you wish. story name is used to define a long name for that location. This name is optional (but MUST be entered in the syntax anyway. If you dont intend on using it, write 0). You can use this naming tag to name chapters or location if you need to show a fancy name in messages or menu in your game. event_id is used to specify for wich event ID you want to store a location. (this must be a number). If 0 is used, the player position is stored. If an higher number than 0 is entered, this will store the location of this event ID instead. Recall back a Location: RecallLocation.new("keyname", facing) keyname is used to refer to an existing location you created with that name. So, if you previously created a location named "Heaven" and you want to go back to this location, you write "Heaven" in place of "keyname". facing is the facing direction you want to have once warped. The numbers are default, meaning that: 2 = down 4 = left 6 = right 8 = up and I added to new things: 0 = No direction changes -1 = You will regain the facing direction you had when you created that location. Recall an event to a location: Be aware that you cannot "move" an event to another map, and that if you try to move an event to a coordinates that doesn't exist on the map, it will cause a bug. You will have to be careful with that new feature. (I.E: If your map is 40 X 40, and you stored a location that is 102 X 140, you won't be able to use it... ) To recall an event to a location (on the same map), use that syntax: RecallEvent.new("rock", Event ID) rock is the keyname of the memorized location, as explained earlier. Event ID is the Event ID you want to move to that location. Make sure that this event ID actually exist on the map you use the call script. Important note: About the rock in the demo, the way to do it may also works in your projects if you have vehicles or such interactive events you can move around. The way it works, is that you need an event set to Parralel Process on your map, and set a switch as the pre-condition. When the player first use the event (the rock, or the vehicle, or anything) you memorize the location of the event, then you activate the switch. The parallel process event must have a conditional branch that check for the condition "$game_temp.transition_processing == true " because that is our way to check if the player was "teleported" on the map or not. Why ? Because that parallel process event actually recall an event to a location, and the event you try to recall actually memorize its own location upon uses; so it can do some little bug; that is why we set a WAIT event in our parralel process event before we recall the event; but ONLY if the player haven't been teleported on the map; otherwise the event "warp" would not be instateneous. Look at the event, you will understand. If you need assistance, use that post; it's there for that ! The warp feature (script teleport): You can easily do a normal teleport with an event, but I add a way to teleport with the same options as the events commands, in script. Use that syntax to teleport: Warp.new(map id, x, y, facing) map id You write the map ID you want to teleport to there. x You write the X coordinates on that map where you want to be teleported too there. y You write the Y coordinates on that map where you want to be teleported too there. facing You write the facing direction you want to have once teleported here. 2 = down 4 = left 6 = right 8 = up Using the MemLocation variable: You can access and modify (read/write) to any value from any memorized location with the following syntax: $MemLocation["keyname"].parameter keyname is the keyname of your location. No need to explain that again. parameter is the parameter you want to read or write to, as the map ID, the name, etc. Here's a full list of those parameters: X AXIS: $MemLocation["keyname"].x Y AXIS: $MemLocation["keyname"].y SCREEN X: $MemLocation["keyname"].rx SCREEN Y: $MemLocation["keyname"].ry MAP ID: $MemLocation["keyname"].mapID MAP NAME: $MemLocation["keyname"].mapName KEYNAME: $MemLocation["keyname"].keyname NAME: $MemLocation["keyname"].name TILE TERRAIN ID: $MemLocation["keyname"].terrain FACING DIRECTION: $MemLocation["keyname"].facing So you can read from those values, if you want to show them in a message, put the one you want in a game variable, like this: $game_variables[1]=$MemLocation["keyname"].mapName Will enable you to use \v[1] to say the map name of this location. You can also modify values, like those example: $MemLocation["keyname"].x += 4 -> will add 4 to the X value $MemLocation["keyname"].facing = 4 -> will make the facing direction equal 4 $MemLocation["keyname"].name = "my new name" -> will change the name of this location (not the keyname!) Warning: You can't change the real "keyname" of a location, as you would have to re-do the location. The keyname is set when you use "MemLocation.new" and it cannot be changed unless you do a new one. IMPORTANT NOTES ABOUT SECURITY: If you try to read/write from or to a $MemLocation that does not exist yet, like doing: $MemLocation["joy"].x = 4 When you never created a location with the keyname joy before, it will crash; but I implemented a security check in RecallLocation for it, and you have to use conditional branch (as seen in the demo) in your event that use the Recall and MemLocation syntax. You can simply do one conditional branch, and choose page 4, at the bottom you have the options "SCRIPT", you can then write this line: $MemLocation.has_key?("keyname") This will actually verify for you if the keyname you choosed between parenthesis exist in $MemLocation. If it does exist, action in the condition are done, and you can use the Else to do any other actions when the location isn't visited yet; like saying a message. In my RecallLocation class, I implemented this same kind of verification, and I give you an error message if you try to recall a location that don't exist so you will know that you have to put a conditional branch in the relevant events. I added this messages to help you develop your game, instead of crashing, it's better if you know what happened :thumb This script can be used in a lot of ways, use your imagination. Anyway, have fun with it ! Share this post Link to post Share on other sites
RMXPirate 0 Report post Posted April 28, 2007 late reply but, yes i need something like this!!! It will be great for pokemon games like for saving the location before entering a cave so you can use escape rope... Share this post Link to post Share on other sites
EmilyAnnCoons 7 Report post Posted April 29, 2007 agreed. I hope you enjoy it. It's an awesome script, though I haven't had a use for it, yet. Share this post Link to post Share on other sites