State Damage Modifiers

It looks like I left in some test code to show that the states aren't being duped.

Anyways it looks like you have 3 states, and I'm assuming one of those states is the one with the damage modifier.

Now the problem here is that in a new project, it worked, but it isn't working in your current project. I would assume there is a compatibility issue somewhere, but I don't think it is with yanfly's plugin.

Perhaps there's a new version of passive states?
Only defender tags aren't working (even in the new project, when I tested I used a attacker tag).

And I already have the newst version of passive states.

@Edit: This is driving me crazy!!!!!!

I remade every single dmg modifier state I made before, and I found out some never worked and some works perfectly. 

I made a item that increase maxMP every action you take, it works and this is the code:

(This state simples increase a variable value. The item itself increases MaxMP according the variable.)

<state damage modifier: attacker>var cid = a.id + 49;var ldd = $gameVariables.value(cid);$gameVariables.setValue(49,ldd + 5);return d;</state damage modifier>then, I made an armor that deals a massive damage every 5 succeful actions the actor does.

<state damage modifier: attacker>var cid = a.id + 59;var cdp = $gameVariables.value(cid);if ($gameVariables.value(59) == 5) {$gameVariables.setValue(59,0);return d + 50 + a.atk;} else {$gameVariables.setValue(59,cdp + 1);return d;}</state damage modifier>Other equip is an item that makes your attacks deal +30 damage. Simple, and easy.

<state damage modifier: attacker>return d + 30</state damage modifier>These 2 itens above does not work. But the item that increases maxMP does!
I took the simple damage increase modifier and wrote

<state damage modifier: attacker>return d + 999999999</state damage modifier>And when the state was applied, by attacker would deal ridiculous amounts of damage.Maybe 30 is too small to notice?
I took the simple damage increase modifier and wrote

<state damage modifier: attacker>return d + 999999999</state damage modifier>And when the state was applied, by attacker would deal ridiculous amounts of damage.Maybe 30 is too small to notice?
I'm using Yanfly armor scaling, the script makes the damage automatically decreases according enemy's armor/resistances without putting the "b.def" in formula box. does your script apply the damage modify before or after the armor decrease calculation?

and how do I make the "5 actions = massive damage" state? :/
It is applied in the order that you arrange your plugins.

I'm using Yanfly armor scaling, the script makes the damage automatically decreases according enemy's armor/resistances without putting the "b.def" in formula box. does your script apply the damage modify before or after the armor decrease calculation?

and how do I make the "5 actions = massive damage" state? :/
I think this is your issue:

Code:
<state damage modifier: attacker>var cid = a.id + 59; <----- It's not variable 59 right?var cdp = $gameVariables.value(cid);if ($gameVariables.value(59) == 5) { <---- But 59 here$gameVariables.setValue(59,0);  <--- and herereturn d + 50 + a.atk;} else {$gameVariables.setValue(59,cdp + 1); <--- and here tooreturn d;}</state damage modifier>
So just replace 59 with the cid.
Worked, thnx!!!

Now, I was trying to get the ID of the skill the actor used in last action... I already know how to check if the skill has Physical, Certain or Magic damage with

 a.currentAction().isPhysical()How do I check the skill? I want to add a "tired" state (the actor becomes weaker for one turn) when he uses a certain(s) skill(s)
state damage modifiers are evaluated in the context of the Game_Action.

You can check

Code:
this.item().id
But it could be an item or a skill so you might need to check the type as well.
Hi Tsukihime.

Is there a way to create states like Pain, Trouble etc.? I mean when actor(with Y state) takes damage, rest party members gets x% of this damage.

for example Pain (when battler with Pain takes damage, each other party member with Pain state gets 10% of this damage).

<state damage modifier: defender>return d;  <- damage applied to uservar tid = this.id <- store damage targetvar b = ???? <- set target to party, should be target, b or this??if (b.isStateAffected(77) && b.id != tid) { return d * 0.1; <- 10% damage to rest party members} </state damage modifier>If it is possible, how to make it?
Thanks in Advance.
Return simply returns the formula, so nothing after it will be executed.

Pain state would be a pretty advanced formula, but the logic is simple

1. get all of the members on the target's unit that are alive (eg: if actor is the target, then get all party members)

2. Apply damage to all members, excluding the target (to avoid double-counting)

3. Return the damage, so that we can process damage as usual

