Dual Wield: Show Off-Hand Weapon when attacking

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
Is it possible to temporarily just show the swing/missile/thrust weapon animations of the actor's Off-Hand weapon instead of their Main-Hand weapon when dual wielding? I'm using Yanfly's Weapon Animations if this helps at all.

Edit: I think the line below is what I need to use by I'm not sure how to implement it:
user.attackAnimationId1()

Maybe: user.attackAnimationId1() = 0? Any help would be appreciated.
 
Last edited:

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
Thanks for the reply but all I need is potentially one line of code. His plugin would be overkill for what I'm trying to do.
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
Hmm, close but that's not quite it. I need a line of code that will allow me to only show the user's second equipped weapon when they attack. I'm sure it's simple and I'm certain it can be done but I just need to find out what it is. I've even look at lines in dual wielding scripts(and attempted to modify them) to get the specific line of code I need but no luck yet.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,401
Reaction score
880
First Language
EN
Primarily Uses
RMMV
It's probably possible but would likely look very ugly in the action sequence without a plugin to abbreviate it to a single function call. For reference, here's performAttack from the base code, which handles the user motion and weapon sprite display:
Code:
Game_Actor.prototype.performAttack = function() {
    var weapons = this.weapons();
    var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
    var attackMotion = $dataSystem.attackMotions[wtypeId];
    if (attackMotion) {
        if (attackMotion.type === 0) {
            this.requestMotion('thrust');
        } else if (attackMotion.type === 1) {
            this.requestMotion('swing');
        } else if (attackMotion.type === 2) {
            this.requestMotion('missile');
        }
        this.startWeaponAnimation(attackMotion.weaponImageId);
    }
};
I think you'd basically just need to invoke this code, except reference weapons[1] (second weapon) instead.
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
It's probably possible but would likely look very ugly in the action sequence without a plugin to abbreviate it to a single function call. For reference, here's performAttack from the base code, which handles the user motion and weapon sprite display:
Code:
Game_Actor.prototype.performAttack = function() {
    var weapons = this.weapons();
    var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
    var attackMotion = $dataSystem.attackMotions[wtypeId];
    if (attackMotion) {
        if (attackMotion.type === 0) {
            this.requestMotion('thrust');
        } else if (attackMotion.type === 1) {
            this.requestMotion('swing');
        } else if (attackMotion.type === 2) {
            this.requestMotion('missile');
        }
        this.startWeaponAnimation(attackMotion.weaponImageId);
    }
};
I think you'd basically just need to invoke this code, except reference weapons[1] (second weapon) instead.
Thanks a lot! I'm going to fool around with this and see if I can come up with something but any more help into breaking it down to a function call would be appreciated. I almost have a unique dual wielding setup for my game. I'm so close!

Also where exactly did you find that line of code? Perhaps I can modify the code so that when a particular state is applied to the user(which would be applied when the actor is getting ready to use their second weapon) it will use "weapons[1] (second weapon)" instead.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,401
Reaction score
880
First Language
EN
Primarily Uses
RMMV
I found the code in rpg_objects.js. That said, editing the base code files is generally inadvisable. Better to write edits as plugins instead...that way it's easier to keep track of edits, you can turn them on/off at will, updates are less likely to mess things up, etc. :kaophew:

With that in mind, you could try saving this as a .js file (Save As > File Type: All Files, Filename: whatever.js) and import it like a plugin:
Code:
Game_Actor.prototype.performAttackOffhand = function() {
    var weapons = this.weapons();
    var wtypeId = weapons[1] ? weapons[1].wtypeId : 0;
    var attackMotion = $dataSystem.attackMotions[wtypeId];
    if (attackMotion) {
        if (attackMotion.type === 0) {
            this.requestMotion('thrust');
        } else if (attackMotion.type === 1) {
            this.requestMotion('swing');
        } else if (attackMotion.type === 2) {
            this.requestMotion('missile');
        }
        this.startWeaponAnimation(attackMotion.weaponImageId);
    }
};
Then in an action sequence, try something like this:
Code:
eval: user.performAttackOffhand();
Note: I haven't tried any of this myself, hopefully I haven't missed anything important. :kaoswt:

