Spike Damage (not counter or reflect)

By "Spike damage" I mean damage that is taken for attacking an enemy (not sure how common this expression is, especially with how often spikes show up in video games in death pits).

I'm trying to setup spike damage in my game. It's separate from a counter in that it simply happens without an attack animation (think like punching a cactus) and it's different from reflect as I will want to have full range of damage formulae to control it, rather than having its damage be based on the amount of damage the blow dealt.

I've theorized about using some plugins like Yanfly's Counter Control and Action Sequence to create counter attacks with no animation. So far I can't truly have NO attack animation. I think this is the best option, but I can't figure out how to do it if it's possible. The other problem is that these would get tangled up in counter-attack skills I also have, but I think Counter Control lets you set up a priority system to let them work in tandem.

I don't suppose I'm missing something? Is there some simple way to have damage trigger using states? Any plugins out there that could help with this?
I figured this might be possible with some states. I was kind of hoping I could recreate this effect in the base maker, but I did some looking about and found
http://yanfly.moe/2016/03/12/tips-tricks-thornmail/

Now Yanfly is showing how to do this with some plug ins, but you've mentioned yanfly plugins in your initial topic, so I hope this doesn't go outside the bounds of what you're willing to do.


Here is the specific point in the related video to kind of look ahead and make sure you aren't gonna waste your time for an effect you don't want to investigate.
You can do this using Yanfly's Buffs and States Core plugin and this code.
Just place this code into a state and add this state to whoever has the "spike" damage.

<Custom React Effect>
// Only triggers this reaction if hit by a physical attack and for more than 0 damage
if (this.isHpEffect() && this.isPhysical() && value > 0) {
// Change X to whatever damage formula you want and add that number to the variable 'spike"
var spike = X;
// Make the attacker lose damage equal to the above variable called "spike"
user.gainHp(-spike);
// Show the damage taken on the attacker
user.startDamagePopup();
user.clearResult();
}
</Custom React Effect>
@Fernyfer775 Wow, quick work! I'll start playing with this tonight and see what all I can do with it. I do have three questions (which might all be the same one).

Can I change this.isPhysical() to any element I have listed? And how do I set it to accept multiple elements (potentially)? Sorry I am pretty garbage at code. I just brute force stuff and revert when it doesn't work how I expect ^_^;;

And how do establish an element for the spike damage itself? (with Element Core I hope to both boost and reduce it with items/skills/etc).
You can add all the conditionals you want by doing "&&" for AND or "||" for OR.

For example, if you want it to trigger off of physical OR magical, you can do:
if (this.isHpEffect() && this.isPhysical() || this.isMagical() && value > 0) {

Alternatively...if the ability is a "certain hit" ability, then neither the physical or magical hit tags will do anything, so you can just do:
if (this.isHpEffect() && value > 0) {

You can do elemental stuff with it as well, but I haven't played with element core, so I'm not very versed on how to do that. D:
@Fernyfer775 Been tinkering with this and it works great! Just wish I could set the element of the spike damage itself.

One big thing, though, is that if an enemy uses a multi-hit attack and they manage to die from spike damage before getting all those hits out, they will die but their sprite will be stuck on the screen forever. I know there's a command in the action sequence plugins for allowing things to "collapse", but I'm not sure that works in this field.
You can force collapse with javascript as well. But i have no access to my home pc at the moment so I can't double-check it.
Ah, yes, just add this to the end of it:
Wish I knew how to add the element part to it.

if (user.isDead()) {
// If the attacker is dead, make it collapse.
user.performCollapse();
}
@Fernyfer775 Beautiful! Thanks!

I did notice that this will proc on counter-attacks, though. I ... kind of like that. Makes spike damage allow you to be extra aggressive. But I could fix this, though, if only I got the elements system working since I have my counter attacks settled with their own "counter attack" element, (and I'm using multi-element so that they can still count as melee or ranged attacks) meaning I could put in there for this to not proc off that element. Ah, well.
I remember seeing some code for Yanfly's stuff that dealt with elements here in this thread:

https://forums.rpgmakerweb.com/inde...tes-26-latest-overpower-darkness-burst.66222/

Maybe you can dig around in there and find something that might help you out with that piece of it?
That's a cool thread! I dug around a bit, and finally found a formula in there with a call for an element. So I mashed this together for the damage formula part you gave me...

var spike = (b.atk * b.luk) * user.elementRate(7)

So the attack and luck part is just your standard damage formula stuff (apparently I needed to use b instead of a in this case). The element rate part is pulling the basic element rate field (I have a Spike damage element in the 7 slot).

This works great! Thing is, if I were to give the Spike Damager a buff to his spike damage, I'm not sure that would work since I don't know if Element Core actually interacts with the element rate or if it does its own separate calculation when it comes to boosting elemental damage *output* from a character (by the way, how does RPG Maker not have a way to boost elemental output? Only input!)

Edit: Just tested it, and placing Element Magnify on an item does not increase the potency of this formula. Dang.
You might be able to just rig it a bit to get what you want in terms of output.

Just throw in another conditional to boost the damage, something like:

<Custom React Effect>
if (this.isHpEffect() && value > 0) {
var spike = (b.atk * b.luk) * user.elementRate(7);

// Second conditional goes here, where "y" is the state that increases that element's output
if (user.isStateAffected(y)){
// This will multiply SPIKE by Z. Do note that 1 = 100%, so 1.2 would give a 20% boost
spike *= z;
}
// Ends Second conditional

user.gainHp(-spike);
user.startDamagePopup();
user.clearResult();
}
</Custom React Effect>

You might need to play around with "user" in the 2nd conditional, I can't recall if that would be "target" - "user" or "origin" lol. I'm sure there are cleaner ways to do it, but this is how I know how to do it XD

Original thread: https://forums.rpgmakerweb.com/threads/spike-damage-not-counter-or-reflect.103725/