Jump to content

Recommended Posts

Originally requested here: http://www.rpgmakerv...to-another-map/

 

This script allows you to copy an event from one map to another. Please note this does not save them to a map, you will need to add them every time. It does allow you to bypass the trial's 10 event limit, you could have the town's people in event repository maps and copy them in on an auto event every time you enter the town for example.

 

More genuine uses could be inserting an army to chase characters in a map, rather than have 10 or 20 soldiers have 1 and copy it as much as you need. Another potential use would be eventers using it to help event systems where you copy in an all purpose event into the map.

 

Anyway here's the script:


class Game_Map
 #--------------------------------------------------------------------------
 # â— Adds an event from another map to the current map
 #--------------------------------------------------------------------------
 def add_event(mapid, eventid, x, y)
map = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
map.events.each do |i, event|
  if event.id == eventid
	e = Game_Event.new(@map_id, event)
	e.moveto(x,y)
	@events[@events.length + 1] = e
  end
end
SceneManager.scene.get_spriteset.refresh_characters
 end
end

class Scene_Map < Scene_Base
 def get_spriteset
return @spriteset
 end
end

 

To use in an event call this:

$game_map.add_event(mapid, eventid, x, y)

Edited by Fomar0153

Share this post


Link to post
Share on other sites

That's great!

I knew it was possible, but I honestly had no idea how to do it. And it's so short, too!

 

The only thing I noticed:

@events[@events.length + 1] = e

Doesn't @events have a zero index? If so, you should remove the +1.

Share this post


Link to post
Share on other sites

[/code]Doesn't @events have a zero index? If so, you should remove the +1.

@events is a hash and when the original events are inserted they use the event id as the key. Which means they start from 1 (I assume this is why it's a hash and not an array).

 

But enjoy the script.

Share this post


Link to post
Share on other sites

I felt like something this useful needs a bump.

 

Good work on making something like this. We need to see more utility scripts~

Share this post


Link to post
Share on other sites

Uhm, just mentioning this, I've found a way around it, but I thought I might mention it anyway:

 

When using this script, I believe ID's for the spawned events aren't assigned properly. When trying to set a move route for them and activating them, they sometimes end up moving other events instead. When asking the game to specify the ID of the spawned event, it returns '1' in some cases, even though there already is an event with an ID of 1 on the map, and sometimes it returns '0', which doesn't really make sense to me, as events can't have an ID of 0.

 

Here is how I worked around it:

class Game_Map

 def add_event(mapid, eventid, x, y) #Call the Event
   map = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
   map.events.each do |i, event|
  if event.id == eventid
    id = eventid
    e = Game_Event.new(@map_id, event)
    e.moveto(x,y)
    #@events[@events.length + 1] = e
    @events[id] = e
    #The Event is now equal to the Event with id 'eventid' on Map 'mapid'.
  end
   end
   SceneManager.scene.get_spriteset.refresh_characters
   #$scene = Scene_Map.new 
 end
end

class Scene_Map < Scene_Base
 def get_spriteset
   return @spriteset
 end
end

 

I believe it now also copies the ID of the Event on that map. This does mean that if you don't want the copied Event to conflict with the events on the current map, it is necessary to copy an Event with an ID different from all the events already placed on the current map.

For example, I've made 199 empty Events on the map from which the needed Event is copied and made the 200th Event the one I need.The ID of the newly created event will now be 200, which is probably a lot higher than the the ID of the Events already present on the map.

 

Sorry if this does not make sense, I am not that great at explaining things...

 

Perhaps you could edit your script so that it creates a fresh ID to assign the new event. I'm fine with it currently, but it might be irritating for others.

Share this post


Link to post
Share on other sites

Alright, here's my ignorance shining through, but...why not just copy and paste the event?

Let's say someone wants to create a tool like a hookshot (because I've almost finished mine, lol) through eventing because that 'someone' is really bad at scripting.

By running a parallel common event that checks if the player presses Shift, for example, you can set conditions when the hookshot tool will be called.

Then, the hookshot event from the appropriate 'tools' page is copied and then pasted in the current map, after which it will fire in the direction the player is facing. After running through the commands of the event of the hookshot, it is deleted from the map and can be called again when the player presses shift.

 

This is cool, because now you don't have to copy and paste the hookshot tool on EVERY SINGLE MAP. Or all the other tools one might have.

Share this post


Link to post
Share on other sites

Events are assigned naturally I thought. Say a map has 5 events on it if you add an event it is now event 6 so far as the interpreter is concerned (I haven't read the interpreter through in full yet but I think I'm ok saying this) and any events interacting with it will have to target event 6. Your way may assign them 200 but don't you still have the same problem as before? Using the editor to interact with them?

 

If you wanted I could make the event return it's id as far as the current map is concerned and then you could stick it in a variable?

 

@Toby - It's a script I made to bypass the 10 events limit in the trial which I'm still using, yes I intend to just copy events across when I get the full version but I can see places where this could be useful. For example, say you want to have a marching army. The one event is programmed to move down 20 spaces then erase, you can just copy them to do each row for as long as you need etc. Or if you have enemies on the map you can copy the enemies in rather than copy and pasting them each time - which also means if you change something then you only have to change it in one place.

