Dual Wielding. Calculate damage from different weapons depending on skill used...

Please bear with, there's quite a lot to this problem.

MAIN PROBLEM
I have a dual wielding setup in my game using the MalMZDualWield plugin. This is combining with an ammunition system I've got going on thanks to VisuStella'sSkillsStates core and a boat load of additional skill cost types (skills cost bullets).


This is all about guns and ammo. The idea is that you can equip one type of weapon in one hand and be able to fire that weapon's ammo type. You can equip a second type of gun in the your off-hand and use a second ammo type.(This is all working fine).

There are 5 handguns that can fire4 different types of basic Ammo and use Handgun Skills
There are 5 machineguns that can fire 4 different types of basic Ammo and use MachineGun Skills.
There are 5 handguns that can fire 6 different types of shotgun Ammo use Shotgun Skills.
+ others.

MAIN QUESTION
The problem arises at damage calculation.
Each gun has it's own attack stat.

Lets say I equip my best shotgun with +20 attack and my worst handgun with +2 Attack. The values combine to give me +22. But what I want is, if I use a shotgun skill I will get +20 damage and if I use a handgun skill I will get+2 damage. My rubbish handgun shouldn't be able to blow an opponents head off, just because I'm holding a shotgun in my other hand.

The primary point of dual wielding in my case is just to provide new available skills.

FUTURE HEADACHE
I'll leave it there for now, because I know there's other difficulties to come, particularly arising from equipping two guns of the same type, but I won't worry about that just yet.
Just reference the specific weapon in your damage formula. Instead of a.atk which is the total ATK stat, you could look at a.weapons()[1].atk the ATK granted by the second weapon.

If you need that plus the actor's base value from their class, you should be able to pull that off the script call list.
Just make sure you either check for a.weapons()[1] first or use null-chaining (a.weapons()[1]?.atk) so that it doesn't crash the damage formula when there isn't a weapon equipped in that slot.
Just make sure you either check for a.weapons()[1] first or use null-chaining (a.weapons()[1]?.atk) so that it doesn't crash the damage formula when there isn't a weapon equipped in that slot.
I was assuming a setup where the skill requires a weapon type that can only be equipped off-hand - but yes, that's sensible to point out 🙂
Just reference the specific weapon in your damage formula. Instead of a.atk which is the total ATK stat, you could look at a.weapons()[1].atk the ATK granted by the second weapon.

If you need that plus the actor's base value from their class, you should be able to pull that off the script call list.
As usual, I think you're on it, but I'm a duck out of water here.

a.weapons()[1].attack <<<<<?? I'm guessing the square bracketed value refers to my equipment slot. Right? Or is that the weapon ID in my weapons list?

A..
If it's referring to the equipment slot, what if I switch the weapons around?

B..
If it's referring to a weapon ID, what about different levels of the same weapon type?

I'm confused. Please consider me an idiot and talk accordingly. =)

Which path are we on A or B?

I'm sure I will need the actor's base value from their class, but when you say "script call list" I come out in a cold sweat and my head implodes. Let's deal with that later.

Am I explaining my idiocy clearly?
Just make sure you either check for a.weapons()[1] first or use null-chaining (a.weapons()[1]?.atk) so that it doesn't crash the damage formula when there isn't a weapon equipped in that slot.
I think you've fished out a problem, but I'm still not understanding the basics of Turan's response. Thank you for the addition. I feel it will come in useful sooner than later. Although I'm not confident of my ability to crack this nut at all.
a.weapons()[1].attack <<<<<?? I'm guessing the square bracketed value refers to my equipment slot. Right? Or is that the weapon ID in my weapons list?
I thought I said it accurately the first time 😛 It is the second weapon you have equipped. Your original post talked about having a main-hand and an off-hand, and how to reflect the specific stats of the off-hand weapon.

