Remember Event Position

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV

Remember Event Position





Author: Shaz


Introduction

If you move an event on the map, then leave the map and return, the event, by default, goes back to its original place (where you put it when designing the map). To get around that, you have to have another parallel process event run every time the map loads, to see if the event has been moved, and if so, put it in its correct position. If you have a lot of these in your game, that's a lot of additional events just checking where events should be. I dislike lots of "setup" events sitting around on maps, so devised this little script to let you tell an event to save its position, and go back to that position next time the map is loaded.

How to Use

Paste this script into its own slot in the Materials section.

Script

Code:
#--------------------------------------------------
# Remember Event Position 1.0
#--------------------------------------------------
#
# Author: Shaz
#
# Description: This script lets you set the position and direction
#              where an event will appear next time the map is
#              loaded.  Events will appear in this new position
#              rather than the place they were put during design.
#
#--------------------------------------------------
#
# Installation: 
#
# Copy into a new script slot in the Materials section
#
#--------------------------------------------------
#
# Use:
#
# Examples below show syntax for an Event Command on an Event Tab.
#   You can use @event_id for the current event, or specify an event number.
# To execute from within a Set Move Route command, omit the
#   $game_map.events[@event_id]. part, and just use save_pos() and forget_pos().
#
# To tell an event to move to its current position the next time
# the map is loaded, execute the following in a script call:
#   $game_map.events[@event_id].save_pos()
#
# To tell an event to move to a particular position (not its
# current position) the next time the map is loaded,
# execute the following in a script call:
#   $game_map.events[@event_id].save_pos(1, 2, 8)
# - the above will move the event to x=1, y=2, facing up
#
# To tell an event to forget its previously remembered position
# and go back to its default position the next time time map
# is loaded, execute the following in a script call:
#   $game_map.events[@event_id].forget_pos()
#--------------------------------------------------

class Game_System
  alias shaz_mem_position_gs_init initialize

  attr_accessor :event_positions

  def initialize
    shaz_mem_position_gs_init
    @event_positions = {}
  end
end

# Check to ensure $game_system.event_positions exists (save files created
# prior to this script being added would not have it initialized)
class Game_Map
  alias shaz_mem_positions_gm_init initialize

  def initialize
    shaz_mem_positions_gm_init
    $game_system.event_positions = {} if !$game_system.event_positions
  end
end

class Game_CharacterBase
  attr_accessor
end

class Game_Event
  alias shaz_mem_position_gcb_init initialize

  def initialize(map_id, event)
    shaz_mem_position_gcb_init(map_id, event)

    if $game_system.event_positions.has_key?([map_id, @id])
      mvx, mvy, mvdir = $game_system.event_positions[[map_id, @id]]
      moveto(mvx, mvy)
      set_direction(mvdir) if mvdir
      @stop_count = 0
      refresh
    end
  end

  def save_pos(x = @x, y = @y, dir = @direction)
    $game_system.event_positions[[@map_id, @id]] = [x, y, dir]
  end

  def forget_pos
    $game_system.event_positions.delete([@map_id, @id])
  end
end
How to Call

To save the current event's position after a move route:



Code:
Set Move Route: This event (Wait)
              : $>Move away from Player
              : $>Script: save_pos()
To save the current event's position, but not within a move route:

(Conditional branch only used as part of the example - only the last line is relevant)



Code:
Conditional Branch: Switch [0001: Move Away] == ON
  Set Move Route: This event (Wait)
                : $>Move away from Player
Else
  Set Move Route: This event (Wait)
                : $>Move toward Player
Branch End
Script: $game_map.events[@event_id].save_pos()
To make a different event move to a set position when the map is next loaded:



Code:
Script: $game_map.events[4].save_pos(15, 6)
FAQ

Conditions

May be used freely in any game, commercial or otherwise. Please give credit.

Please do not copy and post to other forums.

Credits

Shaz
 
Last edited by a moderator:

PK8

