Weapon Effects

I'm trying to figure out a way to make certain weapons cause certain effects. For instance, let's say I have a character equipped with a weapon that has the Attack Elements of Physical and Darkness. I attack an enemy that is of the Darkness element, such as a Ghost or a Demon. Your intended damage from the attack heals the enemy by the same amount instead of decreasing it. How do I go about setting this up?

If I have more questions relating to other effects I want weapons to have, can I post them here?
I actually have a series of lunatic codes for Yanfly's damage core that will do exactly what you want to do.

Unfortunately, I'm at work, and can't access them right now, so I can't copy and paste the information until later tonight. If you are super hungry to get into it though, my most recent posted game is unencrypted and you can take a look at the code in the skills.json. If you're interested, it's in the in progress projects section ("RMRandomizer" is the place holder name).

How I managed it was by setting up states on applicable enemies to reflect what attributes they had (Immunities, vulnerabilities, half damage etc) then the damage code checks the enemy for those states, and then runs the modified damage code. Some is handled with pre-evals to check if the damage should be healing instead.

The advantage of this method is there is literally no limit to the number of interactions you can have, so your multi-elemental weapon type can strike and amplify multiple vulnerabilities.
I actually have a series of lunatic codes for Yanfly's damage core that will do exactly what you want to do.

Unfortunately, I'm at work, and can't access them right now, so I can't copy and paste the information until later tonight. If you are super hungry to get into it though, my most recent posted game is unencrypted and you can take a look at the code in the skills.json. If you're interested, it's in the in progress projects section ("RMRandomizer" is the place holder name).

How I managed it was by setting up states on applicable enemies to reflect what attributes they had (Immunities, vulnerabilities, half damage etc) then the damage code checks the enemy for those states, and then runs the modified damage code. Some is handled with pre-evals to check if the damage should be healing instead.

The advantage of this method is there is literally no limit to the number of interactions you can have, so your multi-elemental weapon type can strike and amplify multiple vulnerabilities.
Oh, I need the Yanfly's Damage Core plug-in to do this?
Unless you want to write a plugin to do the evals, almost certainly. There are a few other damage plugins that might also work, but I have no familiarity with them.

I did find a post where I put some of my code though.
Spoiler: Code Post
<damage formula>
var dmg = 1; //Primes the damage variable to 1 in the event that something breaks.
if (user.isWtypeEquipped(2) || user.isWtypeEquipped(12) || user.isWtypeEquipped(13) || user.isWtypeEquipped(16)) //swords - spears - katanas
{
var attack = a.atk + Math.randomInt(a.atk/8); //Replace this chunk with however you want your damage values set up.
var M = ((a.level*a.luk)/128 + 2);
var dfn = b.def;
}
else if (user.isWtypeEquipped(1) || user.isWtypeEquipped(9) || user.isWtypeEquipped(7) || user.isWtypeEquipped(10) || user.isWtypeEquipped(5)) //knives - bows - whips - claws
{
var attack = a.atk + Math.randomInt(3);
var M = ((a.level*a.luk)/256 + (a.level*a.agi)/256 + 2);
var dfn = b.def
}
else
{
var attack = Math.randomInt(a.atk) * 2;
var M = ((a.level*a.mat)/256 + 2);
var dfn = b.mdf
}
}
if (user.isStateAffected(7)) //Berserk, the .isStateAffected() code is heavily used. It is a great piece of javascript for damage and state functions.
{
attack = attack * 3/2;
}
if (b.isStateAffected(29) || (b.isStateAffected(112)))//shell defense boost
{
M = M / 2;
}
if (user.attackElements() == 3) //thunder weapon
{
if (b.isStateAffected(43)) //thunder Vulnerable here you can see where I've set up vulnerabilities.
{
attack = attack * 2; //the attack from way up there is now doubled.
dfn = 0; //no defense modifier
}
if (user.isStateAffected(53)) //thunder damage boost
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage
{
attack = attack / 2;
}
}
if (b.isEquippedArmor(6)) //Aegis Nullify
{
var aegis = 0;
aegis = Math.random();
if (aegis >= 0.33) {
attack = 0;
}
}
if (user.isEquippedArmor(171)) //Barrier Bit
{
var M = M / 2;
}
if (user.isEquippedArmor(187) && !user.isStateAffected(13)) //Deathgrip gloves
{
var M = M * 2;
}
if (user.isStateAffected(100) ) //Attacker Backrow
{
var M = M / 2;
}
if (b.isStateAffected(100) ) //Defender Backrow
{
var M = M / 2;
}
value = (attack - dfn) * M; //This is the actual damage formula. After all modifiers above.
dmg = value;
</damage formula>
Unless you want to write a plugin to do the evals, almost certainly. There are a few other damage plugins that might also work, but I have no familiarity with them.

