Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Save the state of map events.

This is a very small piece of code I've written for saving the state of map events. I mean, when you go in and out of a map, all the events are loaded from the data stored in your project...
If you want to override this mechanism and mantain for example the position reached by a moving event or its graphic, or whatever would be reset when the map is loaded again from scratch, you can go mad with local switches and their possibilities are somewhat limited... (breathes).
So I have thought to this solution.

Demo

http://sites.google.com/site/charliefleed/EventStates.zip

Here some simple state variables such as the position and the graphic can be stored, loaded from and cleared in a simple database which uses map_id and event_id as the key. When a map is created the state of all events is re-established if it has been previously stored.

I hope this can be useful to someone.
I welcome suggestions, bug reports, and ideas for its applications.
Bye.
 
Like, when I play my game, and save right after picking up an item, when i restart the game, the item appears again.

Will this script prevent that?
 
You can solve your problem by using a switch and make a second page in that even with the event on the upper left on.

Leave the rest blank.

charlie.lee nice script very useful.
 

kdb424

Member

You, are a lifesaver! You will be going near the top of the credits in my game! I do hate to be dumb and ask how to use it though. I inserted it but I assume that it's not automatically done. I'm new to RGSS but I'm learning.
 
Instructions are in the header. Basically you have commands to load, save and clear event state. When you save a state, it will be loaded automatically by entering in the map.
Tell me what you would like to do so that i can be more specific.
 

kdb424

Member

Ok. In the teleporting event leaving that map that I want to save, I use a script with  $game_map.events[@event_id].record_state correct? Then upon reentry it will be loaded automatically?

Edit: I had to replace @event_id with the event ID. Is there a way that I can make something so it remembers every single event place of every event by having it memorize all of them no matter how many there are, it will just memorize them all. I have over 300+ events on this map. lol

Edit 2: Still confused even replacing the event ID. There was another error. What else do I change? Sorry.
 
Try this:
Code:
for id in 0...$game_map.events.size
  $game_map.events[id].record_state unless $game_map.events[id]==nil
end

if you have to break the second line, do it after a "."
 
kdb424":7nq5iwrw said:
Man. I am really RGSS stupid. I have no idea what to replace with what.... I am hopeless.

Ah, ah. "RGSS stupid" is great. :D
You have an event that teleports the hero to another map, right?
Ok. In that event, before the teleport command, insert a script command (it's in the third page) and put the code i wrote in my previous post in it.
That's it.
 

regi

Sponsor

Just a sidenote, kdb424 please check the date of the last post before replying. If it was posted more than a month ago, it's considered necroposting. Next time just PM the OP or create a new thread in a support forum.

It's okay here since the OP is still active, but generally you should avoid this.
 
Oh, please.
He did ask for a script like this in the request board, and I personally told him there was this script of mine here.
So he didn't do anything wrong.

Regi, please check the latest posts of the person you're going to bug with your "you! necroposterrr..."...
( just a joke ;) )
 

regi

Sponsor

Heh Charlie that's okay then, but he's been necroposting a bit and it's one of those things that kind of bug me :eek:

More on topic, now that I'm looking at your script it looks kind of useful.
Reminds me of dubealex's old Memorize Location script, but a lot cleaner and easier to use ;)
 

kdb424

Member

I tried to put that code in a script in the event. It gave me a syntax error. I don't know where to go from there.
 
Is this compatible with Poccil's Pokemon Starter Kit? For when I save after doing an important event that walks next to you, it is reset when I start up that save file totally messing up gameplay.

If it is compatible then you my friend are a lifesaver.

Thanks!
-Krobe
 

kdb424

Member

Charlie Lee":1r7qg0uh said:
Note that the state is not saved in your savefile.

Just so you know. You can use some variables and use RGSS on load to call a game switch to move the event back there like I did.
 
@kdb424
I told you to break the long lines after a ".". That's your problem.
Ok, I'll do it for you.

Code:
for id in 0...$game_map.events.size
  $game_map.events[id].
  record_state unless $game_map.
  events[id]==nil
end


@Krobelus:
I think it can be easily modified so that states are saved in the savefile... expect some update.

What about this?
Code:
#==============================================================================
#==============================================================================
# â–  Support for events' state (by Charlie Lee)
#  use with: $game_map.events[@event_id].record_state
#  $game_map.events[@event_id].load_state
#  $game_map.events[@event_id].clear_state
#  from inside the events through command "Script" 
#  
#------------------------------------------------------------------------------

class Game_Event < Game_Character
  attr_reader   :event
  
  def record_state
    key = [@map_id, @event.id]
    $game_system.game_event_records[key]=[x, y, @character_name]
  end

  def load_state
    key = [@map_id, @event.id]
    if $game_system.game_event_records[key] != nil
      x=$game_system.game_event_records[key][0]
      y=$game_system.game_event_records[key][1]
      moveto(x,y)
      @character_name=$game_system.game_event_records[key][2]
    end
  end

  def clear_state
    key = [@map_id, @event.id]
    if $game_system.game_event_records[key] != nil
      $game_system.game_event_records[key] = nil
    end
  end
end


class Game_Map
  alias setup_record setup
  def setup(map_id)
    setup_record (map_id)
    for i in @map.events.keys
      @events[i].load_state
    end
  end
end


class Game_System
  attr_accessor :game_event_records
  alias ge_initialize initialize
  def initialize
    ge_initialize
    @game_event_records={}
  end
end
 
Hi i was just wondering if this script could possibly be used to solve my very annoying problem..... my game includes an ABS but my problem is i dont want the enemys hp bar to reset when you leave a map and also their position e.g. attack an enemy leaving at it with 10hp, exit the map then re-enter and the enemy is in the exact same loc with 10hp still....
 
I cant get it right, can somebody help?
I need EV015 saved and loaded but i dont know what i should do....
I read all posts here and i dont know what to do, can someone make a demo that works?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top