Re-Ordering the Enemy Book?

Discussion in 'Javascript/Plugin Support' started by AdamantineOrichalcum, Jul 5, 2019.

  1. AdamantineOrichalcum

    AdamantineOrichalcum Villager Member

    Messages:
    5
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm a little surprised I can't find this question anywhere through Google, so I guess I'll ask it. :p

    I'm using the base game's Enemy Book plugin and I honestly prefer it to the other user-made plugins I've found, but I was wondering if there was any way to re-order the entries without re-ordering my whole Enemies tab. I've got over 200 enemies and a good chunk of my game finished, so that would be an insane amount of work, not to mention if I got the urge to add something later, I'd have to do it all over again.

    Any solutions / ideas?
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,134
    Likes Received:
    6,372
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    you can't do that without rewriting the plugin.

    and what order would you want?
    The ONLY possible way to reorder is to base it on a static property when reprogramming the plugin.
    so you can say "I want the enemies sorted by ATK" or "I want them sorted by alphabetic name".

    The only way to give a custom order would be to implement that order in the database.
     
    #2
    Another Fen likes this.
  3. MushroomCake28

    MushroomCake28 KAMO Studio Veteran

    Messages:
    1,614
    Likes Received:
    2,872
    Location:
    Montreal, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    You need to modify the plugin.

    @Andar The way I do it is that I create an array that gets the order I want by storing the enemy ID in that order.

    Code:
    var enemyOrder = [
        4, 6, 12, 17,
        2, 5, 8, 59,
    ]
    So in that example the enemy #4 would have an artificial ID of 1, enemy #6 would be ID of 2, enemy 12 would have an ID of 3, etc. It's a lot of hassle, but it's the only way to truly have a customizable enemy order without filtering by stat, name, or anything else. And of course, it requires modifying the plugin.
     
    #3
    Another Fen likes this.
  4. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    As others mentioned, you need to modify the plugin to allow for alternate ordering. I'd generally recommend against modifying the original plugin, but instead rewrite the parts in question in a second plugin placed after the original (this allows for easy removal/modification of your addition and avoids confusion when you forgot which of your plugins were modified later on).

    In this case you probably only have to modify one function.

    If you only want to change the position of some enemies, you could try this:
    This allows you to add
    <bookorder: 24>
    to an enemies notebox to place it directly before the original position of another enemy (#24 in this case)
    Code:
    (function() {
     
       var orderFunction = function(enemy1, enemy2) {
           if (enemy1.meta["bookorder"] === undefined) {
               var pOrder1 = enemy1.id;
               var sOrder1 = Number.MAX_VALUE;
           } else {
               var pOrder1 = Number(enemy1.meta["bookorder"]);
               var sOrder1 = enemy1.id;
           }
           if (enemy2.meta["bookorder"] === undefined) {
               var pOrder2 = enemy2.id;
               var sOrder2 = Number.MAX_VALUE;
           } else {
               var pOrder2 = Number(enemy2.meta["bookorder"]);
               var sOrder2 = enemy2.id;
           }
           return (pOrder1 === pOrder2) ? sOrder1 - sOrder2 : pOrder1 - pOrder2;
       };
    
        Window_EnemyBookIndex.prototype.refresh = function() {
            this._list = [];
            for (var i = 1; i < $dataEnemies.length; i++) {
                var enemy = $dataEnemies[i];
                if (enemy.name && enemy.meta.book !== 'no') {
                    this._list.push(enemy);
                }
            }
            this._list.sort(orderFunction);
            this.createContents();
            this.drawAllItems();
        };
    
    })();

    If you want to thoroughly change the enemy order and prefer Mushroomcake28's solution you could probably try something like this:
    (Change the enemy list in line 3 of the plugin)
    Code:
    (function() {
     
       var enemyOrder = [ 4, 6, 12, 17, 2, 5, 8, 59,    ];
     
     
       Window_EnemyBookIndex.prototype.refresh = function() {
            this._list = [];
            for (var i = 1; i < enemyOrder.length; i++) {
                var enemy = $dataEnemies[enemyOrder[i]];
                if (enemy && enemy.name && enemy.meta.book !== 'no') {
                    this._list.push(enemy);
                }
            }
            this.createContents();
            this.drawAllItems();
        };
    
    })();

    Not that experienced in Javascript yet, so I just hope it works out.
     
    Last edited: Jul 6, 2019
    #4
  5. AdamantineOrichalcum

    AdamantineOrichalcum Villager Member

    Messages:
    5
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMMV
    This worked! Although it seems to take the notetag number and add one to it, so to put an enemy in the first spot, you'd put <bookorder: 0>. Maybe this is what you meant and I'm misreading, but that method works anyway, so hooray! I haven't tested the second method yet, but it seems like it'd work to me.

    Also, for anyone who finds this thread in the future and is a Javascript noob like me, keep in mind you need to paste this bit of code within the lines that say "(function() {" and the last "})();" to work. It took me a second to figure that out. ^.^;

    Thanks a ton, everybody!
     
    #5
    MushroomCake28 likes this.
  6. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    Have to admit I didn't actually test the code above ingame, so there may be problems in there I overlooked the first time.
    In this case I forgot that the "bookorder" is interpreted as text internally instead of a number, which confuses the comparison in line 18. This shouldn't break the plugin though, apart from the issue you discovered where monsters will now be sorted in before or after a position depending on their original database ID.

    Modified the previous post for future reference.
    Glad to hear it worked. :)
     
    #6
    AdamantineOrichalcum likes this.

Share This Page