I sense there's something in the wind...
Veteran
Joined
Mar 17, 2012
Messages
1,220
Reaction score
152
Primarily Uses
Your code appears messed up. o.o
 
Last edited by a moderator:

Todd

Game Developer
Veteran
Joined
Mar 14, 2012
Messages
269
Reaction score
43
First Language
English
Primarily Uses
N/A
This looks nice, I can think of some pretty cool reasons to use this. But ya your code got messed up trying to set the alignment.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV
Thanks guys. I hate the way this forum software messes things up after you preview. I'll see if I can fix it.

... and fixed :)
 
Last edited by a moderator:

Abi

Veteran
Veteran
Joined
Dec 3, 2012
Messages
191
Reaction score
10
First Language
English
Primarily Uses
I can see a lot of use for this... there's just one thing you didn't explain though... maybe you didn't even include a facility to do this sort of thing... But what if I wanted to check if the map had saved positions and prompt the player if they want to reset it, say, a single move puzzle where you have multiple exits and you can only solve the puzzle for one exit at a time. The Star Ocean series had a lot of these sorts of branching puzzles and I loved them.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV
No, I didn't. I don't know that I'd want to prompt the player too may times when a map is loaded - that would get annoying. But if it was only for one puzzle room or something, perhaps ...

You could try something like this (untested, so may not work at all) in a script call from an event:



Code:
found = false
$game_system.event_positions.keys.each { |map, id|
 found = true if map == $game_map.map_id
}
to determine if events on this map have positions remembered (instead of using a temporary variable 'found', you could use a $game_switch, so you can then use it in a conditional branch)



Code:
$game_system.event_positions.keys.each { |map, id|
 $game_system.event_positions.delete([map, id]) if map == $game_map.map_id
}
to forget all positions on this map

The problem is that by the time this runs, the map has already loaded, and the above will not move the events back to their original spot. So you would either need to call this when exiting the map rather than entering, or call it from the map that teleports you here, and instead of using $game_map.map_id, hardcode the id of the map you're about to teleport to.

Again, I haven't tested this so I don't know if it actually works.
 

Abi

Veteran
Veteran
Joined
Dec 3, 2012
Messages
191
Reaction score
10
First Language
English
Primarily Uses
Next weekend if someone else doesn't try it out before then I'll try your suggestion out in a little test demo and let you know if it works. I only have today off this weekend, so getting to it before then is unlikely at best.
 
Joined
Oct 16, 2012
Messages
1
Reaction score
0
First Language
English
Primarily Uses
So, would this allow me to remember the player's position?

The scenario I'm after is to have a "Campsite" map, which the player would be warped to after using an item. The idea is that the player would do whatever on the Campfire map, and then be able to leave and return to wherever it was they used the item in the first place, however I'm currently unable to figure this out. Would this script allow me to make that dream a reality?

Much obliged in advance.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV
No. This is for events which belong to maps.

To use an item to warp the player to a specific place, you'd need to use variables to track the map number, x and y position - the transfer player command will let you send the player to a map and position identified by those variables.
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
I need to use this! Thanks, will let you know how it works out. :D
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
Nice script!  :)   I was just wondering how it compared to a little script I wrote a bit back... I imagine it's probably more useful than the one I wrote... care to explain the differences?
My script: Events on Map 1.02
 
Last edited by a moderator:

Nicke

Fortune seeker
Veteran
Joined
Apr 4, 2012
Messages
549
Reaction score
552
First Language
Swedish
Primarily Uses
RMMV
@ct_bolt: Why must someone explain the difference when you can try it out yourself and see them? :p
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Nice script!  :)   I was just wondering how it compared to a little script I wrote a bit back... I imagine it's probably more useful than the one I wrote... care to explain the differences?


My script: Events on Map 1.02
At first glance, yours would not load the event positions upon game loading.


But if I am wrong...then I am missing something important about RM save files.


