Remember Event States By Darkshadow44 (Complete and Tested/Working)

naruzeldamaster

Veteran
Veteran
Joined
Jun 9, 2014
Messages
70
Reaction score
3
First Language
English
Primarily Uses
=beginName: Remember Event PositionAuthor: DarkShadow44Description: Saves additional information for events that RPGMaker normally doesn't saveInstructions: Just Copy the script into your script editor, under "Materials".For convenience the door events are skipped during save, so you don't need to reset them manually.Copyright (c) 2015 DarkShadow44Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.=end#=beginclass Game_Event < Game_Character        attr_reader :eventendclass Game_CharacterBase        def setData(eventDataSave)                moveto(eventDataSave[0], eventDataSave[1])                set_direction(eventDataSave[2])                @transparent = eventDataSave[3]                @through = eventDataSave[4]                @step_anime = eventDataSave[5]                @walk_anime = eventDataSave[6]                @move_frequency = eventDataSave[7]                @move_speed = eventDataSave[8]                               if(eventDataSave[9] == true)                        erase                end                               @direction_fix = eventDataSave[10]        end               def getData()                eventDataSave = []                eventDataSave[0] = @x                eventDataSave[1] = @y                eventDataSave[2] = @direction                               eventDataSave[3] = @transparent                eventDataSave[4] = @through                eventDataSave[5] = @step_anime                eventDataSave[6] = @walk_anime                eventDataSave[7] = @move_frequency                eventDataSave[8] = @move_speed                               eventDataSave[9] = @erased                               eventDataSave[10]= @direction_fix;                               return eventDataSave        endendclass Game_Map               attr_accessor:eventData        alias initialize_super initialize        def initialize()                @eventData = []                @lastMap = -1                initialize_super()        end               def log(data)                print(data)        end               def isDoor(event)                return event.event.name =~ /door/i        end               def saveMap(map_id, mapEvents)                log("Trying to save map ")                log(map_id)                log("\n")                if mapEvents == nil                        if(mapEvents == nil)                                log("save: mapEvents nil\n")                        end                else                        if eventData[map_id] == nil                                eventData[map_id] = []                        end                        currentMap = eventData[map_id]                                               #save additional event data                        mapEvents.each_value do |event|                                if(not isDoor(event))                                        currentMap[event.id] = event.getData()                                end                        end                        log("Saved data for map ")                        log(map_id)                        log("\n")                end        end               def loadMap(map_id, mapEvents)                log("Trying to load map ")                log(map_id)                log("\n")                if mapEvents == nil                        if(mapEvents == nil)                                log("load: mapEvents nil\n")                        end                else                        if eventData[map_id] == nil                                eventData[map_id] = []                        end                        currentMap = eventData[map_id]                                               #load additional event data                        mapEvents.each_value do |event|                                if(not isDoor(event))                                        eventDataSave = currentMap[event.id]                                        if(eventDataSave != nil)                                                event.setData(eventDataSave)                                        end                                end                        end                                               log("Loaded data for map ")                        log(map_id)                        log("\n")                end        end        alias setup_super setup        def setup(map_id)                if(@lastMap != -1)                        saveMap(@lastMap, @events)                end                @lastMap = map_id                                       #setup map                setup_super(map_id)                                       loadMap(map_id, @events)        endend#=endThe script is now fixed and should work for doors, there have been no other issues reported.
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,924
Reaction score
14,556
First Language
English
Primarily Uses
RMMV
Wouldn't you expect doors to always be in the same place?


I get what you mean ... you want the door to be closed when you return to the map.


You can either change the door events to close after you go through them but before you transfer to the new map, not save the direction of an event as part of your data, or add a comment to the event and cater for that comment in the script, to not save the direction for certain events. Maybe use the name of the event - give all doors the name DOOR, and in your script don't save the direction if the event's name is DOOR.