<state damage modifier: defender> var members = b.friendsUnit().aliveMembers(); for (var i = 0; i < members.length; i++) { if (members !== { members.gainHp(-d) }}return d;</state damage modifier>This would make it so that all other party members receive the same damage as well. You can change how much damage they receive.However, this doesn't show the damage popup for other members, because the game doesn't actually know that they were hit. All we've done here is directly change their HP. You can tell the game to display some animations

<state damage modifier: defender> var members = b.friendsUnit().aliveMembers(); for (var i = 0; i < members.length; i++) { if (members !== { members.gainHp(-d) members.performDamage() // show "hit" motion members.startDamagePopup() // show damage popup }}return d;</state damage modifier>And now you've made your own pain state.You just need to adjust the amount of damage that the other members get.
Thank You very much
I think I discovered an expansive new use for this script. I was trying to write a plugin that would provide OnSpellCast and OnSpellHit hooks that worked with notetags when it occurred to me that I actively use both this script and Yanfly's Passive States. I hacked away at it for awhile and discovered that the two together can serve as an OnSpellHit hook effect for any battle action. Give your party (and monsters!) a passive state with this notetag.

<state damage modifier: attacker>var castRegex = /<onspellhit>([\s\S]*)<\/onspellhit>/im;var res = castRegex.exec(this.item().note);if (res) { var formula = res[1]; this.castModifier = new Function("a", "b", "v", "d", formula); var a = this.subject(); var b = this.target; var v = $gameVariables; this.castModifier.call(this, a, b, v, d);} return d</state damage modifier>This will read the notetags for whatever item or skill you are using and execute the code it finds there (put it between <OnSpellHit></OnSpellHit>). While this is powerful, it comes with two (really three) caveats:

1) Standard damage formulas don't seem to work. I don't know why. Instead of a.hp - 2, you have to do things like a.gainHp(-2).

2) This plugin was designed to deal with damaging and healing spells and effects. If your item/ability/etc doesn't do that, this won't work. Additionally, it MUST do its work through the formula box, not the Effects box. Note that you can work around this by making non-damaging items and spells do 0 damage (and thus let this access every combat action in the game), but then you have to deal with the "X took no damage!" message every single action.

3) This is fundamentally a ludicrous way of doing things. A custom plugin that read these tags directly would certainly be a better option than using a plugin to read the notetags from a status and execute the code it finds there to read the notetags from a skill and execute the code it finds there. I don't know how noticeable the extra overhead will be to a human player for larger projects. This is probably not a good idea to use in the long run, but is nevertheless here should you need it.

The secret fourth caveat is that I've been away from RMMV for a couple weeks and as such have not updated my plugins in this time. This may or may not work with more up-to-date versions of this plugin.
You shouldn't access HP directly in general. Always use gainHP and analogous methods. This is because it properly updates result objects which are used to handle any results from actions.


Regarding effects...hmm, I do have something in the works for triggering effects.
Plugin updated to v1.3 - There was a bug where if you tried to return 0, the game would just treat it as the previous damage. So if your normal damage was 100, and your damage modifier changed it to 0, it would still be 100.
Here's a video that shows how you can convert damage that you deal into MP that you absorb, using State Damage Modifiers.
Shield Block State.

Works with Auto Passive States, Just give it to a shield or armor.


Breakdown:

(Math.random()*100+1) > 97 3% chance of occurring ( > 90 would be 10%, > 50 would be 50%, etc)
d > 0 So it doesn't block out healing
this.isPhysical() Only physical hit type are taken into account

b.addState(Dummy State ID) If you're using a state pop up plugin, name the dummy state "shield block".... This is not needed.
AudioManager.playSe({name: 'Reflection', pan: 0, pitch: 100, volume: 100}) Plays SE to give the player an audio cue of shield block
b.removeState(Dummy State ID) If you're using a state pop up plugin, have it not pop on remove.... This is not needed.

return (d - d)
Negates damage to 0. (d / 2 would be 50% damage, d / 4 would be 25% damage, etc)

else {return d}
if random chance doesn't meet, if damage is less than 0 aka healing, and it is not a physical hit type, damage is normal.

<state damage modifier: defender>
if (((Math.random()*100+1) > 97 && d > 0 && this.isPhysical()))
{
b.addState(ID)
AudioManager.playSe({name: 'Reflection', pan: 0, pitch: 100, volume: 100})
b.removeState(ID)
return (d - d)
}
else {return d}
</state damage modifier>

Shield_Block.png



I hope some one finds this useful. I am very sure you can use stats for the random check. example: (Math.random()*100+1) < (b.def /agi)

This method does not work with well with state motions, I've tried hard to add a guard motion upon shield block to no avail.

I am using this for parrying as well. Same concept.
Soul Eater State:

MP_Wall.png


Adds 10% of current HP into Physical attack and Skills and removes that 10% HP from attacker.

<state damage modifier: attacker>
if (this.isPhysical())
{
var hp = a.hp
a.gainHp(Math.round(0 - (a.hp/10)))
hp = (hp - a.hp)
return d = (d + hp)
}
else {
return d
}
</state damage modifier>
---------------------------------------------------
Spikes State:

Returns 10% damage back when hit with a physical attack.

<state damage modifier: defender>
if (d > 0 && this.isPhysical())
{
a.gainHp(Math.round(0 - (d/10)))
return d
}
else {
return d
}
</state damage modifier>

I'll post more as I play around, this Plugin is an absolute must have.
This one is very tricky.

Recycle State:

50% chance of Recovering an HP/MP/TP recovery item. IF and ONLY IF there is a damage formula. So for 500 HP potions you must put 500 in the formula (no variance) and NOT THE EFFECT BOX.

Put this in the Recycle State: (Credit to Aluvien in the Posts above)


<state damage modifier: attacker>
var castRegex = /<onspellhit>([\s\S]*)<\/onspellhit>/im;
var res = castRegex.exec(this.item().note);
if (res) {
var formula = res[1];
this.castModifier = new Function("a", "b", "v", "d", formula);
var a = this.subject();
var b = this.target;
var v = $gameVariables;
this.castModifier.call(this, a, b, v, d);
}
return d
</state damage modifier>

Put this in the Item Note Box:

<OnSpellHit>
if ((Math.random()*100+1) > 50)
{
a.addState(Dummy State ID)
AudioManager.playSe({name: 'Item1', pan: 0, pitch: 100, volume: 100})
$gameParty.gainItem($dataItems[ITEM ID], 1)
a.removeState(Dummy State ID)
return d
}
else {
return d
}
</OnSpellHit>

What you need to edit:

((Math.random()*100+1) > 50)
This is the probability of Recycling the Item. (change 50 to 90 for 10%, etc)
a.addState(Dummy State ID) This is if you're using a state pop up plugin, make a dummy state named "Recycle". This is optional
AudioManager.playSe({name: 'Item1', pan: 0, pitch: 100, volume: 100}) Audio notification that recycle has happened. Optional
$gameParty.gainItem($dataItems[ITEM ID], 1) change ITEM ID to the item's ID so it can be gained back. [1] or [2]
a.removeState(Dummy State ID) If you're using a state pop up plugin, make it so that it doesnt pop up on removal. This is optional.

Recycle.png
Mana Wall State

75% of Redirecting 25% of HP damage to MP.

<state damage modifier: defender>
if (((Math.random()*100+1) > 75 && d > 0 && this.isPhysical()))
{
var mpwall = Math.round(d / 4)
b.addState(Dummy State ID)
b.gainMp(0-mpwall)
b.removeState(Dummy State ID)
return d - mpwall
}
else {
return d
}
</state damage modifier>

What you need to edit.
Math.random()*100+1) > 75 Chance of this occurring (Change 75 to 50 for 50%, change to 90 for 10%, etc)
d > 0 doesnt affect healing
this.isPhysical() Physical attacks only

