RMMZ How do you determine and change Equip Slot Order?

Raith

Squire
Veteran
Joined
Oct 28, 2019
Messages
69
Reaction score
55
First Language
Indonesian
Primarily Uses
RMMZ
My project employs pseudo class-free gameplay, which limit the player to use various weapon based on equipped armor.
Hence, for the best user interface and experience, it requires the player to equip the armor first, then set the weapon, shield, and finally accesorries.

Because of that, I'm trying to change the Equip Slot order in the scene menu:

from Weapon - Shield - Armor - Accessories

to Armor - Weapon - Shield - Accessories

However, I'm not certain on how the Equip Slot is being drawn in Scene Equip. I'm already trying to mod everything in Window_EquipSlot with no luck.

The only clue I have is that in the Window_EquipSlot parent, the Window_Selectable, there is "_index" property, which further determine the order of drawn slot based on Window_Selectable.prototype.drawAllItems and Window_EquipSlot.prototype.drawItem functions.

But that doesn't change the fact that I still can't reorder the Equip Slot.

Can someone give me some enlightenment, please?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,058
Reaction score
1,483
First Language
EN
Primarily Uses
RMMZ
Here I'll assume your equip types are defined, in order, as "Weapon", "Shield", "Armor", "Accessory".

Check out the Game_Actor.prototype.equipSlots method:
JavaScript:
Game_Actor.prototype.equipSlots = function() {
    const slots = [];
    for (let i = 1; i < $dataSystem.equipTypes.length; i++) {
        slots.push(i);
    }
    if (slots.length >= 2 && this.isDualWield()) {
        slots[1] = 1;
    }
    return slots;
};
Equip slots are numbered according to their order in the database, with 1 being treated as a Weapon slot and others as Armor slots. Slots are used to lookup names like "Weapon", "Accessory", etc, as well as limit which items are equippable to which slot. Default equip slots are [1, 2, 3, 4] ([1, 1, 3, 4] if dual-wielding).

With that in mind, you can make a new .js file with something like this in it (paste into a text editor, Save As > File Type: All Files, Filename: whatever.js) then import as a plugin, save your project, and test:
JavaScript:
Game_Actor.prototype.equipSlots = function() {
    const res = [3, 1, 2, 4, 4];  // armor, weapon, shield, acc, acc
    if (this.isDualWield()) res[2] = 1;  // replace shield with weapon if dual-wielding
    return res;
};
Doing this (rather than editing the core scripts directly) overrides the default method while still allowing you to easily turn it on/off, edit it mid-development, or upgrade your core scripts without removing your code changes.

Note that the example I've provided also demonstrates multiple slots assigned to a single equip type, in case you wanted that~
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,681
Reaction score
1,095
First Language
Portuguese - Br
Primarily Uses
RMMZ
@caethyril is right!
I also have a hard time figuring that out when I made a commission a time ago. I was searching on Window_EquipSlot and Scene_Equip until I found that the Game_Actor.equipSlots is also part of the system. Honestly, I don't know why the Game_actor class holds this responsibility :(
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,058
Reaction score
1,483
First Language
EN
Primarily Uses
RMMZ
I also have a hard time figuring that out when I made a commission a time ago. I was searching on Window_EquipSlot and Scene_Equip until I found that the Game_Actor.equipSlots is also part of the system. Honestly, I don't know why the Game_actor class holds this responsibility :(
I think it makes sense to store equips and equip slots on the same object. :kaoswt:
 

Raith

Squire
Veteran
Joined
Oct 28, 2019
Messages
69
Reaction score
55
First Language
Indonesian
Primarily Uses
RMMZ
@caethyril Thank you! Your explanation made everything clear! I agree with @Eliaquim on the reason of why (even in MZ,) slot order information in the Eqip Scene is (still) totally held by Game_Actor, not by Scene_EquipSlot - well, current reason is probably for the sake of code flexibility since Makers may add a lot of armor subcategories.

