Determining Element of incoming attack in Buffs & States Core

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Hi there,

I would like to create a state that checks for the type of elemental damage before damage is processed (in the Custom React Effect segment). Currently, I've been using:

Code:
this.isPhysical()
to determine whether a hit is Physical or not, not realizing that the "Physical" refers to Hit Type.

I'm actually after determining the element. I did find this little statement here, however this only takes into account the damage delivered by the skill once received, not the Element ID of the skill itself:

Code:
this.item().damage.ElementID
Can anyone help me find a substitute to "this.isPhysical" that actually works with Elements instead of Hit Type?

Thanks!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,337
Reaction score
1,494
First Language
English
Primarily Uses
RMMV
I'm slightly confused by this:
Code:
this.item().damage.elementId
is the element ID of the skill as defined in the database. Are you looking for something different?
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Thanks @Trihan

No... that's actually what I'm looking for. But I thought I tried it and I didn't work.

Below are 2 examples where I want to specify conditions pertaining to the Element, and not Hit Type.

And when I see Element, I mean this bit:

1593423119570.png

One of these examples is from a state, using YEP's Buffs & States Core, here is the full code for it:

Code:
<Custom Apply Effect>

target._dmgCount = target._dmgCount || 0;

</Custom Apply Effect>

<Custom React Effect>

// Only count HP damage

if (value > 0 && this.isPhysical()) {

    target._dmgCount += value;

}

</Custom React Effect>

<Custom Leave Effect>

// Store value in game variable

$gameVariables.setValue(81, target._dmgCount);

user.forceActionCast(72, 0);

target._dmgCount = undefined;

</Custom Leave Effect>
So in the above code, I have a set up a state that collects and stores HP damage as a variable if the Hit Type is Physical. What I actually want to do is store the HP damage as a variable if the damage received came from the element of Physical, as shown in that top picture.

What would I change to have it this way, instead of as Hit Type?

Another example, I have edited my rpg_managers.js in regards to when the Substitute Special Flag triggers, like so:

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(53) && this._action.isPhysical();
However, I wish for the Substitute to be triggered if the damage is Physical elemental, not if the Hit Type is Physical.

Hit Type has been working so far, but there will be times in my project where I want to use a Physical Hit Type for Null-elemental damage.
 
Last edited:

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,089
Reaction score
497
First Language
English
Primarily Uses
RMMV
I think you should take a look at the Fire Aura tips and tricks page.

What this does is set up a shield that blocks damage until either the attacks have dealt enough damage to overcome the threshold, or if damage of a certain element has been dealt, in which case the shield is broken too.

The ability uses custom apply, custom regenerate, and custom react effects to get it all done. Essentially, it creates a variable to check whether or not incoming damage element matches which element types you've defined as the shield being weak to.

It sounds like with some tweaking to the Fire Aura note tags you could probably achieve what you want. I would suggest going through the lunatic code for Fire Aura, once you understand how it works, I think you'll be able to do what you want.

Also, I believe that this is what checks the element of a skill:

Code:
this.getItemElements()
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,337
Reaction score
1,494
First Language
English
Primarily Uses
RMMV
Assuming you only care about the actual type defined in the database rather than any multi-elements resulting from elements on equiment/traits, change
Code:
this.isPhysical()
to
Code:
this.item().damage.elementId == 1
If you want to incorporate multi-elements, you'll have to use getItemElements() as @HumanNinjaToo said.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,114
Reaction score
787
First Language
English
Primarily Uses
RMMV
I believe your looking for this:
JavaScript:
this.getItemElements().contains(#)
Where # is the element ID.

Edit: Ah, didn't see @HumanNinjaToo already mentioned it.
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Thanks for the feedback everyone, that's been really useful.

@Trihan - unfortunately, regarding the Substitute Special Flag criteria, it's still getting an error when using:

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(53) && this.item().damage.elementId == 1;
};
The error message says "this.item is not a function".

So, I also tried what @Frostorm mentioned, and get the same error:

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(53) && this.getItemElements().contains(1);
};
"this.getItemElements is not a function"

Then, when using it with the other skill I mentioned, I do get the results I want using:

