Status
Not open for further replies.

Kitdan7

Villager
Member
Joined
Dec 29, 2018
Messages
16
Reaction score
4
First Language
English
Primarily Uses
RMMV
OK, I tried my best to figure this out, but I don't have the mental energy to search any more.

I want the option for players to change clothes, but I don't want them to be able to go without clothes. Is there a way, whether command script or plugin, that I can prevent the "Body" slot from being unequipped without locking what's equipped there? I'd settle for an event trick to force equip random or optimized valid clothes (preferably optimized) if they're not wearing anything.
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
668
Reaction score
382
First Language
English
Primarily Uses
RMMV
You can give this a Plugin a try, if you'd like. Make sure to save it as "PreventBlankEquip.js" or download the file attached to this post:

Code:
/*:
* @plugindesc This plugin allows users to specify equipment slots on an Actor that cannot be unequipped
* in a way that would leave them empty.
* @author Zevia
*
* @help If the option to prevent all actors from unequipping items without replacing
* them is true, then this Plugin does not require any further configuration and no
* Actor will be able to unequip an item without replacing it.
* If the option is false, then within an Actor's note box, you can specify which
* slot IDs should not be unequippable without a replacement. By default, the
* slots are:
* 0: Weapon
* 1: Shield
* 2: Head
* 3: Body
* 4: Accessory
*
* So, if you wanted an Actor to always require an item in the Body slot, you would
* put <preventBlankEquip: 3>. You can prevent multiple slots by comma-separating
* each slot ID. If you want to prevent unequipping without replacements for the
* weapon and shield slot, you would put <preventBlankEquip: 0, 1>
*
* If the Prevent All Actors & Slots option is true, then the clear command will be
* removed from the equip menu.
*
* @param shouldPreventAll
* @text Prevent All Actors & Slots
* @type boolean
* @desc Whether every Actor should be unable to unequip an item without a replacement for all equipment slots.
* @default false
*/

(function(module) {
    'use strict';

    module.Zevia = module.Zevia || {};
    var PreventBlankEquip = module.Zevia.PreventBlankEquip = {};
    var shouldPreventAll = !!PluginManager.parameters('PreventBlankEquip').shouldPreventAll.match(/true/i);

    PreventBlankEquip.shouldPreventEquip = function(actor, slotId) {
        if (shouldPreventAll) { return true; }

        var meta = $dataActors[actor._actorId].meta.preventBlankEquip;
        if (!meta) { return false; }

        var slotIds = meta.match(/\d+/g);
        if (!slotIds || !slotIds.length) { return false; }

        return slotIds.indexOf('' + slotId) !== -1;
    };

    PreventBlankEquip.onItemOk = Scene_Equip.prototype.onItemOk;
    Scene_Equip.prototype.onItemOk = function() {
        if (this._itemWindow.item() || !PreventBlankEquip.shouldPreventEquip(this._actor, this._slotWindow.index())) {
            PreventBlankEquip.onItemOk.call(this);
            return;
        }

        SoundManager.playBuzzer();
        this._itemWindow.activate();
    };

    PreventBlankEquip.clearEquipments = Game_Actor.prototype.clearEquipments;
    Game_Actor.prototype.clearEquipments = function() {
        var maxSlots = this.equipSlots().length;
        for (var i = 0; i < maxSlots; i++) {
            if (this.isEquipChangeOk(i) && !PreventBlankEquip.shouldPreventEquip(this, i)) {
                this.changeEquip(i, null);
            }
        }
    };

    PreventBlankEquip.makeCommandList = Window_EquipCommand.prototype.makeCommandList;
    Window_EquipCommand.prototype.makeCommandList = function() {
        if (!shouldPreventAll) {
            PreventBlankEquip.makeCommandList.call(this);
            return;
        }

        this.addCommand(TextManager.equip2, 'equip');
        this.addCommand(TextManager.optimize, 'optimize');
    };
})(window);

There's one configurable parameter, and that's whether or not you want to prevent all Actors from unequipping any slot without having a replacement item or not. By default, it's false, but you can set it to true if you want to just blanket prevent everyone from having blank slots.

If it is false, then you can put notetags in Actors' note boxes with the format <preventBlankEquip: x, y, z...>, where x, y, z, etc. are slot IDs you want to prevent a user from changing to a blank equip. As an example, if you want to prevent an Actor from unequipping the Body slot without replacing the item, you would do:
Code:
<preventBlankEquip: 3>

You'll still be able to force the item slots to be empty through event commands, however. This Plugin will only prevent the user from unequipping an item via the Equip Scene.
 

Attachments

  • PreventBlankEquip.js
    3.1 KB · Views: 16
Last edited:

TWings

The Dragon Whisperer
Veteran
Joined
Jul 26, 2017
Messages
528
Reaction score
867
First Language
French
Primarily Uses
RMMV
Alternatively, Yanfly Equip Core can do it too.
 

Kitdan7

Villager
Member
Joined
Dec 29, 2018
Messages
16
Reaction score
4
First Language
English
Primarily Uses
RMMV
You can give this a Plugin a try, if you'd like. Make sure to save it as "PreventBlankEquip.js" or download the file attached to this post:

It almost works. Unfortunately it doesnt prevent unequipping with the "Clear" button on the equip screen.

Alternatively, Yanfly Equip Core can do it too.

I didn't know Yanfly Equip Core could do that. I sort of just lazily glossed over the plugin in my search because the reliability of Yanfly Cores is spotty at best for me (I think there's a conflict with one of my other plugins, not sure which one) but this one seems to work fine, and it doesn't have the glitch that Zevia's suggestion has. Thanks for the help! (now if only I could use any core that effects how battles look or work)
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
668
Reaction score
382
First Language
English
Primarily Uses
RMMV
It almost works. Unfortunately it doesnt prevent unequipping with the "Clear" button on the equip screen.

...the reliability of Yanfly Cores is spotty at best for me...

If you were still interested in using the one I wrote, I modified it and updated my previous post to prevent the clear command from unequipping slots specified in Actor notetags. If the "Prevent All Actors & Slots" configuration is true, then the clear command is removed from the Equip menu.
 

Kitdan7

Villager
Member
Joined
Dec 29, 2018
Messages
16
Reaction score
4
First Language
English
Primarily Uses
RMMV
Thanks, but Yanfly Equip Core is working, and it comes with other features for me to explore too. This thread is resolved.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,949
Reaction score
5,857
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Today's my first login since Jan 2020. Time sure flies. Sorry to everyone's messages i missed.
It's satisfying to master the usage of a hard plugin, then making it do what you want. ( o w o)!!
I'll be redesigning some of the main characters from my many wip stories :kaohi:
gWBWMzT.jpg

Starting with the (chronologically) first of them, Cedric!
gotta love when a plugin you thought had nothing to do with why something else wasn't working winds up being the issue...
Doing RPG Maker News for 26th September 2021

Forum statistics

Threads
115,399
Messages
1,089,575
Members
150,139
Latest member
JamesZwei
Top