Big Events

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

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Big Events
    2018.01.13
    by Shaz

    Introduction
    This plugin allows you to set an event's collision area to cover more than one tile.
    This is ONLY for events that do not move.

    How to use
    Add plugin to your js/plugins folder - name must be Shaz_BigEvents.js - and enable in plugin manager.
    Place an event in the top left corner of the area you want to cover.
    If you want the collision area to be set the same for all pages of the event, put <bigEvent:wxh> into the event's note box, where w is the total width and h the total height of the collision area.
    If you want a single event page to have a different sized collision area, put <bigEvent:wxh> into a Comment command on the event page.

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

    Credit
    - Shaz

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

    Notes
     
    #1
    Dankovsky, Kyuukon, Llareian and 6 others like this.
  2. GrandmaDeb

    GrandmaDeb Modern Exteriors Posted! Veteran

    Messages:
    4,468
    Likes Received:
    2,793
    Location:
    East Coast, USA
    This looks really useful. Thanks Shaz. Less copying events means less mistakes. Plus each page can change? Super versatile!
     
    #2
  3. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I used this one on Ace. I'm sure someone has written one for MV, but I needed a small, easy one to get back into the swing of things :)
     
    #3
  4. Kyuukon

    Kyuukon 主人公 Veteran

    Messages:
    2,152
    Likes Received:
    974
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    I went ahead and made a little extension for myself of this plugin. What it does now: adds the optional "offset" parameter so that it shifts the big square by ox and oy (more instructions on how to use it in the help section).

    Maybe someone else can find it useful as well. Here it is:
    Code:
    /*:
     * Big Events by Shaz and Akumu Games
     * Ver 1.0.AG 2018.01.31
     * Shaz_BigEvents.js
     *
     *
     * @plugindesc Set an event's collision area to cover more than one tile.
     * @author Shaz
     *
     * @help This plugin allows you to set an event to cover more than one tile
     * for collision purposes.  You can specify the entire event (all pages) to
     * have the large collision area, or just individual pages.
     *
     * USAGE:
     * Place the event in the top left corner of the area to be covered.
     * Enter <bigEvent:wxh|offset:ox,oy> in the event's note box (affects all event pages),
     * or as a comment on the event page (affects just that page), where w is
     * the number of tiles across and h is the number of tiles down that the
     * event will occupy and ox and oy is the collision box offset.
     * A <bigEvent:...> comment on an event page will override a <bigEvent...>
     * tag in the note box.
     *
     * Example:
     * <bigEvent:1x3|offset:-1,0> in the notebox of an event will expand the collision area
     * of that event to cover the current tile plus two tiles below (total width
     * is 1 and total height is 3) and offset the collision box one tile to the left.
     * <bigEvent:4x4> in a comment on an event page will expand the collision
     * area to a 4x4 square, just while that page is active.
     *
     * NOTE:
     * This plugin has no plugin commands.
     * This plugin is only to be used for events that will not move.
     *
     */
    
    var Imported = Imported || {};
    Imported.Shaz_BigEvents = true;
    
    var Shaz = Shaz || {};
    Shaz.BE = Shaz.BE || {};
    Shaz.BE.Version = 1.00;
    
    (function() {
       var _Shaz_BE_Game_Event_initMembers = Game_Event.prototype.initMembers;
       Game_Event.prototype.initMembers = function() {
           _Shaz_BE_Game_Event_initMembers.call(this);
           this._xr = null;
           this._yb = null;
           this._xro = 0;
           this._ybo = 0;
       };
    
       var _Shaz_BG_Game_Event_pos = Game_Event.prototype.pos
       Game_Event.prototype.pos = function(x, y) {
           if (this._xr) {
                 return (this._x + this._xro) <= x && (this._x + this._xr + this._xro) >= x && (this._y + this._ybo) <= y && (this._y + this._yb + this._ybo) >= y;
             } else {
                 return _Shaz_BG_Game_Event_pos.call(this, x, y);
             }
       };
    
       var _Shaz_BE_Game_Event_clearPageSettings = Game_Event.prototype.clearPageSettings;
       Game_Event.prototype.clearPageSettings = function() {
           _Shaz_BE_Game_Event_clearPageSettings.call(this);
           this._xr = null;
           this._yb = null;
           this._xro = 0;
           this._ybo = 0;
       };
    
       var _Shaz_BE_Game_Event_setupPageSettings = Game_Event.prototype.setupPageSettings;
       Game_Event.prototype.setupPageSettings = function() {
           _Shaz_BE_Game_Event_setupPageSettings.call(this);
           this._xr = null;
           this._yb = null;
           this._xro = 0;
           this._ybo = 0;
           var param = null;
           if (this.page() && this.list()) {
               this.list().filter(function(cmd) {
                   if ((cmd.code === 108 || cmd.code === 408)) {
                       if(cmd.parameters[0].match(/<bigEvent:\s*(\d+)x(\d+)\s*\|\s*offset:\s*(-?\d+),(-?\d+)>/)) {
                           param = [RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4];
                           return true;
                       } else if (cmd.parameters[0].match(/<bigEvent:\s*(\d+)x(\d+)>/)) {
                           param = [RegExp.$1,RegExp.$2,0,0];
                           return true;
                       } else {
                           return false;
                       }
                   } else {
                       return false;
                   }
               });
           }
           
           if (!param){
               if (this.event().note.match(/<bigEvent:\s*(\d+)x(\d+)\s*\|\s*offset:\s*(-?\d+),(-?\d+)>/)) {
                   param = [RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4];
               }else if (this.event().note.match(/<bigEvent:\s*(\d+)x(\d+)>/)) {
                   param = [RegExp.$1,RegExp.$2,0,0];
               }
           }
           
           if (param) {
               this._xr = parseInt(param[0]) - 1;
               this._yb = parseInt(param[1]) - 1;
               this._xro = parseInt(param[2]);
               this._ybo = parseInt(param[3]);
           }
       };
    
    })();
    
    Let me know if you find any bugs :kaoswt2:

    And thank you for this plugin, Shaz!
     
    Last edited: Jan 31, 2018
    #4
    Shaz likes this.
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You know, in my Ace version, it was based on centering the event along the bottom, so you could say how many squares to the left and right, and how many above. I only remembered why I did that after I converted the project to Ace and realised I had some "big" events that had sprites covering more than one tile, and the event needed to be at the bottom.

    The only change I would make to your extension is to remove the calculations from this:
    Code:
    return (this._x + this._xro) <= x && (this._xr + this._xro) >= x && (this._y + this._ybo) <= y && (this._yb + this._ybo) >= y;
    and put them into the setupPageSettings function and store the results into new variables. That way, you're only doing the comparisons each time the pos() function is called, and not up to 4 lots of additions as well. You can do this because the event isn't moving around, so those coordinates won't change. I think pos() is called on every event on the map, by every moving event on the map as well as the player, on every frame, so that could be a lot of calculations it's trying to do and could make things slow.
     
    Last edited: Jan 31, 2018
    #5
    Kyuukon likes this.
  6. Kyuukon

    Kyuukon 主人公 Veteran

    Messages:
    2,152
    Likes Received:
    974
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    Oh, I see. Now I wanna try something else. Will edit the update :) Thanks!

    Edit: Based on what you just wrote, I made a little tweak. Probably not for the best in terms of performance, like you said, but now you are able to transfer the event to other coordinates and keep the big size (I tested this and you couldn't do this before). It may come in handy for some cut-scenes, don't you think (like moving a big boulder or I dunno)?
     
    Last edited: Jan 31, 2018
    #6
    Shaz likes this.
  7. Rave

    Rave Veteran Veteran

    Messages:
    99
    Likes Received:
    26
    First Language:
    Polish
    Can you make it work for moving events? I mean, if event doesn't move, you might as well surround it with invisible "same level as character" events and you get the same result.
     
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    No, it specifically only works for static events. Have a look around though as I think someone did make one of these for moving events.
     
    #8
  9. kittgts

    kittgts Villager Member

    Messages:
    15
    Likes Received:
    2
    First Language:
    ru
    Primarily Uses:
    RMMV
    Good afternoon, Thanks for the cool plugin, but here's the question. Can you add the ability to make the expansion of tiles not only down but up?
     
    #9
  10. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    13,769
    Likes Received:
    12,416
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    Hi Shaz, I've been trying the notetag:
    Code:
    <bigEvent:1x3>
    but it doesn't work. Oddly enough, 2x3 works.
     
    #10
  11. Shaz

    Shaz Veteran Veteran

    Messages:
    35,320
    Likes Received:
    9,859
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    @Archeia that's strange - I use it with 1 all the time and have no issues.

    Can you give me a screenshot of the map with the event highlighted, and a screenshot of the event?
     
    #11
  12. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    13,769
    Likes Received:
    12,416
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    Strange it works now and I didn't do anything. Maybe I was just tired. Sorry Shaz :kaoeh:
     
    #12
    Shaz likes this.

Share This Page