That syntax is how (although you changed it - there's no such thing as attack, only atk).

A..
If it's referring to the equipment slot, what if I switch the weapons around?
Then you're no longer activating the skill with your off-hand weapon. You would need some more complicated piece of code to look at equipped weapons, figure out which slot has the weapon that's required to activate the current skill, then reference that.
I thought I said it accurately the first time 😛 It is the second weapon you have equipped. Your original post talked about having a main-hand and an off-hand, and how to reflect the specific stats of the off-hand weapon.

That syntax is how (although you changed it - there's no such thing as attack, only atk).


Then you're no longer activating the skill with your off-hand weapon. You would need some more complicated piece of code to look at equipped weapons, figure out which slot has the weapon that's required to activate the current skill, then reference that.
Hmmm... I really want to skin this cat in the quickest way possible. That's typically my style. I think I could do a fair bit to revise/compromise my system so that certain weapons are always off-hand and others are first hand. I obviously can't code so I'll do what I can to gear my game to your suggestion.

I really think in terms of just left and right hand, without either being considered primary, but I'm trying to communicate with vocabulary that's familiar.

I wasn't expecting a quick fix for this. The problem is far from solved, but I'll do some leg work to manoeuvre my goals to fit what seems to be an easier solution.
I really think in terms of just left and right hand, without either being considered primary, but I'm trying to communicate with vocabulary that's familiar.
Words don't matter, what you're doing in the engine matters.

You can call it main-hand and off-hand, right hand and left hand, first and second weapon slot, left ear and butt - none of that changes how you refer to the slots in the code.

I used the same terminology that you did in your first post...so if that's different for some reason than the terminology you actually have in your game, I presumed you'd be able to translate your own words 🤣

Good luck with your project!
A quick way to select a weapon with a specific type might be to use
a.weapons().find(w => w.wtypeId === 15).params[2]
(replace 15 with the identifier of the weapon type)
This assumes that the user always has a weapon of the right type equipped when using this formula.
If I remember correctly, "params[2]" replaces "atk" here.
Words don't matter, what you're doing in the engine matters.

You can call it main-hand and off-hand, right hand and left hand, first and second weapon slot, left ear and butt - none of that changes how you refer to the slots in the code.

I used the same terminology that you did in your first post...so if that's different for some reason than the terminology you actually have in your game, I presumed you'd be able to translate your own words 🤣

Good luck with your project!
When you have a very loose and fuzzy understanding of coding (as I do), it's hard to articulate what your goals are and to follow (what must seem to you like) simple instructions. The communication barrier is always difficult to navigate at my level. I'll try to do better.
Just reference the specific weapon in your damage formula. Instead of a.atk which is the total ATK stat, you could look at a.weapons()[1].atk the ATK granted by the second weapon.

If you need that plus the actor's base value from their class, you should be able to pull that off the script call list.
OK, I've switched a whole bunch of tags round. Now my system demands that shotguns + machine guns can only be placed in the 1st weapon slot (main hand) and pistols + crossbows can only be placed in the 2nd weapon slot (off hand).

1712486087499.png


So now that's all sorted, pistol skill damage calculations can always be associated with weapon slot 2.

So now I'm trying to plug the damage formula you suggested into a pistol skill formula. In this case the skill is to fire a 9mm bullet.
1712486436824.png


It doesn't seem to do anything. The damage delivered is always 0. Obviously I've tried tinkering around and changing values here and there.

One thought is that although it is a weapon, it's technically in the shield slot. I just have no clue.

Also you said earlier "If you need that plus the actor's base value from their class, you should be able to pull that off the script call list." I'm guessing it's this stuff?

1712487757444.png

Again, even if I'm looking in the right place, I've got no idea how to plug any of that into a formula.
A quick way to select a weapon with a specific type might be to use
a.weapons().find(w => w.wtypeId === 15).params[2]
(replace 15 with the identifier of the weapon type)
This assumes that the user always has a weapon of the right type equipped when using this formula.
If I remember correctly, "params[2]" replaces "atk" here.
Thanks, there's different levels to the weapons though. e.g. Rubbish pistol, Decent Pistol, Awesome Pistol. The attack power of pistol skills should vary depending on which level of pistol I have equipped. I think Turan is closest, but as it stands I can't even get the basics of his damage formula working. This is my very first experience messing with damage formulas, so practically everything is going over my head.
It doesn't seem to do anything. The damage delivered is always 0. Obviously I've tried tinkering around and changing values here and there.
Well, you didn't show the Pistol weapon - what's the ATK on it? If the enemy's defense portion of the formula is greater than the weapon's attack portion, it will mathematically give you 0 (you can't do negative damage).

Also you said earlier "If you need that plus the actor's base value from their class, you should be able to pull that off the script call list." I'm guessing it's this stuff?
No...that says "get reference to actors" - you don't need a reference to the actor, you already have a. You're talking about adding the actor's base ATK parameter to the weapon's ATK parameter, are you not?

Right at the top of the list is a link to a section on parameters.
1712512949974.png


Once you click on it, immediately visible on the screen is the base parameter from the actor's class.
1712513022560.png



And the example next to it even tells you that the ID for ATK is 2.

So if you want to add the actor's base ATK to the pistol's ATK, it's
Code:
a.paramBase(2) + a.weapons()[1].atk
Well, you didn't show the Pistol weapon - what's the ATK on it? If the enemy's defense portion of the formula is greater than the weapon's attack portion, it will mathematically give you 0 (you can't do negative damage).
The attack parameter on the pistol (Glock) is set to 500. I cranked it all the way up to ensure it would do damage. The defence parameter on my test enemy is 0.
You're talking about adding the actor's base ATK parameter to the weapon's ATK parameter, are you not?
YES! That's exactly correct.
Once you click on it, immediately visible on the screen is the base parameter from the actor's class.
1712513022560.png



And the example next to it even tells you that the ID for ATK is 2.
This makes near perfect sense to me. I am a bit worried that it says "party leader" in the examples column. Should I be worried about that, given that I have multiple party members that can switch positions? To put that another way, does "party leader" in this case simply mean the active character, performing the attack? I'm guessing it does.
1712520081622.png


If I simply plug "a.paramBase(2) * 5" into the skill damage formula I get a damage output when I attack. So that part seems to be working.

However "a.weapons()[1].atk" is still resulting in no damage regardless of the skill's attack parameter, the enemy's defence parameter, if it's in combination with the actor's base ATK parameter. i.e if I simply copy and paste "a.paramBase(2) + a.weapons()[1].atk" without any changes I get no damage output.

"a.weapons()[1].atk" breaks any formula I plug it into and always results in 0 damage output.

I can only guess at what the issue is. My gut is telling me that because this is a dual wield, the "weapon slot" is actually an armour slot. Y'know, because normally it would be a shield if the character didn't have the dual wield ability. Could I be on to something there?

I feel like we're right on top of the solution, but it's just not clicking.
I swear to God, this code "a.weapons()[1].atk" doesn't work in any context!

I've tried everything under the sun. I've switched plugins off. I've tried completely different methods of of dual wielding. I've added it to the "a.paramBase(2)" formula. I've bumped up the attack params on the skill, the actor to max. I've reduced the enemy defence parameter to 0.
Hey,

I think this is actually supposed to be a.weapons()[1].params[2]
Hey,

I think this is actually supposed to be a.weapons()[1].params[2]
Oh shoot, were the shorthands added in by one of the Yanfly plugins? Nice call.
Hey,

I think this is actually supposed to be a.weapons()[1].params[2]
Before I go crazy for another 2 days. I need to get this straight.

The full formula (including the character's base attack parameter) should therefor be something like..

a.weapons()[1].params[2] + a.paramBase(2) * 5
Will that work?

That would mean: calculate the attack value of the weapon housed in slot 2 in the attacker's equipment plus their base attack parameter and then multiply by 5.

What is really confusing me is exactly what the square bracketed numbers are referring to.

EDIT:

I dunno to 100% certainty, but I actually think this is working.

Original thread: https://forums.rpgmakerweb.com/threads/dual-wielding-calculate-damage-from-different-weapons-depending-on-skill-used.167525/