How do I implement rules for wielding two weapons using these particular requirements?

Hi all,

I’m looking for a way to accomplish something very specific with dual wielding and equipping weapons in general, and I’m wondering how best to accomplish it. The reason for the specifics is to implement a D&D like system of attacks/damage in general, which also relates to certain characters that will be in the game. I’m using a number of Yanfly plugins, so they can be used to help out here.

Here are all the things that it needs to do.

1) It needs to take into account that I am using weapons completely differently than how the system uses them by default. They do not alter the Basic Parameters *at all*, but instead are intended to add a certain value to damage based on the weapon type. The formula they need to provide is: Math.randomInt(x) + 1
(x) will be based on weapon type. The ATK parameter will adjust damage by adding something like this: (a.atk-10) / 2 to the calculation. (I really need to figure out how to alter that so that the absolute value is rounded down if positive, and up if negative. Ie, ATK 15 should result in a 2, and ATK 9 should result in -1, though I also need to make sure I’m not giving the opponent HP back when I hit with a negative).

I have been able to make weapons do this by using YEP Weapon Unleash. I give each weapon a 100% chance of unleashing a skill associated with that weapon type (ie, the Longsword would unleash the Longsword skill), with the skills having damage formulas of: Math.randomInt(x) + 1 + (a.atk-10) / 2

I am not attached to using that plugin, and am willing to use whatever method works best to achieve that basic formula (hopefully refined to correct the rounding issue).

2) I will need to be able to add specific damage modifiers to specific weapons, that will not influence the base parameters. So if I need the longsword +2 weapon to do an additional 2 points of damage, I need to be able to do that without giving it an ATK value of 2, because I can’t have weapons adjusting my Base Parameters. I could probably do this by making a unique skill for each particular weapon that varies from the basic weapon type if need be, but I’m not sure that would be ideal.

3) Accuracy will be huge, with HIT and EVA being a major factor. HIT needs to be based on a formula derived from an actor’s level and ATTACK, while EVA will be based on a formula derived from specific armor worn and AGI. I’ll probably be using YEP Hit Accuracy to figure out how to make that part work, but I haven’t even started on it yet.

With that background, here is how it relates to dual wielding and equipping weapons.

4) Any actor needs to be able to equip any weapons they are allowed to equip in any of the following ways:
a) One handed weapon + (optional) shield
b) Two-handed weapon
c) 2 one-handed weapons

Some actors will be able to equip every weapon in the game, so I need a system that doesn’t rely on specific actor limitations.

5) When using 2 one-handed weapons, I need each weapon to attack and deal damage separately when the character makes a basic Attack, using that formula above. As I understand it, this is not how the Dual Wield slot setting functions.

6) It would be ideal if I could limit certain actors in which weapons they could use when equipping 2 one-handed weapons, but not have that limitation apply to equipping one weapon. For example, any actors able to wield the weapons can equip one longsword, or one shortsword, OR 2 shortswords, but only some actors can equip 2 longswords. This is the least important part though of the goal, though it would be nice.

What are my options for how to accomplish those goals? (I have glanced at some of the dual wielding threads, but I figure my unique needs might throw a wrench into some of those solutions that experienced users could tell me immediately.)

Thanks in advance for any responses!
1. There's probably a better way of doing this but this should allow your damage system to work but will show actors gaining attack from the equipment). Firstly we'll be using the attack value of the weapon in the database to control x in your Math.randomInt(x) expression. So to do this you'll use

Code:
Math.randomInt(a.equips()[0].params[2]) + 1

NOTE: If there's a stat in your game that you're not using you could use that instead, just rename it to weapon damage or something, you'll need to change the [2] in the above script to the corresponding number (0 = MHP, 1 = MMP, 2 = ATK, 3 = DEF, 4 = MAT, 5 = MDF, 6 = AGI, 7 = LUK)

As for the actors ATK influence we'll use:

Code:
(a.paramBase(2)-10)/2

This will give the actors base attack before equipment is taken into account. The example you've given is unclear as you state you want to round up and round down based on whether the result is negative or positive but the example says both have been rounded down. I'm going to assume you want both instances to round down. (9-10)/2 = -0.5, rounded down is -1.
So, to do this we need to use Math.floor() this rounds numbers down to the nearest whole number. So the formula becomes:

Code:
Math.floor((a.paramBase(2)-10)/2)

Attacks don't give the enemy back hp if their damage is below 0, so we don't need to do anything there. Our end formula should look like this:

Code:
Math.randomInt(a.equips()[0].params[2]) + 1 + Math.floor((a.paramBase(2)-10)/2)