var mpwall = Math.round(d / 4) This is what's going to be redirected to MP. change the 4 to 2 for 50% damage, or to 3 for 33% etc.
b.addState(Dummy State ID) This is if you're using a state pop up plugin, make a dummy state named "MP Wall". This is optional
b.removeState(Dummy State ID) Same as above, if you are using it, make it so that it does not pop up on removal

Result:

25 points of HP damage is now:

MP_Wall.png


Please let me know if this is helping anyone, I'd like to know if I'm contributing in some way. Feels like Im posting on a dead thread lol.
Tool Expert State:

25% Chance of Reducing Skill Item costs. ONLY IF YOU ARE USING A SKILL ITEM COST PLUGIN.

Put this in the Tool Expert State:

<state damage modifier: attacker>
var castRegex = /<onexpert>([\s\S]*)<\/onexpert>/im;
var res = castRegex.exec(this.item().note);
if (res) {
var formula = res[1];
this.castModifier = new Function("a", "b", "v", "d", formula);
var a = this.subject();
var b = this.target;
var v = $gameVariables;
this.castModifier.call(this, a, b, v, d);
}
return d
</state damage modifier>

Put this in the Skills with Item costs.

<Onexpert>
if ((Math.random()*100+1) > 75)
{
a.addState(dummy state id)
AudioManager.playSe({name: 'Item1', pan: 0, pitch: 100, volume: 100})
$gameParty.gainItem($dataItems[item id], skillcost)
a.removeState(dummy state id)
return d
}
else {return d}
</Onexpert>

What you need to edit:

(Math.random()*100+1) > 75 (Change 75 to 50 for 50% chance, to 90 for 10% chance, etc)
a.addState(115) This is if you're using a state pop up plugin, make a dummy state named "Tool Expert". This is optional
AudioManager.playSe({name: 'Item1', pan: 0, pitch: 100, volume: 100}) Optional, this is an audio cue for the player.
a.removeState(dummy state id) This is if you're using a state pop up plugin, have it not pop up on removal

$gameParty.gainItem($dataItems[item id], skillcost) Item ID is the item you are getting back, skill cost is how much you are getting back
example: $gameParty.gainItem($dataItems[1], 2) you are getting two of item one. The idea is to match the item skill cost.


Results are like the pics on my previous posts above.
Salvation State

25% chance of surviving with 1 HP after a death dealing attack.

<state damage modifier: defender>
if ((Math.random()*100+1) > 75 && d > 0 && d > b.hp)
{
b.addState(Dummy state ID)
b.removeState(dummy state ID)
return (b.hp-1)
}
else {return d}
</state damage modifier>

Original thread: https://forums.rpgmakerweb.com/threads/state-damage-modifiers.51758/