RMMV .isWTypeEquipped & .equips()[]

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,626
Reaction score
1,196
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,626
Reaction score
1,196
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,118
Reaction score
1,526
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

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top