RMMV .isWTypeEquipped & .equips()[]

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,834
Reaction score
1,592
First Language
English
Primarily Uses
RMMV
I was wondering if it was possible to make a statement that checks if a certain equipment slot (such as .equips(1)[]) contains a certain weapon type equipped? Also, what's the script call to forcibly unequip something from a specific slot?
 
Last edited:

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Could you use a little more elaboration but I think this is what you want

JavaScript:
 $gameActors.actor(actorId).equips().forEach(function(e){

    if(e.isWtypeEquipped(ID OF WEAPON TYPE)){
     // do whatever
    }

})
and for your other question


$gameActors.actor(actorId).changeEquip(slotId, item);


just set the slot id to 0 to remove the equip
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,834
Reaction score
1,592
First Language
English
Primarily Uses
RMMV
JavaScript:
$gameActors.actor(actorId).equips().forEach(function(e){

    if(e.isWtypeEquipped(ID OF WEAPON TYPE)){
     // do whatever
    }

})
If I only want it to check slot 1, would it look like this?...
JavaScript:
$gameActors.actor(actorId).equips()[1]{

    if(e.isWtypeEquipped(ID OF WEAPON TYPE)){
     // do whatever
    }

})
Edit: No wait, that's not right...I need to retain "function(e)" don't I? But I don't want it to check the whole array (aka "forEach"), just a single slot.
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
The first slot would be 0, and if you only want to check the first slot then you can do something like

JavaScript:
var e = $gameActors.actor(actorId).equips()[0]

if (e.isWtypeEquipped(ID OF WEAPON TYPE)) {

    // do whatever

}
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,222
Reaction score
1,630
First Language
EN
Primarily Uses
RMMZ
isWTypeEquipped is a method of Game_Actor that loops through that actor's equipped weapons and checks each of them for the specified weapon type:
JavaScript:
Game_Actor.prototype.isWtypeEquipped = function(wtypeId) {
    return this.weapons().some(function(weapon) {
        return weapon.wtypeId === wtypeId;
    });
};
In this case it sounds like you just want to check one weapon: you can use something like this in a scripted if or via Conditional Branch > Script, e.g.
JavaScript:
var w = $gameActors.actor(1).weapons()[0]; w ? w.wtypeId === 5 : false
I.e. "let w equal actor 1's first weapon; if the weapon exists, return true iff it is of type 5, else return false". You can reference weapon types via the Types tab in the database.

For changing equipment, note that changeEquip expects item arguments; 0 works here because JavaScript treats it as falsy, but the standard "empty slot object" used in the core scripts is null. An alternative is changeEquipById:
JavaScript:
$gameActors.actor(1).changeEquipById(1, 0);
I.e. "equip item ID 0 (i.e. null) in equip slot 1 (first type, by default a weapon)". You can reference equipment types via the Types tab in the Database.
 

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

Latest Threads

Latest Profile Posts



Guess what's next...
How you feel about font and dialogue box changing for every main character while the minor cast and regular npc get their own styles? Too much?
Just found an obviously custom effect (i.e. edited by me) in my resources>sounds folder called "rip jaw off". Dear Lord what is wrong with me as a person that at some point I needed a sound *specifically* for THAT??
(...rhetorical question.)
so like with the whole 'familiarity breeds contempt thingy', how are you supposed to tell if your title screen/battle music gets really tedious after a few dozen plays or if you're just personally hella sick of it?
YAY!!! My third help Guide STEAM integration in MV (High performance) has been posted!

Forum statistics

Threads
107,520
Messages
1,030,229
Members
139,644
Latest member
five88uytin1
Top