Conditional Branch for Weapon type.

Hello, I found the following line to check for the weapon type currently equipped by the actor:


$gameActors.actor(1)._equips[0].itemId() == 2


Can someone explain me how this works? I can't get it to work in a conditional branch as a script.


I reckon actor is the character, and starts from 0 or 1?


Equips[0] stands for weapons, I reckon? (and allows to set shield, head, body, accessoires)


ItemID is the weapon type ID? Does it start from 0 or 1?


Thank you in advance.
$gameActors is the database data of your actor.


actor(1) takes the first actor in the database. The one with the number 1.


_equips[0] is slot 0 of the character's equips. this one, as far as I know, is the primary weapon.


itemId() gives as an answer the value of the item's id. for 2, it would be the second weapon in the database.


Javascript has both == and === for comparison though. The one like other languages is ===. So, you may be missing an =.


But... why a script? The Conditional Branch has the option to check if said actor is with said weapon already...
$gameActors is the database data of your actor.


actor(1) takes the first actor in the database. The one with the number 1.


_equips[0] is slot 0 of the character's equips. this one, as far as I know, is the primary weapon.


itemId() gives as an answer the value of the item's id. for 2, it would be the second weapon in the database.


Javascript has both == and === for comparison though. The one like other languages is ===. So, you may be missing an =.


But... why a script? The Conditional Branch has the option to check if said actor is with said weapon already...



Thank you for your help. I'm trying to look if a certain weapon type id is equipped by the actor. Isn't that line supposed to do that, or it only checks the weapon id?
no, that checks the weapon's id. That is, it's number on the database.


do you want the weapon's type id or if the type id is equipped? because the earlier I think is is 


$gameActors.actor(1)._equips[0].wtypeId === 2


 while the later is 


$gameActors.actor(1)._equips[0].isWtypeEquipped(2)


Check them out, I didn't test yet but I think it is right.
no, that checks the weapon's id. That is, it's number on the database.


do you want the weapon's type id or if the type id is equipped? because the earlier I think is is 


$gameActors.actor(1)._equips[0].wtypeId === 2


 while the later is 


$gameActors.actor(1)._equips[0].isWtypeEquipped(2)


Check them out, I didn't test yet but I think it is right.



Thank you again, but unfortunately it doesn't work. I tested the second line, to check if a certain weapon type id is equipped by the actor.


It gives me the following error: undefined is not a function
Aha! It does however seem to work when I use:


$gameActors.actor(1).isWtypeEquipped(2)


Is the equips[0] part necessary?
hmm... let me see here.


[Edit] Sorry, try  $gameActors.actor(1).isWtypeEquipped(2)
hmm... let me see here.


[Edit] Sorry, try  $gameActors.actor(1).isWtypeEquipped(2)



Thanks a lot. I would have never been able to figure this out 🙂


Saves me a lot of time, having to switch the battle sprite for every weapon (there are 300 weapons, and only 10 weapon types).
Oh, I did this in my game too. One battle sprite each weapon the battler has equipped, right?


I made this plugin for me. Basically, it works for all characters instead of you choosing which it works for, you have to make battle sprites of them for ALL weapon types they can equip, so it is not good enough to be shared yet, but since you had the same idea you can use it and adapt...


Here, every battle sprite but unnarmed is named the original sprite+number. for example, hero unnarmed's battle sprite is named hero. with sword is hero1, with claws is hero2, with knife is hero3...

Code:
Sprite_Actor.prototype.updateBitmap = function() {
    Sprite_Battler.prototype.updateBitmap.call(this);
    var name = this._actor.battlerName();
    var weapon = this._actor.weapons();
    var weapontid = 0;
    weapon.forEach(function(weapon) {
        if (weapon.wtypeId > 0) weapontid = weapon.wtypeId;
    });
    if (weapontid > 0) {
    	name = name + String(weapontid);
    }
    if (this._battlerName !== name) {
        this._battlerName = name;
        this._mainSprite.bitmap = ImageManager.loadSvActor(name);
    }
};
Oh, I did this in my game too. One battle sprite each weapon the battler has equipped, right?


I made this plugin for me. Basically, it works for all characters instead of you choosing which it works for, you have to make battle sprites of them for ALL weapon types they can equip, so it is not good enough to be shared yet, but since you had the same idea you can use it and adapt...


Here, every battle sprite but unnarmed is named the original sprite+number. for example, hero unnarmed's battle sprite is named hero. with sword is hero1, with claws is hero2, with knife is hero3...



Sprite_Actor.prototype.updateBitmap = function() {
Sprite_Battler.prototype.updateBitmap.call(this);
var name = this._actor.battlerName();
var weapon = this._actor.weapons();
var weapontid = 0;
weapon.forEach(function(weapon) {
if (weapon.wtypeId > 0) weapontid = weapon.wtypeId;
});
if (weapontid > 0) {
name = name + String(weapontid);
}
if (this._battlerName !== name) {
this._battlerName = name;
this._mainSprite.bitmap = ImageManager.loadSvActor(name);
}
};



That's epic. Thanks a lot for sharing it with me!
No problem. Hope it helps. ^_^

Original thread: https://forums.rpgmakerweb.com/threads/conditional-branch-for-weapon-type.69118/