If statement to check attack motion

I need an if statement that will check if the actor's attack motion is missile.
Where do you want to use it? In an Action Sequence, or somewhere else?


Didn't see the forum this was posted in, sorry.


It should be:


if (attackMotion.type === 2)


At least that's what is used in the Game_Actor.prototype.performAttack function of rpg_objects.js, with attackMotion defined as a variable there. (0 is thrust, 1 is swing, 2 is missile.) If you want to use the if statement somewhere else, you might need to do it differently.
I'm trying to use it in a plugin that edits the rpg_windows.js file.
I'll assume that you have the actor you want to check stored in a variable (or parameter) named "actor". (Otherwise, replace "actor" with "$gameActors.actor(ID)" - insert the ID of the actor you want to check.)


var weapons = actor.weapons();
var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
var attackMotion = $dataSystem.attackMotions[wtypeId];
if (attackMotion) {
if (attackMotion.type === 0) {
...
}
}


I haven't tried it, but it should work, I think.
Do I need ";" after "}"?
Only at the very end of the function, after the } that corresponds to the { that comes after ... = function()
Okay, thank you. I also want to make an entire plugin conditional based on this check. Is that possible?
With a bit of a workaround, yes - for every function, put your custom code into that if statement, then make an else block underneath and and call the original function in that else block.
What do you mean by original function? Sorry for being a noob...
The original function is the one provided by the rpg*.js file.


If you write plugins, you usually use aliases for the code you write, for example


var _Scene_Menu_createBackground = Scene_Menu.prototype.createBackground;
Scene_Menu.prototype.createBackground = function() {
//my code here
};


In this case, the original initSkills function is saved in the alias "_Scene_Menu_createBackground". You can call the original function by calling the alias:


_Scene_Menu_createBackground.call(this);


In the code I used for this example, I did something similar: if a custom menu background image is specified ("backgroundMenu" was defined somewhere above), use that image; otherwise draw the background normally. The whole function for that looked like this:

Code:
	var _Scene_Menu_createBackground = Scene_Menu.prototype.createBackground;
	Scene_Menu.prototype.createBackground = function() {
	    if (backgroundMenu) {                        // if background image is specified, draw it
	    	this._backgroundSprite = new Sprite();
	    	this._backgroundSprite.bitmap = ImageManager.loadPicture(backgroundMenu);
	    	this.addChild(this._backgroundSprite);
	    } else {                                     // if not:
	    	_Scene_Menu_createBackground.call(this); // call original function
	    }
	};
Ah, okay. That makes sense. I was confused because the function I'm trying to make conditional starts like this:


(function() {


It's View attachment VE_ThrowableObjects (2).js


At this point I might be asking you to do the work for me as opposed to just helping me out. If you don't want to, that's fine.


I essentially want the plugin "turned off" anytime an actor is using a weapon with any motion other than "missile". I figured making the entire plugin conditional for the missile motion would accomplish that.


I managed to get the first part of what I wanted done with the code you gave me. Thank you for that. But I'm hung up on this part.
I'm afraid that goes beyond the extend of my Javascript skills as well ... or it's just too late for me to think properly.


Anyway, what exactly do you want to achieve by "switching off" the plugin if an actor uses the missile motion?
It conflicts with YEP Battle Core Engine. I found a work around but it only works if I don't have any fancy Battle Action Sequences. I don't use Action Sequences for Bows and such, so that's not a problem. But if I add a sequence to, say, a sword, then the conflict is still an issue. If I can disable the plugin's functions for anything other than a missile motion weapon, then the conflict won't be an issue for those weapons. It's not perfect, but it does what I need it to.


Also, do I use !=== instead of === to check if it's not "missile"?
Second question first: "not equal to" would be written as !== (with only two "equals")


You'll probably have to either ask in Plugin Requests for a compatility patch or wait if someone more knowledgable than me come across this topic. I'd really like to help, but I haven't really started to understand what causes and what fixes compatibility problems between plugins, so I'm afraid I'm not much help here :|
Okay. You've still helped me a lot. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/if-statement-to-check-attack-motion.70213/