And thanks to that, now I also know that reordering the item slot will also interfere the information stored in $gameParty.members()[ID].equips()[index].

So, if Makers decide to do equip slot reorder and call $gameParty.members()[ID].equips()[index] somewhere, they should also redefine the [index] too so it will match with the default order.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,058
Reaction score
1,483
First Language
EN
Primarily Uses
RMMZ
@caethyril Thank you! Your explanation made everything clear! I agree with @Eliaquim on the reason of why (even in MZ,) slot order information in the Eqip Scene is (still) totally held by Game_Actor, not by Scene_EquipSlot - well, current reason is probably for the sake of code flexibility since Makers may add a lot of armor subcategories.
Storing the equip slot info on a single scene would limit equip/unequip operations to that scene. However, even with the default code, actors can equip stuff on scenes other than Scene_Equip using the Change Equipment command. Equip slot names are referenced by multiple windows (Window_EquipSlot, Window_StatusBase, Window_ShopStatus, etc) on multiple scenes (Scene_Status, Scene_Shop, etc). Not to mention potential modifications (e.g. crafting scenes?). So I stand by my claim that it makes more sense to store equip slots on Game_Actor. :kaophew:

That said, you're welcome! Happy RPG Making~ :kaojoy:
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,681
Reaction score
1,095
First Language
Portuguese - Br
Primarily Uses
RMMZ
Storing the equip slot info on a single scene would limit equip/unequip operations to that scene. However, even with the default code, actors can equip stuff on scenes other than Scene_Equip using the Change Equipment command. Equip slot names are referenced by multiple windows (Window_EquipSlot, Window_StatusBase, Window_ShopStatus, etc) on multiple scenes (Scene_Status, Scene_Shop, etc). Not to mention potential modifications (e.g. crafting scenes?). So I stand by my claim that it makes more sense to store equip slots on Game_Actor. :kaophew:
I think that is okay to store equipment slots on Game_Actor, I mean the data of it, and because of the same reasons, you have explained.
But I believe that this should not be a factor that interferes with how the window will draw the slots. Unless there was a way by default to change the order of slots by the actor data too:
1600510654623.png
But after I found out that is the Game_Actor.prototype.equipSlots that will define the order in Window_EquipSlot, it is easy to change that for all actors or even for a different order per actor ^^
Guess this is a plugin idea for me now xD
 

Raith

Squire
Veteran
Joined
Oct 28, 2019
Messages
69
Reaction score
55
First Language
Indonesian
Primarily Uses
RMMZ
Equip slot names are referenced by multiple windows (Window_EquipSlot, Window_StatusBase, Window_ShopStatus, etc) on multiple scenes (Scene_Status, Scene_Shop, etc). Not to mention potential modifications (e.g. crafting scenes?).
This is exactly the reason on why I'm stuck for days, looking the function responsible in drawing equip slot order for each scene, hoping that it is not located in a vital parent function for easy and safe modding.

I'm really hesitated with messing something inside rmmz_objects. In this case, because once you mess with that order in Game_Actor.prototype.equipSlots, everything else referencing it will adapt to the change - and as I suspected, by modifying only that, the default Change Equipment event command is now not working at all.

I guess there is something else that need to be modified.

EDIT: it turned out that by doing the slot reorder through Game_Actor.prototype.equipSlots, you must redefine "slotId" to make everything else work by default. The standard engine recognize this slotId value as 0 = weapon, 1 = shield, 2 and onwards = armors. I'm not sure if we can modify those values at this point. So in short, if we only achieve equip slot reorder through modding Game_Actor.prototype.equipSlots, be ready for a very niche-specific plugin.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,058
Reaction score
1,483
First Language
EN
Primarily Uses
RMMZ
EDIT: it turned out that by doing the slot reorder through Game_Actor.prototype.equipSlots, you must redefine "slotId" to make everything else work by default. The standard engine recognize this slotId value as 0 = weapon, 1 = shield, 2 and onwards = armors. I'm not sure if we can modify those values at this point. So in short, if we only achieve equip slot reorder through modding Game_Actor.prototype.equipSlots, be ready for a very niche-specific plugin.
Whoops, yep, that'll happen. :kaoslp:
  • This equipSlots override remaps the database slots in-game;
  • The editor takes its values from the database types;
  • Plugins only affect the gameplay, not the editor.
