Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: ShadowSaber on April 09, 2011, 09:20:29 am

Title: [Resolved][XP] Save Event Position
Post by: ShadowSaber on April 09, 2011, 09:20:29 am
Hello everyone, I want to request script that save every event position in the map
so when character leave the map and came back again, the event position didn't reset

thanks in advance
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 09, 2011, 09:39:16 am
That is not really doable. It would result in savefiles that are several MB in sizes, maybe even dozens of MB. This would also increase saving and loading times dramatically. If you really need this kind of thing, decide in which maps you need that and simply use a couple of variables with a parallel process event (that you delete right after setting all the positions that you saved the last time) and another parallel process event that keeps saving the positions.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 09, 2011, 10:36:13 am
ah, forgot to add

the saved position only saved in $game_temp, so if you close rmxp the saved position will lost
that way, the savefiles will stay the same


if I use variable for each event, that will waste a lot of variable, it seems much more efficient for a script
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 09, 2011, 12:36:50 pm
Quote from: Blizzard on April 09, 2011, 09:39:16 am
That is not really doable. It would result in savefiles that are several MB in sizes, maybe even dozens of MB. This would also increase saving and loading times dramatically. If you really need this kind of thing, decide in which maps you need that and simply use a couple of variables with a parallel process event (that you delete right after setting all the positions that you saved the last time) and another parallel process event that keeps saving the positions.


Maybe not necessarily. We could just use save_data and keep dumping data back into the map file. But of course there could be a risk of file corruption and stuff.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 09, 2011, 12:48:37 pm
It would still take time. Opening several files takes a lot more time than just one.

