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.

[XP]Call a event from one map to another.

I am trying to find a script that calls an event from one map to another.

So i could call Event:Bomb on map:weapons to the hero's current map and position.

I would use a conditional branch to see if you push a button then call a script using the @>Script: that
copies the bomb event from another map and puts it on the map with the hero
at his x and y position, Record the bombs position in new variables
Then i could use a common event to check around the bomb
and deal damage to any monsters in the range.

Could any one help me either find some thing that could work or make the code???
 
I made a short script to copy an event from one map to the hero's map, but it gives a new unused id to the copy, so I don't know how to handle it with a common event.

Paste this script where you want above main, there shouldn't be any compatibility problem :

Code:
#==============================================================================
# ** Service_Event
#------------------------------------------------------------------------------
#  24/03/08 - MGCaladtogel
#==============================================================================
class Service_Event
  #--------------------------------------------------------------------------
  # * copy_event : copies a Game_Event from one map to the current map
  #     map_id    : source map's id
  #     event_id  : source event's id
  #     x         : new event's x-coordinate (facultative)
  #     y         : new event's y-coordinate (facultative)
  #--------------------------------------------------------------------------
  def self.copy_event(map_id, event_id, x=nil, y=nil)
    # loads the source map and the event
    map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    event = map.events[event_id]
    # alters default coordinates
    if x != nil
      event.x = x
      event.y = y
    end
    # finds a unused id
    new_event_id =  $game_map.events.keys.sort[$game_map.events.keys.size - 1] + 1
    event.id = new_event_id
    # instanciates a new Game_Event from the loaded event
    new_event = Game_Event.new($game_map.map_id, event)
    # adds the event to the current map
    $game_map.events[new_event_id] = new_event
    # clears and re-creates the spriteset's character_sprites to obtain a correct display
    character_sprites = $scene.spriteset.character_sprites
    for sprite in character_sprites
      sprite.dispose
    end
    character_sprites.clear
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      character_sprites.push(sprite)
    end
    character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
class Scene_Map
    attr_accessor :spriteset
end

#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
class Spriteset_Map
  attr_accessor :character_sprites
  attr_accessor :viewport1
end

To use it, just write :
Code:
Service_Event.copy_event(source_map_id,source_event_id,x,y)

For example, in order to copy the event with id = 1 from the map with id = 2 and to put it at the hero's coordinates, call :
Code:
@>Script: x=$game_player.x
               : y=$game_player.y
               : Service_Event.copy_event(2,1,x,y)

I hope that this will help you a little.
 

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