Share this post


Link to post
Share on other sites

Events are assigned naturally I thought. Say a map has 5 events on it if you add an event it is now event 6 so far as the interpreter is concerned (I haven't read the interpreter through in full yet but I think I'm ok saying this) and any events interacting with it will have to target event 6. Your way may assign them 200 but don't you still have the same problem as before? Using the editor to interact with them?

 

If you wanted I could make the event return it's id as far as the current map is concerned and then you could stick it in a variable?

 

I have tested this, but it always seems to return a strange ID, so perhaps it's just me. :P

Well, this script is great nonetheless, so I won't complain!

Share this post


Link to post
Share on other sites

I am trying to figure it out what to do with my version. It have its problems too, it's soon to publish it. Later I'll examine yours carefully and give some advice. Yea, I also have to do some work to go.

Share this post


Link to post
Share on other sites

How about a snippet to make it so we can delete an event we added on the map?

Share this post


Link to post
Share on other sites

About the ID-problem... you may want to take a look at this. (modified add_event method)

def add_event(mapid, eventid, x, y)
 map = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
 map.events.each do |i, event|
   if event.id == eventid
  e = Game_Event.new(@map_id, event)
  e.moveto(x,y)
  e.id = @events.length + 1
  @events[e.id] = e
  SceneManager.scene.get_spriteset.refresh_characters
  return e.id
   end
 end
end

It returns the event id, there will be no risk of ID conflicts if event was on same map and the id is equal to the event-key. Also this version has a veeery light better performance since it stops looping trough the events of a map when the requested event was found.

 

@ze1:

If you got the key of the event you simply clear it out of the event-hash and refresh the map.

@events.delete(key)
SceneManager.scene.get_spriteset.refresh_characters

Usually the key is the same like the id. Note that id's of events copied with the original script of this thread may not be equal to their key.

Share this post


Link to post
Share on other sites

#eid = new event id
def add_event(mapid, eventid, x, y, eid=100)
map = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
map.events.each do |i, event|
	  if event.id == eventid
		e = Game_Event.new(@map_id, event)
		e.moveto(x,y)
		@events[eid] = e
	end
end
SceneManager.scene.get_spriteset.refresh_characters
 end

Replace Event Commands by Scripts (Game_Interpreter) may help

Example: Display Animation

a = $game_map.events
a[100].animation_id = 1
Fiber.yield while a[100].animation_id > 0

it works fine with me

Share this post


Link to post
Share on other sites

@Death:

It may work this way..but I would not recommend to assign the id's manually. It's a bad habit and may lead to collissions (in this case it would simply overwrite). Also you're looping still through the events of the map after you already found the requested one. Maybe you want add a break command ;)

Share this post


Link to post
Share on other sites

@ze1:

If you got the key of the event you simply clear it out of the event-hash and refresh the map.

@events.delete(key)
SceneManager.scene.get_spriteset.refresh_characters

Usually the key is the same like the id. Note that id's of events copied with the original script of this thread may not be equal to their key.

 

Won't that simply erase the value in the hash? Will that erase the "object" event? If I create 10000000 events and use that snippet to delete all of them, won't I have an overloaded the memory?

 

Oh, and by the way, can't I turn on a self switch of a copied event via script? I'm using the code below, but it's not working.

 

key = [@map_id, @id, "A"]
$game_self_switches[key] = true

Edited by ze1

Share this post


Link to post
Share on other sites

Uh...good point about the overloaded memory. I'll take a look again onto memory management of ruby this evening. I'm used to managed languages there I usually don't have to care about memory.

 

About the self switch...messed around with it and found the problem and fixed it.

 

Also I noticed that id of Game_Event can't be set by default. Maybe you want to try this one (fixed and runs perfectly in my tests)

 

class Game_Map
 #--------------------------------------------------------------------------
 # â— Adds an event from another map to the current map
 #--------------------------------------------------------------------------
 def add_event(mapid, eventid, x, y)
   map = load_data(sprintf("Data/Map%03d.rvdata2", mapid))
   e = Game_Event.new(@map_id, map.events[eventid])
   e.moveto(x,y)
   e.event.id = @events.length + 1
   @events[e.id] = e
   SceneManager.scene.refresh_characters
   return e.id
 end
end
class Game_Event < Game_Character
 attr_accessor:event
 def id
    return @event.id
 end
end
class Scene_Map < Scene_Base
   def refresh_characters
       @spriteset.refresh_characters
   end
end

 

 

*edit*

updated the code, so it now works on a clean project.

Edited by DasMoony

Share this post


Link to post
Share on other sites

It still doesn't work here.

 

When I use it on my project, it says "Script Game_Interpreter line 1414: NoMethodError occured. Undefined method 'id=' for <Game_Event...>"

 

When I try it on a new project, it doesn't work as well. "Script Game_Interpreter line 1414: NoMethodError occured. Undefined method 'event' for <Game_Event...>"

Share this post


Link to post
Share on other sites

Uh.. my fault... have tested it on a project where i had some stuff in others scripts, sorry :(

 

I've updated the code on my last post. The new code works fine. (Tested it in a clean and new project).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×