Anyway, if it's just temporary, then it's not much of a problem. You would just need a simple Map manager that which you use to create maps. You just "ask" the manager for a map and the manager gives it to you. If the map doesn't exist yet, the manager will load it. If it already exists (basically if you entered a map, left it and entered it again), then it will use that map. This is a script of 20-30 lines of code, very simple to make. It will use somewhat more RAM, though. In this case it would be good to be able to configure the map IDs which should be kept in the memory so not all maps are kept there (since often you have maps that never change like most dungeon maps or maps where you already use switches and variables for the map state).
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ForeverZer0 on April 09, 2011, 01:24:22 pm
You are likely gonna have some bugs if you aren't careful. You need to save more than just the coordinates. Any move routes are going to be screwed up because although the event may be starting a different place, they will still start executing their move route from the beginning. I really can't think of any simple way to store data for where in their move routes they should begin, but it shouldn't prove a problem for stationary events.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 09, 2011, 01:40:47 pm
That's why I suggested a whole map manager to keep the state of the whole map.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: WinterVisage on April 09, 2011, 06:12:23 pm
This is actually simply doable by an x/y variable per event (as long as you don't have more events than you do available variables).

All you'd need to do is set it so that when you leave your town, lets call it Nooblocity, and go to the level, lets call it Pwnsage Fields, in that teleport event you take every last one of the events x/y positions. When you step onto the teleport event to go back to the town, it'll then replace their "starting" x/y with this new x/y, thus making them remember their last location. The beauty of it is it's simple, the bad part is if you have a few hundred events on one map (hah, I highly doubt you will, but just saying!), you'll have to have two times that value in variables to handle all of them. My suggestion would be name the variables something like this syntax:

0001:{EVENT_NAME1}_X
0002:{EVENT_NAME1}_Y
0003:{EVENT_NAME2}_X
0004:{EVENT_NAME2}_Y

with {EVENT_NAME#} being the name of said event (best you actually name them, as well. That makes dumping the X/Y easier). This'll also be a permanent solution, saving those positions for not only the length of the game, but as well when you save/exit the game. You can even set up an extra common event doing the same thing which'll move the events back to where they were after they moved when you reload (last I remember, when you load in a map and they've moved, they reset back). Obviously, scripts are a little more quick than common events, but in some situations the common event is the easy route.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 09, 2011, 06:13:23 pm
Wait...self variables + event positions + modifying event creation method = solution?

My genius is showing.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ForeverZer0 on April 09, 2011, 06:26:53 pm
This doesn't solve the bug with move routes that will occur. You need to be able to save the index in the event's list, and set it to this on load.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 10, 2011, 04:13:27 am
Quote from: Blizzard on April 09, 2011, 01:40:47 pm
That's why I suggested a whole map manager to keep the state of the whole map.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 10, 2011, 08:31:13 am
Quote from: Blizzard on April 10, 2011, 04:13:27 am
Quote from: Blizzard on April 09, 2011, 01:40:47 pm
That's why I suggested a whole map manager to keep the state of the whole map.



Yea yea Blizz, we all know you have a huge ego. :V
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 10, 2011, 09:16:39 am
Nobody listens to my advice. ._.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 10, 2011, 09:43:43 am
Well of course. Its the internet. We have to read it. Anyways I've read it, I have no idea on how to go about it so meh.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 10, 2011, 02:11:40 pm
It's this easy.

module MapManager
 
  @maps = {}
  def self.get_map(map_id)
    @maps[map_id] = Game_Map.new if !@maps.has_key?(map_id)
    return @maps[map_id]
  end
 
end

class Game_Map
 
  alias setup_mapmanager_alias setup
  def setup(map_id)
    $game_map = MapManager.get_map(map_id)
    $game_map.setup_mapmanager_alias(map_id)
  end
 
end

Title: Re: [REQUEST] [XP] Save Event Position
Post by: The Niche on April 10, 2011, 03:01:07 pm
*Freaks out about Blizzard making a script so he *has* to be coming out of retirement*

Note: This is mostly hear to stop someone else saying it and meaning it.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 10, 2011, 03:29:22 pm
Yeah, I'm not coming out of retirement. xD
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 10, 2011, 03:40:21 pm
What if we paid you 20 grand a year to code us scripts?
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 10, 2011, 04:03:34 pm
Then yes.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 10, 2011, 04:24:24 pm
Alright then. Career plan change. I shall become a chef, only to live and die alone. Make 50 grand a year. Pay blizzard 20 of it. RMX-OS shall be flawless. And then I will slave drive you to make me minecraft in RMXP.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: The Niche on April 10, 2011, 05:44:08 pm
And I shall labour night and day to render G_G immortal.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 10, 2011, 11:09:42 pm
so, is anyone willing to do this?
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 11, 2011, 02:43:32 am
Lol, I already did.

Quote from: Blizzard on April 10, 2011, 02:11:40 pm
It's this easy.

module MapManager
 
  @maps = {}
  def self.get_map(map_id)
    @maps[map_id] = Game_Map.new if !@maps.has_key?(map_id)
    return @maps[map_id]
  end
 
end

class Game_Map
 
  alias setup_mapmanager_alias setup
  def setup(map_id)
    $game_map = MapManager.get_map(map_id)
    $game_map.setup_mapmanager_alias(map_id)
  end
 
end


Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 11, 2011, 03:54:35 am
oh thanks :D, but, can you tell me how to use it?
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 11, 2011, 04:14:59 am
Just insert is above main and that's that. No need to do anything.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: G_G on April 11, 2011, 08:23:08 am
Holy crap I thought that was like a base leading us in a direction or something. My god blizzard you beast.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: The Niche on April 11, 2011, 08:31:45 am
Blizzard came out of retirement, made one script, got bored and went back.
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 11, 2011, 09:26:11 am
:rofl:
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 11, 2011, 10:04:23 am
Quote from: Blizzard on April 11, 2011, 04:14:59 am
Just insert is above main and that's that. No need to do anything.


i didn't understand, I placed the script above main and the script have no effect?
I even testing it in new project without any custom script
Title: Re: [REQUEST] [XP] Save Event Position
Post by: Blizzard on April 11, 2011, 10:20:31 am
I made a small mistake, my bad. Try this.

module MapManager
 
  @maps = {}
  def self.get_map(map_id)
    if !@maps.has_key?(map_id)
      @maps[map_id] = Game_Map.new
      @maps[map_id].setup_mapmanager_alias(map_id)
    end
    return @maps[map_id]
  end
 
end

class Game_Map
 
  alias setup_mapmanager_alias setup
  def setup(map_id)
    $game_map = MapManager.get_map(map_id)
  end
 
end

Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 11, 2011, 07:58:20 pm
I have error with the new script :(

(http://img864.imageshack.us/img864/7751/unledsn.jpg)
Title: Re: [REQUEST] [XP] Save Event Position
Post by: nathmatt on April 11, 2011, 10:15:39 pm
here
Spoiler: ShowHide
class EventManager
  attr_accessor :events
  def initialize
    @events = {}
  end
end
$eventmanager =  EventManager.new
class Game_Map
  attr_reader   :events
  alias setup_eventmanager_alias setup
  def setup(map_id)
    setup_eventmanager_alias(map_id)
    if $eventmanager.events[map_id] != nil
      @events = $eventmanager.events[map_id]
      refresh
    else
      $eventmanager.events[map_id] = @events
    end
  end
 
end
Title: Re: [REQUEST] [XP] Save Event Position
Post by: ShadowSaber on April 12, 2011, 01:14:38 am
thank you very much, it works  :D