Yours also does not provide a convenience method for forgetting stored positions, which of course is not a problem if users can read code.


But other than that it is the same concept.
 
Last edited by a moderator:

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
@ct_bolt: Why must someone explain the difference when you can try it out yourself and see them? :p
Because I asked nicely... lol, I did try it just wasn't sure what all was different. B) It is much nicer then the script I had wrote.

At first glance, yours would not load the event positions upon game loading.

But if I am wrong...then I am missing something important about RM save files.

Yours also does not provide a convenience method for forgetting stored positions, which of course is not a problem if users can read code.

But other than that it is the same concept.
Thank you for such a nice reply!  :D   That is basically what I've noticed too. :thumbsup-left:
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV
Here are a few differences I noticed:


- yours requires a script call to set up the events in the correct locations. Mine does it automatically.


- yours looks at ALL events, and if the map is the current one, it moves the event. Mine looks at ONLY the events for the current map and moves them (yours would take longer to run as it's looking at events that will not be processed).


- as already mentioned, yours does not provide a way to 'forget' the location.


- again, as already mentioned, yours does not stick when the player saves and closes the game.


- yours saves only the coordinates of the event - mine also saves the facing direction.


My script is not necessarily better than yours, if you only have a need to do the things in your script. Note, when I started mine, I JUST stored the event location too. Storing the direction and forgetting the position were additions that came as I used it more and decided it needed those things as well.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
Here are a few differences I noticed:

- yours requires a script call to set up the events in the correct locations. Mine does it automatically.

- yours looks at ALL events, and if the map is the current one, it moves the event. Mine looks at ONLY the events for the current map and moves them (yours would take longer to run as it's looking at events that will not be processed).

- as already mentioned, yours does not provide a way to 'forget' the location.

- again, as already mentioned, yours does not stick when the player saves and closes the game.

- yours saves only the coordinates of the event - mine also saves the facing direction.

My script is not necessarily better than yours, if you only have a need to do the things in your script. Note, when I started mine, I JUST stored the event location too. Storing the direction and forgetting the position were additions that came as I used it more and decided it needed those things as well.
Wow! Thank you so much for that info. :D I will most likely be using yours instead for now at least.

I may try and implement a few more things in mine and change it a bit to at least save the positions when the player closes the game though. B)
 

light487

Parrot Keeper
Veteran
Joined
Mar 26, 2013
Messages
852
Reaction score
26
First Language
English
Primarily Uses
Just saw this linked from another thread and found the script might be useful. I wonder if there is a way to make this work with "Random" event movement or is it only possible when being used as part of a move_route command?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,086
Reaction score
13,698
First Language
English
Primarily Uses
RMMV
Under Autonomous Movement, choose Custom. Then enter two movement commands - one will be Move at Random, the next will be save_pos
 

light487

Parrot Keeper
Veteran
Joined
Mar 26, 2013
Messages
852
Reaction score
26
First Language
English
Primarily Uses
Under Autonomous Movement, choose Custom. Then enter two movement commands - one will be Move at Random, the next will be save_pos
Oh right.. I didn't realise there was a random move command in there.. there's so many commands in that dialog, I guess I missed it. :)
 

chigoo

Void Walker
Veteran
Joined
Aug 15, 2012
Messages
136
Reaction score
18
First Language
English
Primarily Uses
RMMV
Is there a way to make the script call use zero if you want the script to tell the event it's in to remember position.

I have over 100 events I want to remember their position, and more to be added on 1 map. so I want an easier way to do it so I can copy and paste, most of the events are identical. 
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

It's Saturday already. Last Saturday felt just like yesterday. o_o
I really need to stop adding more levels to this thing already...
My computer is now on the dead list. Parts and Services stopped two days ago for this type.
someone help my thread has been silent since the initial post I just wanna make a goddamn game
People3_6 and People3_7 added!

Forum statistics

Threads
105,838
Messages
1,016,872
Members
137,540
Latest member
Kurow
Top