For a plugin I'm currently trying to make, I've stored a weapon into a variable (let's call it w). Given the weapon w and a wtypeId, how do I check that the weapon is that weapon type?
I've looked up other answers to this, but the predominant assumption seems to be that you're checking an actor's weapons, rather than a specific weapon stored in a variable.
I attempted the console.log thing with the appropriate javascript variables, but it just redirected me to the lines that called console.log when I looked at them. I suppose I should've made it clear it wasn't a game variable but rather a javascript variable I'm using to store the weapon.
This variable is being stored for each Game_Actor. I know there's a possible plan B in the making there, but I want to know if it's possible to do the comparison directly.
Huh could you show me the lines of code?
For simplicity I put the calls in a plugin command that was already used in a chest event I had going for testing, which is shown below:
if (command.toLowerCase() === "showactiveweapon") {
var actorId = Number(args[0]);
$gameMessage.add(`${$dataActors[actorId].name}'s active weapon is currently ${$gameActors.actor(actorId).activeWeapon.name}.`);
console.log($gameVariables.value($gameActors.actor(actorId).activeWeapon));
console.log($gameVariables.value($gameActors.actor(actorId)));
}
The variable's added in with an alias on the game actor initial members constructor, and the initialization of it works similarly to equipment optimization, except it's with only the weapons the actor has equipped. (So if you put an attack 15 sword first and then an attack 25 hammer second, the hammer will be the active weapon--and it'll be visually used for attacking too!) I know the initialization works thanks to that same plugin command above.
My end goal here is to get to where I can have skills that require an equipped weapon type that's not the active weapon to automatically switch the active weapon to the required weapon type. So, you know, you never get a character using a skill that should involve a weapon without a weapon in their hands.
Thankfully I have a solid grasp of what to edit... it's just this one part that's tripping me up at the moment.
Well, boy am I glad to know just enough to catch that typo there. It should be $gameActors, but that otherwise worked perfectly for bringing up that info. Now to dredge through it to find what I need.
Nice job catching that. Good luck dredging.
Did some digging and realized what needed to be done here was handling of null values, particularly for the ActiveOffhand variable. (Yes I do plan to eventually implement dual weapon wielding support.)
It was basically as simple as doing this.activeWeapon.wtypeId, except that throws an error if activeWeapon is null, which took me forever to figure out. My code's definitely gonna be better for it though.