NPC's Move While Waiting

Discussion in 'RGSSx Script Support' started by BrokenEffect, Mar 26, 2016.

  1. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    I have some NPC's moving around in my game with autonomous movement, and I don't want them to move around while waiting from the "Wait..." Command in an event.


    I found a simple script from someone with a similar problem.

    Code:
    class Game_Event < Game_Character  
      alias shaz_wait_for_message_game_event_update_self_movement update_self_movement
      def update_self_movement
        return if $game_message.busy? || $game_message.visible
        shaz_wait_for_message_game_event_update_self_movement  
      end
      end
    That script causes autonomous movement to pause while text is displayed from a message box.


    However, I also want autonomous movement to pause while waiting.


    For example,


    If i have an event that displays some text to the player and then waits (i.e you can't control the player until the waiting is done),


    I want all NPC's to stop moving until the waiting is done


    With the above script, NPC's will stop moving while text is displayed, however, when the text is done displaying and the character is waiting, all NPC's will resume movement.


    I tried using


    return if $game_timer.working?


    instead, but that did nothing. (It was just a guess, I don't think the game_timer class is actually used for waiting)


    Can anyone help me out?
     
    #1
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    37,797
    Likes Received:
    11,505
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You didn't say what engine you're using, so I'll assume you're using Ace (as that's what that bit of script I wrote, that you quoted, is based on).


    I am assuming you're referring to the Wait event command, and not the Wait command that's a part of the Move Route command list.


    Try changing this:

    Code:
    return if $game_message.busy? || $game_message.visible
    to this:

    Code:
    return if @interpreter.waiting?
    and add this to the very bottom of the script:

    Code:
    class Game_Interpreter
      alias shaz_pause_movement_while_waiting_initialize initialize
      alias shaz_pause_movement_while_waiting_wait wait
      def initialize(depth = 0)
        shaz_pause_movement_while_waiting_initialize(depth)
        @waiting = false
      end
      def wait(duration)
        @waiting = true
        shaz_pause_movement_while_waiting_wait(duration)
        @waiting = false
      end
      def waiting?
        @waiting
      end
    end


    What this is doing is, when you issue a Wait command, it sets the event's interpreter's 'waiting' status to true.  After the wait is over, it sets it back to false.  And when the move route is about to be updated, it checks if the interpreter is at a 'waiting' status, and if it is, it skips executing the update move method.


    I haven't tested this.  If you try it and it doesn't work, please post your full script as well as the full error message you receive - including the line number.  And confirm that you're using Ace.
     
    #2
  3. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Hi! Thanks for the quick reply, I am indeed using VX Ace.


    I'm getting an error when running my game:


    [​IMG]


    Here's the script:

    Code:
    class Game_Event < Game_Character  
      alias shaz_wait_for_message_game_event_update_self_movement update_self_movement
      def update_self_movement
        return if @interpreter.waiting?
        shaz_wait_for_message_game_event_update_self_movement  
      end
    end
    
    class Game_Interpreter
      alias shaz_pause_movement_while_waiting_initialize initialize
      alias shaz_pause_movement_while_waiting_wait wait
      def initialize(depth = 0)
        shaz_pause_movement_while_waiting_initialize(depth)
        @waiting = false
      end
      def wait(duration)
        @waiting = true
        shaz_pause_movement_while_waiting_wait(duration)
        @waiting = false
      end
      def waiting?
        @waiting
      end
    end


    The


    'return if @interpreter.waiting?'


    line is what's apparently causing the error.
     
    #3
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    37,797
    Likes Received:
    11,505
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    okay, can you change that one line to

    Code:
    return if @interpreter && @interpreter.waiting?


    and see if that fixes it?
     
    #4
  5. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Ok the script runs now with no error, but it doesn't actually function.


    I have an NPC moving around with autonomous movement and If I activate an event with the Wait event command, the NPC continues to move around.
     
    Last edited by a moderator: Mar 27, 2016
    #5
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    37,797
    Likes Received:
    11,505
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    The script works if you activate a Wait command on that event.


    A Wait command applies to that event only, not to the whole game.  And one event cannot look at every other  event to see if any of them have issued a Wait command.


    So you seem to be saying that if ANY event issues a Wait command (via the Wait event command, not the Wait move route command), you want ALL events to stop moving if they're on an autonomous move route?
     
    #6
  7. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Yes, sorry for not being clear enough.


    Here's what I mean.


    When the player interacts with an event that waits, you can not control the player. The player will stop moving until the wait event command has finished waiting.


    I want all NPC's to stop moving while this is happening. I.e. when you cant move due to waiting from an event, I want NPC's to stop autonomous movement.


    It similar to how NPC's will stop moving when a message box pops up. (with the original script)


    EDIT: However, I don't want just ANY wait command to do it. (for example, If i have some event that constantly runs that will flicker the lights every 120 frames or so, I don't want NPC's to stop moving while waiting between the Tint Screen commands. That wouldn't make any sense)


    The point is that I don't want NPC's to move around while the player has no control over anything. Therefor, if the player is waiting and cannot move, I want autonomous movement to pause until the waiting has finished and the player can resume control.


    Is there a way to do this?
     
    Last edited by a moderator: Mar 27, 2016
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,797
    Likes Received:
    11,505
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    There would be, but I think a different approach is necessary.  I'm having troubles getting Ace to run at the moment, but as soon as I get it working again I'll take a look.


    I suspect if we look at Game_Player and find what conditions allow button input to control movement, we can apply the same conditions to that method for events.
     
    #8
  9. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Ok, Thanks so much for your help! :)


    If you find anything, let me know.
     
    #9
  10. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    If there's a way to manually make NPC's pause and resume autonomous movement Via Events (A script or something)


    That would also be a viable option.
     
    #10
  11. Shaz

    Shaz Veteran Veteran

    Messages:
    37,797
    Likes Received:
    11,505
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Try this:

    Code:
    class Game_Event < Game_Character  
      alias shaz_wait_game_event_update_self_movement update_self_movement
      def update_self_movement
        return if $game_message.busy? || $game_message.visible
        return if $game_map.interpreter.running?
        shaz_wait_game_event_update_self_movement  
      end
    end
    This should stop NPCs moving if the character can't move because there's a message showing or there's an autorun common event.


    There are other reasons the player might not be able to move - if there's a forced move route, if followers are being gathered, if they're getting on or off a vehicle, or if they're in a vehicle but not able to move.


    I am not sure what happens if there is a map event (as opposed to a common event) that's set to autorun.  That would also stop the player from moving.  I'm not sure if the addition above would stop NPC events moving in that case.  Give it a try anyway - it should get you a bit closer.  If you decide you want your NPCs to be able to move when there's a message on the screen, just comment out that line.
     
    #11
  12. BrokenEffect

    BrokenEffect Villager Member

    Messages:
    15
    Likes Received:
    0
    First Language:
    English
    Is there a way to just manually do it?


    You can put scripts inside of events under the 'advanced' section.


    Can you just give me a script to manually insert into an event whenever I want all NPC's to stop movement?


    [​IMG]
     
    Last edited by a moderator: Mar 28, 2016
    #12

Share This Page