Toggle Event Page

Discussion in 'JS Plugin Releases (RMMV)' started by Shaz, Jan 14, 2018.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Toggle Event Page
    2018.01.14
    by Shaz

    Introduction
    This plugin allows you to temporarily disable a page on an event on the current map, and to re-enable it again. It is like the Erase Event command, but works on individual pages instead of the whole event. Like that command, the effect is only temporary - when you leave the map and return, all pages will be enabled again. It works alongside page conditions - the highest numbered page whose conditions are met and has not been disabled will become active.

    How to use
    Add plugin to your js/plugins folder - name must be Shaz_TogglePage.js - and enable in plugin manager.
    Enter TogglePage in a plugin command, followed by optional arguments.
    You can use a formula for one or both arguments - just make sure there are no spaces.
    The page id refers to what you see in the editor. Tab 1 is the first page id.

    Example
    TogglePage - toggles the current page of the current event
    TogglePage 5 - toggles page 5 of the current event
    TogglePage 10 3 - toggles page 3 of event 10 on the current map

    Plugin
    Download from pastebin
    make sure to save it as Shaz_TogglePage.js

    Credit
    - Shaz

    Terms
    - free for use in commercial games
    - do not post elsewhere - link back to this page

    Notes
    - This plugin overwrites the Game_Event.prototype.findProperPageIndex function. There will likely be compatibility issues if you have other plugins that overwrite the same function. There may be compatibility issues if you have other plugins that alias the same function - try changing the plugin order.
     
    #1
    ∊η∊ηra and Frogboy like this.
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Here's an easy way to use it ...

    Let's say you're in a park area in town, and you want a bit of wildlife around, but you don't want it to always be the same. Sometimes it might be a dove walking on the ground that just does its own thing, sometimes a bird that flies over the trees, sometimes a mouse that scurries away from you.

    Create an event with 3 pages - each one with the different creature, with its priority, through, move route set appropriately. Condition each page by a different self switch (or you could use a self variable if you have a plugin for it).

    Now create a 4th page - the highest numbered, as a parallel process. On that page, turn off all self switches, then randomly turn one of them on (or set the self variable to a random number in the acceptable range). Finally, call the plugin command TogglePage to disable the current page. The page will no longer be active, as it's disabled, and whatever highest numbered page has its self switch (or self variable) condition met will become the active page.

    When you leave the map and return, a different random page will be activated.


    This could be used for anything you want to randomly change each time a map is loaded, without using up global variables or switches, or requiring a "controlling" event just to determine which page is going to be active. Sometimes a kitchen table might have food and drinks, food preparation, books, sewing supplies. NPC dialogue or actions could change each time you return to a map. I'm sure you'll have more imaginative ideas than this.

    Remember the pages are all enabled when you return to a map - just like the Erase Event command.
     
    #2
    SuperMasterSword likes this.
  3. RadiantCadenza

    RadiantCadenza Veteran Veteran

    Messages:
    99
    Likes Received:
    62
    First Language:
    English
    I cannot thank you enough for this one!


    It solves several issues I was having, and much more elegantly than my current solutions.

    You see, I'm working on an action RPG, with all combat being real time, evented and in map, and in most maps the enemies return/reset when defeated. (Just like in a game like Legend of Zelda for instance) I made my right-most page an 'initializer' that resets all the event's health, self switches etc tied to a global 'reset room' switch that I turn on every room transition and turn off a few frames later. Worked as a quick and dirty solution, but it prevented me from making large maps and inviting many potential bugs if I messed up and forgot to flip the switch on and off properly for every single map and transition.

    This will let me do that but way better. Just have the initialization page first and make it deactivate itself. Way more user friendly to myself, and much less room for bugs to sneak in.

    I'll definitely need to play around with this.
    Might be able to use the functionality for toggling pages in other events for designing puzzles as well.
     
    #3
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Make the initialization page last (on the right) and don't give it any conditions. It MUST be the active one when the map is loaded.
     
    #4
  5. Frogboy

    Frogboy I'm not weak to fire Veteran

    Messages:
    1,396
    Likes Received:
    1,649
    Location:
    North Carolina, U.S.
    First Language:
    English
    Primarily Uses:
    RMMV
    This looks cool. Great way to handle some map preprocessing. Thanks!
     
    #5
  6. RadiantCadenza

    RadiantCadenza Veteran Veteran

    Messages:
    99
    Likes Received:
    62
    First Language:
    English
    Oh, I just read/count the pages right to left. So when I say "first page" I actually mean the right most one. If I add a new page at the right, then that becomes the first page.

    It makes more sense to me with how they work, but I forgot a lot of other people think of it the other way around.
     
    #6
  7. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Actually, another good use for this would be those events that block your way until you do a certain task, then they move out of your way and every time you go back to the room they're in the "new" position.

    Page 1: no condition: You shall not pass!
    Page 2: have item bribe in inventory: Okay, you can pass. Move Route to go to new position, turn on self switch A.
    Page 3: self switch A is on: I said you can pass now.
    Page 4 (parallel process): self switch A is on: Set Event Location to go to new position, toggle page.

    No more needing a second event to move the blocking event to where it should be.

    There are a couple of plugins (at least one from me and one from Yanfly) that already let you save an event's new location. This is a different way to do the same thing.
     
    #7
    Frogboy likes this.

Share This Page