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.

Copy event from seperate map(during run-time)!

Copy events during run-time! v1.0
By: Near

Introduction

I recently figured out how to take an event from a map, and place it in the player's current map.

Screenshots

No screens. It doesn't prove much to have screenies of an event on a map, now does it?

Demo

Why do you need a demo for such a simple script?

Script

[rgss] 
class Game_Map
  def new_ev_id
    for i in 0..999
      return i if @events.nil?
    end
  end
 
  def transfer_event(map_id, ev_id, x, y)
    new_map ||= Game_Map.new
    new_map.setup(map_id)
    ev = new_map.events[ev_id]
    @events[new_ev_id] = ev
    @events[new_ev_id].moveto(x, y)
    refresh
    new_map = nil
    ev = nil
  end
end
 
[/rgss]

Instructions

Just call $game_map.transfer_event(<the map the event is on>, <the event's id>)
Easy as that.

Credits and Thanks

RTH, because he helped me figure this out.

Terms and Conditions

Do what you like.
 
What does
Code:
new_map ||= Game_Map.new
the || mean?

Well, there are some scripts like that already and yours is not really the best.
You could just use:

Code:
def transfer_event(map_id, ev_id)

  new_map = load_data(sprintf("Data/Map%03d.rxdata", map_id))

  event = Game_Event.new(@map_id,new_map.events[ev_id])

  @events << event

end

Your method also needs parameters to set the position of the map like

Code:
def transfer_event(map_id, ev_id, x, y)

  new_map = load_data(sprintf("Data/Map%03d.rxdata", map_id))

  event = Game_Event.new(@map_id,new_map.events[ev_id])

  @events << event

  event.x, event.y = x, y

end

Finally you have to refresh the Game_Map after adding the event.

Code:
def transfer_event(map_id, ev_id, x, y)

  new_map = load_data(sprintf("Data/Map%03d.rxdata", map_id))

  event = Game_Event.new(@map_id,new_map.events[ev_id])

  @events << event

  event.x, event.y = x, y

  refresh

end
 
||= means assign if null.

Code:
for i in 0..200
Why not 0..999 ? If I have more then 200 events, this script doesn't work.
 
Why would you have more than 200 events on a map?

Fine, I'll add that then. Also, I knew I had to refresh it, i just didn't think of it at the time... but why do you need to set the event's position in the function? It gets put where it was on the other map too.
 
In case there is an event there in the new map..
Code:
class Game_Map

  def occupied_tile?(x,y)

    return false if @map.events.keys.size ==0 

    for i in @map.events.keys

      e = @events[i]

      if (e.x == x) and (e.y==y) 

        return true 

      end

    end

    return false     

  end

 

def new_x_y

  for x in [email=0...@map.width]0...@map.width[/email]

    for y in [email=0...@map.height]0...@map.height[/email]

      if ! occupied_tile?(x,y)

         @new_x = x

         @new_y = y

         return

      end

    end

  end

end

 

  def new_ev_id

    for i in 0..999

      return i if @events[i].nil?

    end

  end

 

  def transfer_event(map_id, ev_id)

    new_map ||= Game_Map.new

    new_map.setup(map_id)

    ev = new_map.events[ev_id]

    new_x_y

    ev.x = @new_x

    ev.y = @new_y

    @events[new_ev_id] = ev

    new_map = nil

    ev = nil

  end

 

end
 
Near":16sqgyuz said:
Why would you have more than 200 events on a map?

Fine, I'll add that then. Also, I knew I had to refresh it, i just didn't think of it at the time... but why do you need to set the event's position in the function? It gets put where it was on the other map too.

As a scripter you should never make such an assumption. It's not even that unlikely.
 
Well, I'm not only a scripter, I'm also a skilled eventer. And I would only use 200+ events under 2 conditions:
1. I had a very good Anti-Lag script.
2. It was a huge map with tons of npcs/transfers.

But anyway, I'm updating the script right now.

Off Topic:

While I remember, are you still working on Netplay+ 3? I'd use it if it works well.
 

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