There's really not any way to change the script without changing all the events you want to behave a little differently, as the script won't know which ones need to have different behaviour. Maybe you could check the event's character_name to see if it contains the word Door - that would get you out of having to modify all those events, but it's still prone to error.
 

naruzeldamaster

Veteran
Veteran
Joined
Jun 9, 2014
Messages
70
Reaction score
3
First Language
English
Primarily Uses
Wouldn't you expect doors to always be in the same place?

I get what you mean ... you want the door to be closed when you return to the map.

You can either change the door events to close after you go through them but before you transfer to the new map, not save the direction of an event as part of your data, or add a comment to the event and cater for that comment in the script, to not save the direction for certain events. Maybe use the name of the event - give all doors the name DOOR, and in your script don't save the direction if the event's name is DOOR.

There's really not any way to change the script without changing all the events you want to behave a little differently, as the script won't know which ones need to have different behaviour. Maybe you could check the event's character_name to see if it contains the word Door - that would get you out of having to modify all those events, but it's still prone to error.
Fabian gets different errors with his same script (He made it) but I don't get these errors, I have yet to try the door thing, but I checked something else he reported (Changing a map anywhere in the game(in the editor) in any way reset the event positions) and it didn't get that error. Maybe it's just his particular PC? He does find strange errors that don't occur on my pc. XP And yes that's what I meant, the door stays there, but the animation stays where it was and won't allow you to enter if you leave the map and come back.

Making all the doors named Door seems to be a far better idea actually, if that actually works I'll add that to the script and call it done. (I don't have fancy door stuff like automated/sliding doors or locked doors that need keys in my game)

Is there a way to reset an event entirely? EX: If Event Name "Door" = true then Reset Event on map load  ? (don't know how to set that up in Ruby script )  

Doors don't actually move, but the animation does, so yeah that is what I meant. XP this is what I get for typing at 2 AM xD 

He also said something about the door not letting you 'enter' (and teleport to the new place) but as I've said I haven't tested that for myself yet.

I usually have an idea of how I want something to work, but I don't know anything about scripting; I took a visual basic class a while back but that was like 3 years ago. XP

Everything else seems to work fine though, even autorun events that are already done. :3 

It could be the way he's programming his door events and not the script though, that also seems to be a possibility.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,924
Reaction score
14,556
First Language
English
Primarily Uses
RMMV
When you change the map, save it and play, even if you're still on that map in your save file, the Game_Map.setup method will be run. It's because you made a change to the map.

See this code?

#save additional event datamapEvents.each_value do |event| currentMap[event.id] = event.getData()endChange it to this:
Code:
#save additional event datamapEvents.each_value do |event|  currentMap[event.id] = event.getData() unless event.name =~ /door/iend
If it crashes saying it doesn't know what 'name' means, add this in a new script slot (or at the top of his script):

Code:
class Game_Event < Game_Character  attr_reader   :nameend
 
Last edited by a moderator:

naruzeldamaster

Veteran
Veteran
Joined
Jun 9, 2014
Messages
70
Reaction score
3
First Language
English
Primarily Uses
Script has been updated, and all bugs have been fixed, also I take no credit for this script; I only posted it here with permission because Darkshadow44 made it for my project and his and thought it would be useful compared to the other scripts of this kind.
 

Latest Threads

Latest Profile Posts

I am new to RPG maker MV, please be harsh with me :D
Shaz wrote on Tohtori_Jamba's profile.
Hi, you can post a thread for your game in the Completed Games forum. Please check the pinned thread there and make sure you provide all the requested information.
and_remember_tomorrow_more_redesigns_4.jpg

edit: The complete redesign of my player HUD, Time rewind message, mini map and puzzle map.... I'll toss up an animated version later. :LZSexcite:
Oh no my hospital test results are not good......just not good, but at least explains why my health tank more than usual lately. Stupid body. I want a refund on this body. = .=

Forum statistics

Threads
110,629
Messages
1,054,817
Members
143,758
Latest member
piruhawas
Top