Code:
if (value > 0 && this.item().damage.elementId == 1) {
In the first instance with the Substitute, I feel it's just a case where I'm misusing the statement, but I don't know where I'm going wrong.

@HumanNinjaToo - thanks for the YEP link, it's quite complicated given I don't understand much about coding, so I went for the potential easier solutions first, but you're right - when I get time I'll go through it and see if I can use what it uses to achieve what I want. Just wondering if a shorter solution would work for the Substitute Special Flag conditions.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,114
Reaction score
787
First Language
English
Primarily Uses
RMMV
What's your goal exactly? You want a state that adjusts the damage of DoTs / HoTs if it's of a certain element correct? Cuz, you might not even need the whole substitute thingy.

Edit: Ok, I c...I got your 2 goals mixed up... Still confused about what you're trying to achieve tho.
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Okay so the Substitute goal is this, which is working fine under the previous code I had altered, however it relied on Hit Type and not Elemental Type of an incoming skill.

1) Actor casts "Guard" ability. Selects which target in the party they want to Guard.

2) Puts state on self to enable Substitute, puts State on individual actor so Substitute knows who to guard (state 53).

3) It works as intended, except it Substitutes based on Hit Type instead of Element Type.

Let me know if you need more info @Frostorm , thanks!

EDIT: Just to be clear, the reason I want to use the Substitute Special Flag is because of the visual element as well. I know it is possible to replicate the effects of this set-up otherwise, however I literally want the party member who is doing the Guarding, to jump in front of the Guarded before the hit.

In all the iterations I've tried of this previously, using the Substitute ability but manipulating its conditions is the best solution I've found.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,114
Reaction score
787
First Language
English
Primarily Uses
RMMV
Can you give me the early working iteration? The one based on hit type.

Edit: Just to confirm, this part you posted works right?
JavaScript:
<Custom Apply Effect>
target._dmgCount = target._dmgCount || 0;
</Custom Apply Effect>
<Custom React Effect>
// Only count HP damage
if (value > 0 && this.isPhysical()) {
    target._dmgCount += value;
}
</Custom React Effect>
<Custom Leave Effect>
// Store value in game variable
$gameVariables.setValue(81, target._dmgCount);
user.forceActionCast(72, 0);
target._dmgCount = undefined;
</Custom Leave Effect>
For the other thing, try this:
JavaScript:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(53) && this._action.getItemElements().contains(1);
Edit: ^Lemme know if this works^
 
Last edited:

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Sure @Frostorm !

Here is the early iteration that was working, the iteration that was based on Hit Type (Physical):

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(53) && this._action.isPhysical();
};
And yes, the second bit of code you quoted back to me, which is for an unrelated skill in the game, works perfectly fine.

EDIT: Just saw your edit, @Frostorm :

Code:
For the other thing, try this:
JavaScript:
BattleManager.checkSubstitute = function(target) {
return target.isStateAffected(53) && this._action.getItemElements().contains(1);
This did the trick! Thanks so much!
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,114
Reaction score
787
First Language
English
Primarily Uses
RMMV
For this part, try this:
JavaScript:
<Custom Apply Effect>
target._dmgCount = target._dmgCount || 0;
</Custom Apply Effect>
<Custom React Effect>
// Only count HP damage
if (value > 0 && this.getItemElements().contains(1)) {
    target._dmgCount += value;
}
</Custom React Effect>
<Custom Leave Effect>
// Store value in game variable
$gameVariables.setValue(81, target._dmgCount);
user.forceActionCast(72, 0);
target._dmgCount = undefined;
</Custom Leave Effect>
This did the trick! Thanks so much!
:kaojoy:
Edit: Your skill/state/effect makes me want to implement such a mechanic in my game as well lol. My tank could really use such a skill.
 

thepsyche

Veteran
Veteran
Joined
Nov 16, 2016
Messages
287
Reaction score
65
First Language
English
Yup! That’s the class type I’m using both these moves for!

thanks for the help!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,337
Reaction score
1,494
First Language
English
Primarily Uses
RMMV
Yup! That’s the class type I’m using both these moves for!

thanks for the help!
Just FYI, the reason "this.item()" didn't work in the lines you mentioned is that in that context, "this" was BattleManager, and BattleManager doesn't have an item() function.

Unless you specify otherwise, "this" in JavaScript is basically a stand-in for "whichever object is in scope right now".
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Will probably never use MZ. Buys it anyway
Been playing Star Ocean: The Last Hope, the remastered version on PS4. I like it. Seems others think it's garbage, but I like these cutesy, silly, and tropey characters. Having waaaay more fun with it than SO: Integrity and Faithlessness.
In other news, my new computer is now ordered, and I'll have it in my hot little hands by the end of the week! CAN'T WAIT!!!
I've said my cat's names in such a baby-talk manner over the years, Biggs is now Biggoro, Bella is now Bellllyyaah, and somehow.....somehow Tessa is Sessashan

Forum statistics

Threads
100,457
Messages
976,149
Members
132,082
Latest member
nwr
Top