I did find a post where I put some of my code though.
Spoiler: Code Post
<damage formula>
var dmg = 1; //Primes the damage variable to 1 in the event that something breaks.
if (user.isWtypeEquipped(2) || user.isWtypeEquipped(12) || user.isWtypeEquipped(13) || user.isWtypeEquipped(16)) //swords - spears - katanas
{
var attack = a.atk + Math.randomInt(a.atk/8); //Replace this chunk with however you want your damage values set up.
var M = ((a.level*a.luk)/128 + 2);
var dfn = b.def;
}
else if (user.isWtypeEquipped(1) || user.isWtypeEquipped(9) || user.isWtypeEquipped(7) || user.isWtypeEquipped(10) || user.isWtypeEquipped(5)) //knives - bows - whips - claws
{
var attack = a.atk + Math.randomInt(3);
var M = ((a.level*a.luk)/256 + (a.level*a.agi)/256 + 2);
var dfn = b.def
}
else
{
var attack = Math.randomInt(a.atk) * 2;
var M = ((a.level*a.mat)/256 + 2);
var dfn = b.mdf
}
}
if (user.isStateAffected(7)) //Berserk, the .isStateAffected() code is heavily used. It is a great piece of javascript for damage and state functions.
{
attack = attack * 3/2;
}
if (b.isStateAffected(29) || (b.isStateAffected(112)))//shell defense boost
{
M = M / 2;
}
if (user.attackElements() == 3) //thunder weapon
{
if (b.isStateAffected(43)) //thunder Vulnerable here you can see where I've set up vulnerabilities.
{
attack = attack * 2; //the attack from way up there is now doubled.
dfn = 0; //no defense modifier
}
if (user.isStateAffected(53)) //thunder damage boost
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage
{
attack = attack / 2;
}
}
if (b.isEquippedArmor(6)) //Aegis Nullify
{
var aegis = 0;
aegis = Math.random();
if (aegis >= 0.33) {
attack = 0;
}
}
if (user.isEquippedArmor(171)) //Barrier Bit
{
var M = M / 2;
}
if (user.isEquippedArmor(187) && !user.isStateAffected(13)) //Deathgrip gloves
{
var M = M * 2;
}
if (user.isStateAffected(100) ) //Attacker Backrow
{
var M = M / 2;
}
if (b.isStateAffected(100) ) //Defender Backrow
{
var M = M / 2;
}
value = (attack - dfn) * M; //This is the actual damage formula. After all modifiers above.
dmg = value;
</damage formula>
The damage formula looks somewhat complicated. Is this with or without the plugin?
With the plugin. And when you want to get to the "heal on X element" effect, you're either hoping that a bunch of elemental plugins all work together, or you do it through the damage core <pre-eval> code. I don't have the pre-eval code handy, but I can post the code later.

As for complexity, you're going to have to learn a bit of javascript, particularly how MV interacts with javascript and how to implement it through script calls or plugin commands.

I've stripped out some complexity from the code to really make it straight forwards

