Remember Event Position

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Shaz, May 8, 2012.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    35,256
    Likes Received:
    9,807
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    $game_map.events[@event_id].save_pos


    @event_id is the 'current' event.


    But if you're doing this as a move route, you can just add save_pos as a script call (in the move route).
     
    #21
  2. chigoo

    chigoo Void Walker Veteran

    Messages:
    123
    Likes Received:
    9
    Location:
    Union, NJ
    First Language:
    English
    Primarily Uses:
    N/A
    oh so I use this as $game_map.events[@event_id].save_pos. and i knew about the move route thing. This will really come in handy for my game. I can just spawn events once in a random location and keep them there for good.
     
    Last edited by a moderator: Jan 8, 2014
    #22
  3. Shaz

    Shaz Veteran Veteran

    Messages:
    35,256
    Likes Received:
    9,807
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    As long as the next time you return to the map, the same events get spawned with the same event id.


    If you have any kind of conditions that will cause events to get spawned in a different order, that won't work.
     
    #23
  4. chigoo

    chigoo Void Walker Veteran

    Messages:
    123
    Likes Received:
    9
    Location:
    Union, NJ
    First Language:
    English
    Primarily Uses:
    N/A
    nope they will always have the same event ID. I haven't even seen a script or know a way to change event IDs
     
    #24
  5. Darc_The_Hero

    Darc_The_Hero Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    Problem solved.

    king.png
     
    Last edited by a moderator: Mar 3, 2014
    #25
  6. Andar

    Andar Veteran Veteran

    Messages:
    24,706
    Likes Received:
    5,199
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    Your event saves the position of the king-event, not the positions of the guard-events.
    You should have done it the way I told you in the other post, not looking here for the solution of other players, because the save_pos() command can be used in several ways.


    See attached picture for the correct solution in your case

    save_pos.png
     
    #26
  7. Darc_The_Hero

    Darc_The_Hero Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    I must have missed that, thank you.

    Fixed.
     
    #27
  8. rivalhyuu

    rivalhyuu Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    English
    Hi, it's my first time to use the scripts, so I don't have an idea how to copy and paste your script to the script and where to paste it.. How do you do it in a way that the game will still work?
     
    #28
  9. Shaz

    Shaz Veteran Veteran

    Messages:
    35,256
    Likes Received:
    9,807
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Hi rivalhyuu, welcome to the forum.


    Scripting is an advanced topic, so if you're new to the engine, I suggest you don't spend too much time looking at scripts - at least not until you've familiarized yourself with the event editor.


    To add a script, you open the Script editor (F11 or click the script icon on the toolbar - I can't tell you what it looks like as I don't have it in front of me).


    In the list on the left, scroll down until you see Materials and Main.


    Click on the row BELOW Materials (if you haven't added any other scripts, it'll say something like Insert Here).


    Press the Insert button to insert a new slot.


    In the script name box at the bottom of the list, type in a name for the script - this doesn't have to be what the scripter called it - it's just for your own reference (make sure you do this, as it will help with debugging issues or locating scripts later).


    Then in the empty panel on the right, paste the script itself.


    ALWAYS check the comments (green text at top of scripts) to see if it requires you to do any customizing or reserve any switches or variables. If it does require that and you don't do it, your game will not behave the way you expect it to, and it can be difficult to figure out why.
     
    #29
  10. rivalhyuu

    rivalhyuu Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    English
    Thanks! Btw the script you have there's very useful.
     
    Last edited by a moderator: Mar 3, 2014
    #30
  11. Imagine

    Imagine Warper Member

    Messages:
    4
    Likes Received:
    1
    First Language:
    English
    Great script, well done mate! :)
     
    #31
  12. Candacis

    Candacis Pixel Pusher Restaff

    Messages:
    1,461
    Likes Received:
    1,907
    Location:
    Vienna
    First Language:
    German
    I could have needed this script in my face contest entry. Well, glad I found it now. This is an amazing script! Thank you very much for sharing.
     
    #32
    Shaz likes this.
  13. Dreadshadow

    Dreadshadow Lv 38 Tech Magician Moderator

    Messages:
    3,002
    Likes Received:
    1,853
    First Language:
    Greek
    Primarily Uses:
    RMMV
    This script is a fantastic idea.

    It can actually make our life simple.

    It is really hard to do this with eventing, it might work wrong and also it might create extra lag if needed for many events.

    Thanks Shaz!

    A thanks goes also to Celianna for recommending that to someone. It's how I learned about it.
     
    #33
  14. JAD94

    JAD94 The Noblest of Knights Veteran

    Messages:
    584
    Likes Received:
    144
    Location:
    New York
    First Language:
    English
    Primarily Uses:
    N/A
    Ah Shaz you're the best. Been looking for a script like this for a while!
     
    #34
  15. Nataxinus

    Nataxinus Villager Member

    Messages:
    11
    Likes Received:
    0
    First Language:
    Danish
    I've made some modifications to this script. Now you can use it by default and control exceptions with single events or entire graphic sheets. Saves some time.

    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()#--------------------------------------------------# I, Nataxinus has made modifications to this script# I do not own it etc. etc.#--------------------------------------------------# This requires some knowledge of ruby.# You can now choose to remember event# positions by default. You can specify exceptions# if you're using this new feature. You can also# specify exceptions for whole graphic sheets.# I have specified graphic sheets from the RTP# so you might want to change that if you're# not using RTP.# Configure my module to use the new# features of the script. # Follow the instructions listed there.#--------------------------------------------------module Nataxinus  module RememberEventPos    # Set to true if you want to save the event positions by default, set to    # false otherwise.    USE_DEFAULT = true    # The exceptions to the default. Use map id's as keys and insert the event    # id's that belong to that map. For example to make event 1 and 2 at map 1     # exceptions, and event 9 at map 2:     # 1 => [1, 2], 2 => [9]    EXCEPTIONS = {}    # You can add the graphic file names that you don't want to automatically    # save the position of.    EXCEPTION_GRAPHICS = ["!Door1", "!Door2", "!Door3", "!$Gate1", "!$Gate2",     "!Other3", "!Switch1", "!Switch2", "", "$Text", "$Text2"]  endendclass Game_System  alias shaz_mem_position_gs_init initialize  attr_accessor :event_positions  def initialize    shaz_mem_position_gs_init    @event_positions = {}  endend# 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  endendclass Game_CharacterBase  attr_accessorendclass Game_Event    include Nataxinus::RememberEventPos    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    alias save_event_pos_update update  def update    save_event_pos_update    if @page      return if EXCEPTION_GRAPHICS.include?(@page.graphic.character_name)    else      return    end    if EXCEPTIONS[$game_map.map_id]       if USE_DEFAULT && !EXCEPTIONS[$game_map.map_id].include?(@id)        save_pos       end    elsif USE_DEFAULT      save_pos    end  endend 
     
    Last edited by a moderator: May 18, 2015
    #35
  16. Kes

    Kes Global Moderators Global Mod

    Messages:
    16,817
    Likes Received:
    8,721
    First Language:
    English
    Primarily Uses:
    RMVXA
    I am trying to tell an event to move to a particular position (not its current position) the next time the map is loaded.  I am having to do this via an event on another map.  I have used this script call:

    $game_map.events[290, 4] .save_pos(14, 3, 8)

    290 is the map_id, 4 is the event_id.  For the position to move to, I have had to guess 8, as this is an object, not a sprite, so does not actually have an up/down/left/right orientation.

    I get the error message:

    wrong number of arguments (2 for 1).

    Could you tell me what's wrong with my script call?

    thanks.
     
    Last edited by a moderator: Jun 20, 2015
    #36
  17. ♥SOURCE♥

    ♥SOURCE♥ Too sexy for your party. Member

    Messages:
    693
    Likes Received:
    405
    Hey there! Try the following instead:

    Code:
    $game_system.event_positions[[290, 4]] = [14, 3, 8]
     
    #37
    Kes and Shaz like this.
  18. Shaz

    Shaz Veteran Veteran

    Messages:
    35,256
    Likes Received:
    9,807
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    ALL events have a direction. If you mean this event uses a spritesheet where you check Direction Fix to stop it turning because all the sprites are different, then your direction will be as follows:


    Rows 1 or 5: 2


    Rows 2 or 6: 4


    Rows 3 or 7: 6


    Rows 4 or 8: 8


    And yes, you can only use $game_map.events to refer to events on the current map. This is why you got an error. SOURCE's answer is spot-on.
     
    #38
    Kes likes this.
  19. Kes

    Kes Global Moderators Global Mod

    Messages:
    16,817
    Likes Received:
    8,721
    First Language:
    English
    Primarily Uses:
    RMVXA
    Thanks for the clarification of $game_map.events

    This isn't on an 8 row sprite sheet, but a B-E tilesheet and it's on row 15.  So I'm still unclear what I should do about direction.
     
    #39
  20. ♥SOURCE♥

    ♥SOURCE♥ Too sexy for your party. Member

    Messages:
    693
    Likes Received:
    405
    Don't worry, it won't do anything with the direction if the graphic is from the tilesheet. :)
     
    #40

Share This Page