If statement to check attack motion

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
I need an if statement that will check if the actor's attack motion is missile.
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
I'm trying to use it in a plugin that edits the rpg_windows.js file.
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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.
 

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
Do I need ";" after "}"?
 
Last edited by a moderator:

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
Only at the very end of the function, after the } that corresponds to the { that comes after ... = function()
 

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
Okay, thank you. I also want to make an entire plugin conditional based on this check. Is that possible?
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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.
 

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
What do you mean by original function? Sorry for being a noob...
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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
	    }
	};
 

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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?
 

Michael Caiola

The Stone Bull
Veteran
Joined
Sep 14, 2016
Messages
392
Reaction score
76
First Language
English
Primarily Uses
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"?
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
645
Reaction score
524
First Language
German
Primarily Uses
RMMV
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 :|
 

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

Latest Threads

Latest Posts

Latest Profile Posts

He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top