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.

Player based event movement question.

I am wondering if there is a way to cause a movement of a map event to be based on the movement of the player i.e. dungeons in Lufia II: Rise of the Sinistrals or in Lufia: Ruins Lore. If I can do that, then I can remove my dependancy on rm2k map areas by having monsters move around in the exact same manner that they do in THOSE dungeons. I posted here because I was hoping a non-script means of doing this is possible because I do not need to make the engine lag that is not a good thing and scripts can tend to lag in a virtualized environment such as VMWare or Virtual PC.
 
This should do the trick. Just add a comment with the word defined at the top of the script within the event and BAM, it now approaches like a lufia enemy.

Code:
 

#===============================================================================

# Lufia Enemy Movement - by GubiD (04/24/2011)

#===============================================================================

 

#-------------------------------------------------------------------------------

# * Constants 

#-------------------------------------------------------------------------------

# ENEMY_COMMENT_IDENTIFIER - text that must be contained in comment for event to 

#    be recognized as Lufia type enemy. 

#-------------------------------------------------------------------------------

ENEMY_COMMENT_IDENTIFIER = "enemy"

 

#-------------------------------------------------------------------------------

# Game Map

#-------------------------------------------------------------------------------

class Game_Map

  #-----------------------------------------------------------------------------

  # Setup - Adjusted to setup lufia event hash

  #-----------------------------------------------------------------------------

  alias setup_gm_map_lufia_movement setup

  def setup(map_id)

    setup_gm_map_lufia_movement(map_id)

    @player_pos = [ $game_player.x, $game_player.y]

    refresh_enemy_event_list

  end

  #-----------------------------------------------------------------------------

  # Refresh Enemy List - Method to locate enemies for later updating

  #-----------------------------------------------------------------------------

  def refresh_enemy_event_list

    @l_enemy_list = []

    for id in @events.keys

      event = @events[id]

      if event.list.size > 0

        for command in event.list

          if command.code == 108 #comment

            if command.parameters[0].include?(ENEMY_COMMENT_IDENTIFIER)

              @l_enemy_list << id

            end

          end

        end

      end

    end

  end

  #-----------------------------------------------------------------------------

  # Update - Changed to check for 'player movement' and update enemies when done

  #-----------------------------------------------------------------------------

  alias upd_gm_map_lufia_movement update

  def update

    upd_gm_map_lufia_movement 

    if @l_enemy_list.size > 0

      if @player_pos != [ $game_player.x, $game_player.y]

        @player_pos = [ $game_player.x, $game_player.y]

        move_enemies

      end

    end

    check_for_event_erase

  end

  #-----------------------------------------------------------------------------

  # Check for Event erase - If an event is later erased, it cannot be updated

  #      so here we remove it from our 'update list'

  #-----------------------------------------------------------------------------

  def check_for_event_erase

    needs_removed = []

    for id in @l_enemy_list

      event = @events[id]

      if event.erased == true

        needs_removed << id

      end

    end

    if needs_removed.size > 0

      for id in needs_removed

        @l_enemy_list.delete(id)

      end

    end

  end

  #-----------------------------------------------------------------------------

  # Move_enemies - Takes all the enemies from list, and has them move toward player

  #-----------------------------------------------------------------------------

  def move_enemies

    for id in @l_enemy_list

      event = @events[id]

      event.move_type_toward_player

    end

  end

end  

#-------------------------------------------------------------------------------

# Game Event - Added ability to read if it has been erased

#-----------------------------------------------------------------------------

class Game_Event < Game_Character

  attr_reader :erased

end
 
That script will work but a true lufia style enemy can even move on a fixed path or a custom one as well as the type you provided a script for, simply only executing that path sequence when the player moves. In other words, same event movement as normal, just changing the frequency to only per player step.
 

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