Check if actor can equip aType/wType in eType slot SOLVED

Hello, I am almost done with my script that reorganizes eTypes upon class change as well as equips the previously worn items after the fact.

One problem I noticed is that if an actor can equip say, javelin in slot 3 eType 10, and then I change classes to a job that cannot equip javelin in slot 3 due to their eType being changed to type 9, the changeEquip function will attempt to equip the javelin anyways, and since the eType is not compatible, the javelin will be removed from inventory and seemingly sent to the void.

I want to fix this with a conditional check to instead replace the item to be equipped with a 0 or a best fit option instead. Pretty much all of this is handled, except for the conditional check to see if the new class can equip the previous item.

I can likely do this by checking this.actor().currentClass().id; and using this for the conditional, but I was wondering if there might be an easier way to go about this. I had thought isEquipChangeOk might work for this, but it seems it only checks to see if there is an equip slot available, rather than comparing it with an eType for compatibility.

Is there a way to modify this.actor().isEquipChangeOk(2) to do so? Or perhaps another function that can do this instead?

Maybe something like this?

this.actor().isEquipChangeOk(2).$dataWeapons[$gameVariables.value(83)]

JavaScript:
if (
    $gameVariables.value(83) !== 0 && this.actor().isEquipChangeOk(2))
{
this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
};
Hi there!

the changeEquip function will attempt to equip the javelin anyways, and since the eType is not compatible, the javelin will be removed from inventory and seemingly sent to the void.

By default, when changing classes, if the new class cannot equip the current equipment, that same equipment will be returned to the inventory. The code flow that shows that is the one below:

JavaScript:
Game_Actor.prototype.changeClass = function(classId, keepExp) {
    if (keepExp) {
        this._exp[classId] = this.currentExp();
    }
    this._classId = classId;
    this.changeExp(this._exp[this._classId] || 0, false);
    this.refresh();
};

Game_Actor.prototype.refresh = function() {
    this.releaseUnequippableItems(false);
    Game_Battler.prototype.refresh.call(this);
};

Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
    for (;;) {
        var slots = this.equipSlots();
        var equips = this.equips();
        var changed = false;
        for (var i = 0; i < equips.length; i++) {
            var item = equips[i];
            if (item && (!this.canEquip(item) || item.etypeId !== slots[i])) {
                if (!forcing) {
                    this.tradeItemWithParty(null, item);
                }
                this._equips[i].setObject(null);
                changed = true;
            }
        }
        if (!changed) {
            break;
        }
    }
};

Game_Actor.prototype.tradeItemWithParty = function(newItem, oldItem) {
    if (newItem && !$gameParty.hasItem(newItem)) {
        return false;
    } else {
        $gameParty.gainItem(oldItem, 1);
        $gameParty.loseItem(newItem, 1);
        return true;
    }
};

So I guess, the thing is, how are you changing that class. By using the default RPG Maker function, it should work as you want.

The only thing is, that instead of equipping another piece of equipment, it will leave it empty.
Theoretically, to not leave it empty, you could just call a function to optimize the actor equipment after changing class:
JavaScript:
$gameActors.actor(ID).optimizeEquipments()

So maybe the thing here is, how are you changing the actor class?
I just tested changeEquip in isolation via an in game event. The item will disappear into the void when it is attempted to be equipped into an invalid eType slot. This occurs regardless of how class is changed and independently from class change, as well as any other features, addons, plugins, etc. So the default functions that prevent item deletion are only specific to aType and wType mismatches, not eTypes.


Think I finally got it. Should have just gone with the original plan and used classes to determine if the wType can fit the eType in a specific slot.

Code:
this._lastClass = this.actor().currentClass().id;
this._lastSubClass = this.actor().currentClass().id;
//////
if (this.actor().equips()[2])
{
$gameVariables.setValue(83, this.actor().equips()[2].id);
$gameVariables.setValue(93, this.actor().equips()[2].etypeId);
this.actor().changeEquip(2, $dataWeapons[0]);
}
else
{
$gameVariables.setValue(83, 0);
$gameVariables.setValue(93, 0);
};
//////
this._currentClass = this.actor().currentClass().id;
this._currentSubClass = this.actor().currentClass().id;
//////
if (this._currentClass || this._currentSubClass == this._lastClass || this._lastSubClass)
{
this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
};
//////
if (this.actor().equips()[2] == null)
{
this.actor().changeEquip(2, this.actor().bestEquipItem(2));
};

That was easy, damn.

Oh wait, I still need to add an additional case where the class check if case only passes a true when class/subclass 13 = 13, 14 = 14, 19 = 19, 20 = 20, 24 = 24, 26 = 26, or 34 = 34 while associating each class with another if condition that only passes true if the proper wType is equipped while the correct class/subclass is active.