I think the most elegant solution is to remap the command input before telling it to actually change the equipment, e.g. add something like this to the same file as the equipSlots override:
JavaScript:
// Change Equipment - override!
Game_Interpreter.prototype.command319 = function(params) {
    const actor = $gameActors.actor(params[0]);
    const slotMap = [3, 1, 2, 4, 4];  // your equip slot order
    if (actor) {
        actor.changeEquipById(slotMap[params[1] - 1], params[2]);
    }
    return true;
};
So now if the input slot ID is 1 (normally weapon) this would tell the game to call changeEquipById for slot 3 instead, because element (1 - 0) of slotMap is 3. Hope that helps! I'll add an "equip slot config" feature to my plugin ideas list, too~ :kaothx:

(Haven't tested it, so hopefully it works OK. :kaoswt2:)
 

Raith

Squire
Veteran
Joined
Oct 28, 2019
Messages
69
Reaction score
55
First Language
Indonesian
Primarily Uses
RMMZ
@caethyril I'd like to quote this:

  • Plugins only affect the gameplay, not the editor.
Since this little fella here:

JavaScript:
Game_Actor.prototype.equipSlots = function() {
    const slots = [3, 1, 2, 4]
    if (slots.length >= 2 && this.isDualWield()) {
        const shieldIndex = slots.indexOf(2);
        slots[shieldIndex] = 1;
    }
    return slots;
};
is affecting this event command like a dang disease, so it doesn't work at all, even under default [1,2,3,4] order:
command.PNG


Then thanks to your cure, by modifying it a little until it become this:

JavaScript:
Game_Interpreter.prototype.command319 = function(params) {
    const actor = $gameActors.actor(params[0]);
    const slotMap = [3, 1, 2, 4];  // your equip slot order
    const index = slotMap.indexOf(params[1]) + 1;
    if (actor) {
        actor.changeEquipById(index, params[2]);
    }
    return true;
};
The disease is gone!
Capture.PNGCapture1.PNGCapture2.PNG

I think the original params[1] works as etypeId, which add 1 into default value of 0(weapon), 1(shield), 2-onwards(armor). Hence the original [1,2,3,4] slot order is actually the etypeId.

By doing slotMap.indexOf(params[1]) + 1; you search the original etypeId value position inside the slotMap array, and store it in new "index" constant. In other words, you search the original equipment position based on the new slot order and call the new position as "index".

And finally, you execute it in changeEquipById(index, params[2]) which is actually changeEquipById(etypeId, itemId).

I guess it is all really clear now!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts


My only regret is the portal mirror effect is too subtle to show up in these GIFs. It probably just needs more sparkles. :LZSwink:
Microsoft: Hey, let's waste money advertising the Xbox Series X when nobody has any in stock, we don't seem to be making more, we aren't taking preorders and you can't get on a waiting list. BEST. IDEA. EVER.
So I'm practicing ITC with a spirit box, and decide to try to contact my deceased soulmate. It actually gave me multiple identifiers. Me, still a bit skeptical, asked aloud "Fine but does he still love me?" and the box spoke and printed the word "Forever" at the same time. Been a mess of tears since. :kaocry:
Been scratching away at my game and making progress, but just had a revelation. I'm working in full screen and adjusting all my pictures accordingly, but will they resize if someone's screen is smaller?? I hope this doesn't turn out to be a problem later.

Forum statistics

Threads
105,635
Messages
1,015,171
Members
137,309
Latest member
wagemuts
Top