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.

[Resolved] [VX] Event duplication

To duplicate the 1st event of a map, I use the following code :

Code:
class Game_Map

    def data_events

      return @map.events

    end

end

 

def duplicate_event

  n = 0

  for i in $game_map.data_events.keys do

    n = [n, i].max

  end

  n += 1

  $game_map.data_events[n] = RPG::Event.new( $game_map.data_events[1].x+1, $game_map.data_events[1].y)

  $game_map.data_events[n].id = n

  $game_map.data_events[n].pages = $game_map.data_events[i].pages

  $game_map.events[n] = Game_Event.new( $game_map.map_id, $game_map.data_events[n])

end

The new event works perfectly, exept... it doesn't appear on the map.
When I say it doesn't apper, it only apply to its graphic (altough its pages[n].graphics is correct). It IS on the map, blocking the PC and giving the items it have to give (in my test project, the event is a chest).

What did I miss ??
Unless there is a simpler way to duplicate an event.
 
You need to refresh it's graphic in Spriteset_Map. A simple way to do that would be to make @spriteset in Scene_Map accessible (an attr_accessor) and then, at the end of duplicate_event, you can add $scene.spriteset = Spriteset_Map.new.

I know, it's bit of a dirty way to recreate the spriteset each time, but it works.
If you want to optimize the script, you can create a method in Spriteset_Map that refreshes the events graphics.

Also, I suggest you to take a look at my VX Map Layers script, I'm sure it can help you. :)

Hope it helps
-Dargor
 

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