Something like this:
JavaScript:
if (this.actor().equips()[2])
{
$gameVariables.setValue(83, this.actor().equips()[2].id);
$gameVariables.setValue(93, this.actor().equips()[2].etypeId);
$gameVariables.setValue(103, this.actor().equips()[2].wtypeId);
this.actor().changeEquip(2, $dataWeapons[0]);
}
else
{
$gameVariables.setValue(83, 0);
$gameVariables.setValue(93, 0);
$gameVariables.setValue(103, 0);
};   



//if (this._currentClass || this._currentSubClass == this._lastClass || this._lastSubClass)
if (this._currentClass == this._lastClass || this._currentSubClass == this._lastClass || this._currentClass==this._lastSubClass || this._currentSubClass == this._lastSubClass)
{
    
//            if (this._currentClass || this._currentSubClass == 5)
            if (this._currentClass == 5 || this._currentSubClass == 5)
    {
//        if ($gameVariables.value(103) == 141 || 142 || 143 || 144 || 145 || 146 || 147 || 148 || 149 || 150)
        if ($gameVariables.value(103)>=141 && $gameVariables.value(103)<=150)
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }
    
    
//            if (this._currentClass || this._currentSubClass == 13)
            if (this._currentClass == 13 || this._currentSubClass == 13)
    {
        //if ($gameVariables.value(103) == 151 || 152 || 153 || 154 || 155 || 156 || 157 || 158 || 159 || 160 || 161 || 162 || 163 || 164 || 165 || 166 || 167 || 168 || 169 || 170)
        if ($gameVariables.value(103)>=151 && $gameVariables.value(103)<=170)    
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }
    
            //if (this._currentClass || this._currentSubClass == 14)
            if (this._currentClass == 14 || this._currentSubClass == 14)
    {
        //if ($gameVariables.value(103) == 131 || 132 || 133 || 134 || 135 || 136 || 137 || 138 || 139 || 140)
        if ($gameVariables.value(103)>=131 && $gameVariables.value(103)<=140)    
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }
    
            //if (this._currentClass || this._currentSubClass == 19)
            if (this._currentClass == 19 || this._currentSubClass == 19)
    {
        //if ($gameVariables.value(103) == 271 || 272 || 273 || 274 || 275 || 276 || 277 || 278 || 279 || 280 || 251 || 252 || 253 || 254 || 255 || 256 || 257 || 258 || 259 || 260)
        if ($gameVariables.value(103)>=271 && $gameVariables.value(103)<=280 || $gameVariables.value(103)>=251 && $gameVariables.value(103)<=260)    //double check me (koda)
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }
    
    
            //if (this._currentClass || this._currentSubClass == 20)
            if (this._currentClass == 20 || this._currentSubClass == 20)
    {
        //if ($gameVariables.value(103) == 181 || 182 || 183 || 184 || 185 || 186 || 187 || 188 || 189 || 190)
        if ($gameVariables.value(103)>=181 && $gameVariables.value(103)<=190)    
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }
    
            //if (this._currentClass || this._currentSubClass == 24)
            if (this._currentClass == 24 || this._currentSubClass == 24)
    {
        //if ($gameVariables.value(103) == 221 || 222 || 223 || 224 || 225 || 226 || 227 || 228 || 229 || 230 || 261 || 262 || 263 || 264 || 265 || 266 || 267 || 268 || 269 || 270)
        if ($gameVariables.value(103)>=221 && $gameVariables.value(103)<=230 || $gameVariables.value(103)>=261 && $gameVariables.value(103)<=270)    //double check me (koda)
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }    
    
            //if (this._currentClass || this._currentSubClass == 26)
            if (this._currentClass == 26 || this._currentSubClass == 26)
    {
        //if ($gameVariables.value(103) == 31 || 32 || 33 || 34 || 35 || 36 || 37 || 38 || 39 || 40 || 171 || 172 || 173 || 174 || 175 || 176 || 177 || 178 || 179 || 180)
        if ($gameVariables.value(103)>=31 && $gameVariables.value(103)<=40 || $gameVariables.value(103)>=171 && $gameVariables.value(103)<=180)    //double check me (koda)
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }                
    

            //if (this._currentClass || this._currentSubClass == 34)
            if (this._currentClass == 34 || this._currentSubClass == 34)    
    {
        //if ($gameVariables.value(103) == 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10)
        if ($gameVariables.value(103)>=1 && $gameVariables.value(103)<=10)    
        {
            if ($gameVariables.value(93) == 1) 
            {
            this.actor().changeEquip(2, $dataWeapons[$gameVariables.value(83)]);
            }
            else if ($gameVariables.value(93) !== 1) 
            {
            this.actor().changeEquip(2, $dataArmors[$gameVariables.value(83)]);
            }
    
    
        }
    
    }    
};

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.

Original thread: https://forums.rpgmakerweb.com/threads/check-if-actor-can-equip-atype-wtype-in-etype-slot-solved.166673/