Question about storing X,Y of an event

Discussion in 'RPG Maker MV' started by woop, May 20, 2019.

Thread Status:
Not open for further replies.
  1. woop

    woop Freelance Illustrator Member

    Messages:
    20
    Likes Received:
    36
    First Language:
    English
    Primarily Uses:
    RMMV
    Is it possible to store an event’s x, y into variables from a specific map, without the player having to be in said map? Or maybe reference the event’s x,y directly from a specific map using a script call?
     
    #1
  2. V_Aero

    V_Aero Veteran Veteran

    Messages:
    46
    Likes Received:
    28
    Location:
    Germany
    First Language:
    german
    Primarily Uses:
    RMMV
    It is. I dont know the command by heart, but all you need to do is do read that map.json data and look into the events.
     
    #2
  3. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,235
    Likes Received:
    492
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Use the "script" option in the Control Variable event command and store this:
    Code:
    $gameMap.event(event_id).x
    or
    Code:
    $gameMap.event(event_id).y
    If you want you can even use a single script call and write this:
    Code:
    $gameVariables.setValue(varId, $gameMap.event(event_id).x);
    or you could store both values in a single variable as an array. If you want to know more about this you can take a look at this thread containing MV script calls. There is also an example where an array is stored in a variable (it is more or less the same as storing a single value).
     
    #3
  4. Andar

    Andar Veteran Veteran

    Messages:
    28,426
    Likes Received:
    6,485
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    @Heirukichi that only works for the events on the current map ($gameMap), the OP asked specifically about accessing data from events on other maps.

    @woop
    it is possible, but not by simple script call. Only the current map exists in memory and there is no other space in RAM by default, so you'll need a plugin that temporarily loads that other map into a new map structure, then checks the data of the event and copies it and then releases the memory of the other map again.
    You might look into existing "clone event" plugins as they would have to do the same to get the event data to be cloned from another map.

    EDIT:
    And just as an addendum: since the player is not on that map, the events on the other maps are not processed and cannot move in that time (if your question was made while believing the other maps would work)
     
    #4
    Heirukichi and caethyril like this.
  5. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    1,235
    Likes Received:
    492
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    You're right, I completely missed that part. I guess the only way to do it is to have either the event or the map stored in memory from somewhere else then.

    EDIT
    However, there is one thing I do not understand about this request...the position of each event is set back to its original position when the map is loaded again. What is the point of storing its X and Y in a variable? Why not using their numeric value taken from the editor then? If the event has been moved and the OP is using a plug-in to store events position, it means the map has been loaded already and you can just store the new event position when the event moves, there is no need for something as heavy as loading a whole map into memory for that.
     
    Last edited: May 20, 2019
    #5
  6. mathmaster74

    mathmaster74 just...John Veteran

    Messages:
    285
    Likes Received:
    188
    Location:
    Sheboygan, WI USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @woop Well...concerning setting variables equal to the X and Y coordinates of an event from a different map, you could technically do that at the start of the game since you placed every event at a particular X and Y coordinate in the editor and that's its home when not on its map. Then you just reference those coordinate variables when you want to. Bonus: If you want to call an event from another map, Yanfly has a plugin for that: Call Event. Hope it helps. :smile:
     
    #6
  7. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,600
    Likes Received:
    1,005
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    That's a really important distinction. If OP is using some plugin to store the event position, then that's a different question entirely than reading from the map json file.

    Anyways to the read the x and y for an event on a different map:
    Code:
    const getRemoteEventXY = async (mapId, eventId, coords) => {
        const rawStream = await fetch(`/data/Map${mapId.toString().padStart(3, '0')}.json`)
        const json = await rawStream.json()
        coords.x = json.events[eventId].x
        coords.y = json.events[eventId].y
    }
    const coords = {}
    getRemoteEventXY(10, 5, coords)   // populate coords variable with x,y of event 5 on map 10
    console.log(coords)
    
    Note this requires MV 1.6+ because doing that in pre-2015 Javascript is tedious. If you're going to do this a bunch, then paste that function to a .js file and then you can just call the function in an event or something.
     
    #7
  8. woop

    woop Freelance Illustrator Member

    Messages:
    20
    Likes Received:
    36
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you for the information, that helps a lot! I didn't realize these clone event plugins existed, I've been using Galv's Event Spawner to call in events from a specific map but there's no support for referencing their x,y, but I think Orange's Custom Event Creator might be able to solve my issue.

    I've been making it so that the player can spawn in an event from a specific map to any other map, and have that event interact with other map events.

    With the help of all of you guys, I think I've gotten everything to work now, thank you!
     
    Last edited: May 20, 2019
    #8
  9. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,544
    Likes Received:
    4,121
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #9
Thread Status:
Not open for further replies.

Share This Page