RMMV Yanfly's Action Sequences -- conditional movement

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
143
Reaction score
39
First Language
English
Primarily Uses
RMMV
I'm using Yanfly's Action Sequences, and I'm currently trying to put in a conditional script into one of the sequences.

The idea is: when you take the Attack action, the character moves up to the target to attack, UNLESS the attacker is using a crossbow type weapon. The crossbow's weapon type ID is 3, so I came up with this script:

Code:
<whole action>
if (a.weapons()[0].wtypeId : 0) != 3
  move user: target, front, 20
  wait for movement
end
</whole action>

I'm not getting something right, cause the action sequence is skipping everything between if-end no matter the weapon type. I also tried the following statements:

Code:
if ((a.weapons()[0].wtypeId : 0) != 3)
if (a.weapons()[0] ? a.weapons()[0].wtypeId : 0) != 3
if ((a.weapons()[0] ? a.weapons()[0].wtypeId : 0) != 3)

But I still can't get it right. I'm not sure what I'm getting wrong here, I'm still kind of an amateur coder.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,553
Reaction score
3,619
First Language
English
Primarily Uses
RMMV
I'm using Yanfly's Action Sequences, and I'm currently trying to put in a conditional script into one of the sequences.
You're doing a weird thing with a colon that isn't valid JavaScript syntax. I have no clue where you got it from.

Also, I'm not sure what led you to use a - that's for damage formulae. The instructions in Action Sequences say to use user

So do if (user.weapons()[0].wtypeId != 3)

I'm also not positive you want that in a whole action. The purpose of whole action is that in multi-target skills it gets resolved on each target simultaneously...so I have no idea how that's going to play out with you moving the actor.

For your stated purpose, there's a "default attack" action sequence written by Yanfly you can find in a bunch of posts and places.

Code:
<setup action>
display action
immortal: targets, true
if user.isActor() && user.attackMotion() != 'missile'
   motion walk: user
   move user: targets, front, 30
   wait for movement
end
if user.isActor() && user.attackMotion() == 'missile'
   perform start
   wait for movement
end
if !user.isActor()
   enemy effect: user, whiten
end
</setup action>

<target action>
if user.isActor()
   motion attack: user
   wait: 10
   attack animation: target
   wait for animation
end
if !user.isActor()
   wait: 10
   attack animation: target
   wait for animation
end
action effect
if !target.isActor()
   enemy effect: target, blink
end
wait: 10
</target action>

<follow action>
</follow action>

<finish action>
clear battle log
immortal: targets, false
if user.isActor() && user.attackMotion() != 'missile'
   motion walk: user
   move user: home, 20
   wait for movement
end
perform finish
wait for movement
</finish action>

That's what I have - I might have modified a couple of things from the default one Yanfly provided, but you can always look that up.
 
Last edited:

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
143
Reaction score
39
First Language
English
Primarily Uses
RMMV
I was using the same sort of code as used in the <Post-Damage Eval> tags, which I think comes from another Yanfly plugin, but I can't remember which one.

But your suggestion worked great! For some reason, enemies would also not move, but I just made a slight alteration. I ended up with this code:

Code:
if user.isActor() && user.weapons()[0].wtypeId == 3
else
  move user: target, front, 20
  wait for movement
end

This does everything that I need at the moment, so I don't think I need to use that whole Yanfly script, but I will save it for later in case something changes.

Thanks for the help!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,553
Reaction score
3,619
First Language
English
Primarily Uses
RMMV
I was using the same sort of code as used in the <Post-Damage Eval> tags, which I think comes from another Yanfly plugin, but I can't remember which one.
If you care, you can find what you were looking at and link to it, and I'll try to explain it - but I guarantee you that's not an exact copy of any functioning code.
For some reason, enemies would also not move
Well, the sequence was designed for sv actors against the standard static battlers, so it was intentional to not have the enemy battlers sliding around the screen.
Code:
if user.isActor() && user.weapons()[0].wtypeId == 3
else
  move user: target, front, 20
  wait for movement
end
For the purposes of your action sequence, this will do what you say you want.

For the purposes of you being an amateur coder, this is not good practice, because if it were JavaScript and not an action sequence, it wouldn't work correctly.

What you would do is correctly check for the conditions you do want. So if you want to move if it's either not using a ranged weapon or it's an enemy, you would do:
Code:
if !user.isActor() || user.attackMotion() != 'missile'

Notice how all the code I posted is checking the attackMotion instead of the weapon type? That's to make it more functional - it will apply to any weapon type that uses the ranged attack motion.

Whereas if you decide later you want to have both crossbows and longbows, for example, you would have to go back into your code and type out an additional condition for that new weapon type.
 

Latest Threads

Latest Profile Posts

DamageEvil_5.png added!
index.php

Rendering the intro for the 4 time today, everytime it finished I noticed something that I found off and had to fix it and render it all over again...
Would not be so bad if it was not for my PC having the speed of a slug.:kaoswt2:
Tried something. Little sneak peak of Unity AD.
M42S7Us.gif

It's the little things. Lengthened the time the bar fades in and out to be a bit more comfortable.

Forum statistics

Threads
125,739
Messages
1,173,126
Members
164,890
Latest member
bubblesloli
Top