• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] NPC Follow Script Issues in RPG Maker with Pokémon Essentials v20.1

  • 1
    Posts
    84
    Days
    • Seen Mar 12, 2025
    Hi everyone,

    I'm having trouble with a custom script I'm trying to create for RPG Maker with Pokémon Essentials v20.1. I'm trying to implement an "NPC Follow" feature, where the player can ask an NPC to follow them, and the NPC will then follow the player around the map.

    I've written a script that seems to mostly work, but I'm encountering a few issues:

    # Questo plugin consente al giocatore di seguire gli NPC, offrendo un'esperienza di gioco più coinvolgente e dinamica.
    # Realizzato per la versione v20.1 di Pokemon Essentials. L'autore del plugin non vuole essere accreditato.
    # Spero che possa esservi utile nei vostri progetti.
    # This plugin allows the player to follow NPCs, offering a more engaging and dynamic gameplay experience.
    # Developed for version v20.1 of Pokémon Essentials. The author of the plugin does not wish to be credited.
    # I hope it can be useful in your projects.
    # Verifica se il plugin "follow_npc" è installato, altrimenti lo registra
    # Includi il file di configurazione
    # Modifica la classe Game_Player solo se il plugin è abilitato
    # Classe per il giocatore
    class Game_Player < Game_Character
    alias_method :original_initialize, :initialize
    def initialize(*args)
    original_initialize(*args)
    @following_npc = nil # Nessun NPC da seguire inizialmente
    end
    # Funzione per avviare il follow dell'NPC
    def start_following_npc(npc)
    @following_npc = npc
    pbMessage("#{npc.name} ha iniziato a seguirti!")
    end
    # Funzione per fermare il follow dell'NPC
    def stop_following_npc
    @following_npc = nil
    pbMessage("Hai smesso di seguire l'NPC.")
    end
    # Funzione di movimento verso l'NPC (migliorata)
    def move_toward(npc)
    sx = self.x - npc.x
    sy = self.y - npc.y
    if sx.abs + sy.abs > 1 # Maggiore di 1 per evitare movimenti a scatti
    if sx.abs > sy.abs
    sx > 0 ? move_straight(6) : move_straight(4)
    else
    sy > 0 ? move_straight(2) : move_straight(8)
    end
    end
    end
    # Funzione update per muovere il giocatore verso l'NPC
    def update
    super
    if @following_npc && @following_npc.pages.any?
    move_toward(@following_npc)
    end
    end
    end
    class Game_Event < Game_Character
    alias_method :original_initialize, :initialize
    def initialize(*args)
    original_initialize(*args)
    @is_followable = false # L'NPC non è seguibile inizialmente
    end
    # Funzione per abilitare il follow per questo NPC
    def enable_following
    @is_followable = true
    end
    # Funzione di aggiornamento
    def update
    super
    if @is_followable && $game_player.x == self.x && $game_player.y == self.y && Input.trigger?(Input::C)
    $game_player.start_following_npc(self)
    end
    end
    end
    class Game_Map
    alias_method :original_initialize, :initialize
    def initialize(*args)
    original_initialize(*args)
    end
    # Funzione per ottenere tutti gli eventi seguibili sulla mappa
    def followable_events
    events.values.select { |event| event.is_a?(Game_Event) && event.is_followable }
    end
    end
    class Scene_Map
    alias_method :update_original, :update
    def update
    update_original
    $game_player.update
    end
    # Override della funzione start per inizializzare gli NPC seguibili
    def start
    super
    $game_map.followable_events.each(&:enable_following)
    end
    end



    1. Camera movement: The camera doesn't follow the player smoothly when they're being followed by an NPC. It seems to lag behind or get stuck.
    2. NPC movement: The NPC's movement isn't very smooth either. They tend to move in a jerky or unnatural way.
    3. Potential conflicts: I'm worried that my script might be conflicting with other scripts or the default RPG Maker camera system.
     
    Back
    Top