Spoiler: Code
<damage formula>
var dmg = 1; //Primes the damage variable to 1 in the event that something breaks.
if (user.isWtypeEquipped(2)) //swords, this now only checks for swords, or whatever is in weapon type 2 in your terms list.
{
var attack = a.atk * 2 - b.def;
}
else
{
var attack = a.atk - b.def;
}
if (user.attackElements() == 3) //thunder weapon, checks element 3.
{
if (b.isStateAffected(43)) //thunder Vulnerable here you can see where I've set up vulnerabilities. Checks state 43
{
attack = attack * 2; //the attack from way up there is now doubled.
}
if (user.isStateAffected(53)) //thunder damage boost, checks if the user has state 53 to amplify their damage.
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage, checks if defender has state 63
{
attack = attack / 2;
}
}
value = attack; //This is the actual damage formula. After all modifiers above.
dmg = value;
</damage formula>
With the plugin. And when you want to get to the "heal on X element" effect, you're either hoping that a bunch of elemental plugins all work together, or you do it through the damage core <pre-eval> code. I don't have the pre-eval code handy, but I can post the code later.

As for complexity, you're going to have to learn a bit of javascript, particularly how MV interacts with javascript and how to implement it through script calls or plugin commands.

I've stripped out some complexity from the code to really make it straight forwards

Spoiler: Code
<damage formula>
var dmg = 1; //Primes the damage variable to 1 in the event that something breaks.
if (user.isWtypeEquipped(2)) //swords, this now only checks for swords, or whatever is in weapon type 2 in your terms list.
{
var attack = a.atk * 2 - b.def;
}
else
{
var attack = a.atk - b.def;
}
if (user.attackElements() == 3) //thunder weapon, checks element 3.
{
if (b.isStateAffected(43)) //thunder Vulnerable here you can see where I've set up vulnerabilities. Checks state 43
{
attack = attack * 2; //the attack from way up there is now doubled.
}
if (user.isStateAffected(53)) //thunder damage boost, checks if the user has state 53 to amplify their damage.
{
attack = attack * 2;
}
if (b.isStateAffected(63)) //thunder half damage, checks if defender has state 63
{
attack = attack / 2;
}
}
value = attack; //This is the actual damage formula. After all modifiers above.
dmg = value;
</damage formula>
If it's easier to do what I want with only Yanfly's Damage Core, I'll go with that instead of using multiple plugins.

Also, how would I learn about those aspects? I've never used JavaScript before, and I don't think my computer has a suitable program to help me use Javascript.
Yanfly's Element Core plugin gives you the ability to "absorb" certain elements (i.e. heal from damage). It also allows you to assign multiple elements to skills other than Attack and provides various alternative rules for combining multiple elements (default is "highest element rate").

So with that plugin you could just put an <Element Absorb: Darkness> tag in each of the "darkness" enemies' noteboxes. ^_^
Caethyril: With regards to Element Core, I found that it didn't always work and never could nail down why. Not everyone will have my experience with it, and I encourage people to try different approaches, it may work just fine for the task at hand.

NickPat: As for how to learn Javascript: The forums have some great resources. The next step is writing out exactly what you want your formula to do, and then to look at how to implement it.

Once you know what you want to do, as yourself: Is this fun, and is it worth the time to figure it out? If the answer is yes, then ask: what is the easiest, simplest way to do this?

The script call database is your best friend, particularly if you want to get into slightly obscure conditional checks. I still have to look up every single thing I do in javascript, and reference Stackexchange/Github and other code libraries for examples and solutions all the time.

Ultimately do not be afraid of plugins. Use them liberally to save yourself time and energy. I've found with the damage end of things that Yanfly's Damage Core, Buff and States Core, Skills Core, and a smattering of others are always super useful.

Don't let the good (a plugin that does 90% of what you want) be the enemy of the great (your dream ideal that is 100% what you want).

Home finally: Here's the pre-eval code:

<Pre-Damage Eval> //fireabsorb
if(b.isStateAffected(72)){ //this is the fire absorb state that I assign to enemies/things that grant fire absorb
value =-value; //flips the damage value, so it now heals instead of damages.
}
</Pre-Damage Eval>

Original thread: https://forums.rpgmakerweb.com/threads/weapon-effects.105888/