2. Using the above formula for your attack skill you can just plug in an extra two attack for the Longsword +2 etc (or whatever parameter you're controlling weapon damage with.

3. I don't feel like this is a question.

4. I would suggest looking at Yanfly's Equip Core and Equip Requirements plugins. You should be able to implement this using these.

http://yanfly.moe/2015/10/15/yep-10-equip-core/
http://yanfly.moe/2016/02/27/yep-75-equip-requirements/

5. You could have a ternary operator check that the equipment in the second slot is a weapon, if it is deal additional damage, if not don't. Ie.

Code:
Math.randomInt(a.equips()[0].params[2]) + 1 + Math.floor((a.paramBase(2)-10)/2) + ($gameActors.actor(1).equips()[1].etypeId === 1 ? Math.randomInt(a.equips()[1].params[2]) + 1 + Math.floor((a.paramBase(2)-10)/2) : 0)

NOTE: This is based on the assumption that all your weapons are equipment type 1 in the database.
As for the actual animation, I don't have an exact answer for you but I would check out Yanfly's action sequences which might have the functionality you need (I haven't gotten around to using it yet):

http://yanfly.moe/2015/10/11/yep-4-action-sequence-pack-1/

6. Again, you should be able to pull this off using Yanfly equip requirements.
Thanks! That helps a lot. I spent some time trying out the formulas and figuring out what they're doing.

One issue that I'm having though, is that while using paramBase is preventing the ATK value from the weapon from figuring into the portion of the damage calculation it's not supposed to figure in, outside of attacking the actor's ATK value is still considered to have the bonus from the equipment. That is an issue for me because I'm going to use ATK to represent physical strength, and it can be used out of combat to do things that aren't related to the weapon they have equipped, and I'd like the value without the weapon to show up when checking character's Status.

Thanks on the round down correction. For some reason I've "always" thought that rounding down negative numbers was based on their absolute value. (I say always, because I obviously learned better in school and just forgot somewhere along the way).

I'd prefer to have the secondary weapon make it's own attack rather than just adding damage on the first, but I might very well have to just have it add on damage. At some point, "close enough" will work.

I decided that using Weapon Unleash won't work for me, because it has the downside that I can't use different weapons with the same skill (without making a huge number of skill+weapon skills).

I did look at those plugins before I posted, but I'm going to have to back to them again and see if there is anyway to make things work.
Unfortunately, the weapons attack will always factor in on the status menu with this method. You can have the checks your doing for strength later subtract the weapons atk value but I feel this isn't going to be suitable for you. I haven't used this plugin, so I can't say how well it works, but I think it solves your problem in a better way than my solution.

http://himeworks.com/2016/02/weapon-damage/

Using this plugin your weapon damage formula would be:

Code:
<weapon damage>
Math.randomInt(x) + 1
</weapon damage>

Where x = maximum weapon damage

Your damage formula would then become:

Code:
Math.floor((a.atk-10)/2) + a.weaponDamage(b)

For the equip requirements I think you're going to be using the lunatic mode scripts. Something along the lines of this:

Code:
if (user.equips()[0].wtypeId !== 2 && user.equips()[1].wtypeId !==2) {
condition = true;
} else {
condition = false;
}

You would put this on all of your weapons and shields etc. All your two handed weapons would be weapon type 2 in the database. This would mean if in either of the players hand slots they had a two handed sword they would not be able to equip anything else.

As for the 2 separate animations for the attack I can't really advise other than taking a look at the action sequence pack.
The damage is *perfect*. Thanks a lot!

(EDIT: The HIME_WeaponDamage plugin has a conflict with a setting in YEP Item Core. Anyone using both needs to disable the Max Weapons (set to 0) in Item Core, or the weapon damage value will not work in battles (but *will* work in the Battle Test, so you might not see the problem at first)).

Do you know how to allow for multiple weapon types in that sort of equip formula? I'm sure it's pretty basic, but if I wanted:
!== (2, 5, 8, and 15)
how would I do that sort of thing?
I think a good way to do it might be to use a Dual Wielding state. I found a plugin that makes it toggle-able. So what I basically need to do is have that equip requirement check to see if the Dual Wielding state is active, and if so disallow the weapon. (Or allow it as long as that state isn't active, is I think how it would go).

To make it a bit trickier though, I actually need two of those states, one of them is more restrictive (Two-Weapon Fighting state) than the other (Dual Wielding state). So I need to be able to set equip requirements for some items that that won't work unless neither of those states is active, and others that will work as long as Two-Weapon Fighting isn't active.
Do you know how to allow for multiple weapon types in that sort of equip formula? I'm sure it's pretty basic, but if I wanted:
!== (2, 5, 8, and 15)
how would I do that sort of thing?

If you wanted to say check for more weapon types your would just use the && to add extra conditions to your checks, like I used above to check both the first and second equipment slot (numbers 0 and 1).

Code:
user.equips()[0].wtypeId !== 2 && user.equips()[1].wtypeId !==2 && user.equips()[0].wtypeId !== 3 && user.equips()[1].wtypeId !== 3

This would probably get quite cumbersome though if you had lots of 2 handed equipment so it might be worth using an array - I'll admit my JS isn't the strongest and I'm not in MV at the moment to confirm this is working but you could try:

Code:
var thWeapons = [2, 5, 8, 15];

if (thWeapons.includes(user.equips()[0].wtypeId) || thWeapons.includes(user.equips()[1].wtypeId)) {
condition = false;
} else {
condition = true;
}

Any other two handed weapons just add them to the end of the array, separate all values with commas.

With regards to your 2 dual wielding variants, do you actually mean using states (ie from the database)? You'll have to link the plugin you're using for me to be able to offer any suggestions - without knowing what it is I don't know how it works.
Thanks! I'll keep that code, because I'll likely need it.

Yes, what I ended up doing was making two different states in the database, both of which have the Slot Type: Dual Wield State. One of them has a couple of other features to it. I got some help and now I've figured out how to limit which weapons can be used based on which state you are in.

So here's how it all looks:

<Custom Equip Requirement Condition>
if (user.isStateAffected(32) || user.isStateAffected(33)) {
condition = false;
} else {
condition = true;
}
</Custom Equip Requirement Condition>

That goes in the notes for greatswords, bows, and anything else that requires both hands, so that no one can dual wield them. It relies on YEP Equip Requirements.

<Custom Equip Requirement Condition>
if (user.isStateAffected(32)) {
condition = false;
} else {
condition = true;
}
</Custom Equip Requirement Condition>

This instead goes in the notes for weapons that can be dual wielded, but only by those with special skills. Same requirement.

State 32: Two-Weapon Fighting
-Trait: Slot Type Dual Wield
-Note: <toggleable>

State 33: Dual Wielding
-Trait: Slot Type Dual Wield + eventually more
-Note: <toggleable>
-Note: <Replace Attack: 244>

The states both require HIME Toggleable States https://himeworks.com/2015/11/toggle-able-states/ so they can be toggled on and off. State 33 is the less restrictive one. It also makes use of YEP Weapon Unleash to replace the wielder's basic attack with another skill when the state is active.

I have two skills to activate those states.

Skill: Two-Weapon Fighting
-Scope: The User
-Effect: Add State Two-Weapon Fighting 100%
-Note: <Instant>

Skill: Dual Wielding
-Scope: The User
-Effect: Add State Dual Wielding 100%
-Note: <Instant>

YEP Instant Cast is needed to allow these skills to toggle the Two-Weapon Fighting or Dual Wielding states on and off without taking the character's action.

So it's mostly working the way I want it to now. 🙂

I do have one other thing I'm trying to pull off, that I'm not sure how to do.

HIME Weapon Damage is working great. I'm using weapon damage formulas that look like this:

<weapon damage>
Math.floor((a.atk-10)/2) + Math.randomInt(8) + 1
</weapon damage>

What I want to do is find a way to check if the weapon is being wielded in the off-hand, and if it is, the damage formula should only be:

Math.randomInt(8) + 1

In other words, you only get to add the number derived from your ATK once, even if you are wielding two weapons. Now, the easier way to do this would probably be to put it in the Attack skill's damage formula, but that would prevent me allowing weapons to use different parameters for their damage (some can use the higher of ATK or AGI, while some only use AGI and ignore ATK).

So is there a way to check whether the weapon is used in the off-hand, and if so change the damage formula? If it isn't easy to check if the particular weapon is being used in the off-hand, I'd settle for checking to see if any weapon is used in the off-hand.
You could use this formula to check if the second weapon is a particular id (you would just substitute the weapon id in from the database).

For instance this weapon has id 5

Code:
a.equips()[1].id === 5 ?  Math.randomInt(8) + 1 : Math.floor((a.atk-10)/2) + Math.randomInt(8) + 1

However, there's a problem with doing this - if the actor is equipped with 2 of the same weapon then the players own stats won't get factored in at all. Now you could make this work but it's more complex, and I think I have a solution that works better.

Rather than check for a particular weapon just check if the player has two weapons equipped (similar to what you've already states was your back up). If the player does have two weapons adjust your actor stat modifier to become:

Code:
Math.floor((a.atk-10)/4)

This means that you'll have half of the bonus applied to each weapon which will then equal the whole - so the end result works (asides from maybe 1 point due to rounding twice). An additional bonus is that say for instance one weapon got a bonus from attack and the other got a bonus from dexterity both of these bonuses would be factored in, rather than just the parameter bonus of the main weapon. With that in mind, I would suggest using this code:

Code:
a.weapons().length === 2 ? Math.floor((a.atk-10)/4) + Math.randomInt(8) + 1 : Math.floor((a.atk-10)/2) + Math.randomInt(8) + 1

If this doesn't work or you don't like it let me know and we can spitball something different (maybe see about making the first method work).
Thanks again! That last formula works great. I even figured out how to fix the math rounding. Instead of using Math.floor in the weapon notes, I can use it in the skill damage formula to get the correct results. It seems to be doing it's job according to the tests I've run.
I actually had the same thought some time after posting. Glad you've got it working now.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-implement-rules-for-wielding-two-weapons-using-these-particular-requirements.105417/