Basically, the plugin thing should add a new method called performAttackOffhand, identical to performAttack except it checks the second equipped weapon rather than the first. (I think performAttack is called as part of Yanfly's perform action action.) Then the eval action (Action Sequence Pack 1) can be used to call that new method. :kaopride:
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
I found the code in rpg_objects.js. That said, editing the base code files is generally inadvisable. Better to write edits as plugins instead...that way it's easier to keep track of edits, you can turn them on/off at will, updates are less likely to mess things up, etc. :kaophew:

With that in mind, you could try saving this as a .js file (Save As > File Type: All Files, Filename: whatever.js) and import it like a plugin:
Code:
Game_Actor.prototype.performAttackOffhand = function() {
    var weapons = this.weapons();
    var wtypeId = weapons[1] ? weapons[1].wtypeId : 0;
    var attackMotion = $dataSystem.attackMotions[wtypeId];
    if (attackMotion) {
        if (attackMotion.type === 0) {
            this.requestMotion('thrust');
        } else if (attackMotion.type === 1) {
            this.requestMotion('swing');
        } else if (attackMotion.type === 2) {
            this.requestMotion('missile');
        }
        this.startWeaponAnimation(attackMotion.weaponImageId);
    }
};
Then in an action sequence, try something like this:
Code:
eval: user.performAttackOffhand();
Note: I haven't tried any of this myself, hopefully I haven't missed anything important. :kaoswt:

Basically, the plugin thing should add a new method called performAttackOffhand, identical to performAttack except it checks the second equipped weapon rather than the first. (I think performAttack is called as part of Yanfly's perform action action.) Then the eval action (Action Sequence Pack 1) can be used to call that new method. :kaopride:
Hmm, I tried it but this line: user.performAttackOffhand();, only makes them swing with the first equipped weapon. I even moved the plugin around and disabled another dual wield plugin but no luck.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,401
Reaction score
880
First Language
EN
Primarily Uses
RMMV
OK I just tested and it works fine for me; plugins Battle Engine Core, Action Sequence Pack 1, and this little performAttackOffhand thing, loaded in that order. Here's my "Offhand Attack" skill action sequence, for reference:
Code:
<target action>
wait for movement
eval: user.performAttackOffhand();
motion wait: user
action effect: target
action animation: target
wait: 10
</target action>
Check you're using different weapons in each hand and remember that battle test does not necessarily use the actors' starting equipment. Save before testing, too, otherwise any plugin changes since you last saved will be ignored. Press F8 during test to show the console, if there are any errors, the messages will display in red text in the console window. :)
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
OK I just tested and it works fine for me; plugins Battle Engine Core, Action Sequence Pack 1, and this little performAttackOffhand thing, loaded in that order. Here's my "Offhand Attack" skill action sequence, for reference:
Code:
<target action>
wait for movement
eval: user.performAttackOffhand();
motion wait: user
action effect: target
action animation: target
wait: 10
</target action>
Check you're using different weapons in each hand and remember that battle test does not necessarily use the actors' starting equipment. Save before testing, too, otherwise any plugin changes since you last saved will be ignored. Press F8 during test to show the console, if there are any errors, the messages will display in red text in the console window. :)
Sorry for the super late reply(I haven't had a chance to test things out until now) but it still doesn't work for me. I think it may be due to Yanfly's Weapon Animation plugin that I have installed. There really isn't any way of getting around this plugin because it's crucial for my game. Maybe there's a way the plugin can be modified to fit my needs.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,401
Reaction score
880
First Language
EN
Primarily Uses
RMMV
Oh I see, the <Weapon Image: x> notetag seems to affect all equipped weapons simultaneously...I should've checked that earlier. I think the necessary edit/rewrite to enable the behaviour you want is a bit beyond me at present, sorry. :kaoslp:

It seems there's an older, deprecated version of Ramza's plugin called True Dual Wield, which states compatibility with YEP_WeaponAnimation (I haven't tested). If that doesn't cut it, I'm assuming the supported, paid version (indirectly linked near the start of this thread) will also be compatible with the WeaponAnimation plugin. :)
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
Oh I see, the <Weapon Image: x> notetag seems to affect all equipped weapons simultaneously...I should've checked that earlier. I think the necessary edit/rewrite to enable the behaviour you want is a bit beyond me at present, sorry. :kaoslp:

It seems there's an older, deprecated version of Ramza's plugin called True Dual Wield, which states compatibility with YEP_WeaponAnimation (I haven't tested). If that doesn't cut it, I'm assuming the supported, paid version (indirectly linked near the start of this thread) will also be compatible with the WeaponAnimation plugin. :)
I've actually already looked at his dual wield script. I does successfully change the images but it's wonky since in my game each individual weapon has it's own specific skill. The way I'm approaching dual wield is by forcing the user to use a specific action at the end of an action sequence by using a line such as this:

if (user.isStateAffected(1830))
Eval: BattleManager.queueForceAction(user, 2730, target);
end

You see at the beginning of skill 2730 I would run the necessary code to disable the weapon image for whatever weapon skill that preceded it. The process I'm using works perfectly, I just need to find the proper code to disable the weapon image for the first weapon from appearing. Here is a small preview below showcasing two individual skills being combined to create the illusion of dual wielding a sword and an ax(the sword is the first equip):


However in Ramza's plugin at line 258
I've noticed this code below:
Code:
//swap values of mainhand and offhand
$dataWeapons[$gameActors._data[subject.actorId()]._equips[0]._itemId].weaponImageIndex = $dataWeapons[$gameActors._data[subject.actorId()]._equips[1]._itemId].weaponImageIndex
$dataWeapons[$gameActors._data[subject.actorId()]._equips[0]._itemId].weaponAttackMotion = $dataWeapons[$gameActors._data[subject.actorId()]._equips[1]._itemId].weaponAttackMotion
I think this is what he uses to to get the images to swap but I haven't figured out how to do that in my game. I know yanfly limits you to one line of code for his "Eval:" command but perhaps I can run a common event instead to get more code processed.
 

alcreator440

Veteran
Veteran
Joined
Mar 26, 2014
Messages
242
Reaction score
124
First Language
English
Primarily Uses
RMMV
Okay I managed to figure out a solution. I took Caethyril's script and added the line with "//" in front of it below:
Code:
Game_Actor.prototype.performAttackOffhand = function() {
    var weapons = this.weapons();
    var wtypeId = weapons[1] ? weapons[1].wtypeId : 0;
    var attackMotion = $dataSystem.attackMotions[wtypeId];
  //this._cacheWeaponImage = this.equips()[1].weaponImageIndex;
    if (attackMotion) {
        if (attackMotion.type === 0) {
            this.requestMotion('thrust');
        } else if (attackMotion.type === 1) {
            this.requestMotion('swing');
        } else if (attackMotion.type === 2) {
            this.requestMotion('missile');
        }
        this.startWeaponAnimation(attackMotion.weaponImageId);
    }
};
Thanks again for the help! This thread can be closed now.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Is the "2 status updates 24h" still in effect?
My first attempt at Pixel Art :blink::) (I have no idea what I'm doing but I'm doing it)
Plugin instructions: *exists*
Plugin: What did he say? *error*
I feel like it's about time I share all the result of my experiment project here. But there's a lot of it.
Me and brother have an ongoing rivalry. We constantly fight for the High Score in Galaga on our arcade cabinet. Today I take back the top with 239,000. He'll be back. (No-Fire glitch is banned)

Forum statistics

Threads
93,723
Messages
914,937
Members
123,329
Latest member
ChrisCKC
Top