"addState" in damage formula doesn't seem to work

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
I'm trying to make a skill where the enemy would lose 100 mana and the user would get 20% increased magical attack. The problem is, it doesn't seem to work. The formula for the attack is: a.addState(0021); 100 + a.mat * 4 - b.mdf * 2. The state is not added to the attack and the MP damage is random, not 100. I'm new to RPG Maker, if anyone could help me solve this issue I'd be grateful.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,485
Reaction score
3,514
First Language
EN
Primarily Uses
RMMZ
0021, with leading zeroes, is interpreted as an octal (base 8) number: you're telling it to add state ID 17 instead.

Randomness is due to the skill's Variance setting, default 20%. It's just under the formula box, next to the "Critical Hits: Yes/No" option.

Try this instead:

a.addState(21); 100 + a.mat * 4 - b.mdf * 2
Or, if you just want it to do 100 damage, ignoring the attacker's mat param and the defender's mdf param, try this:

a.addState(21); 100
Regardless, be careful if the skill can be used by actors with an Auto Battle trait: Auto Battle evaluates the formula of each available skill to decide which one to use.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,550
Reaction score
5,313
First Language
English
Primarily Uses
RMMV
Welcome!

I had a whole thing typed up and caethyril posted it first :stickytongue:

I will add: it's better to use something like Yanfly's Skill Core and put this as a Post-Damage Eval notetag.
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
0021, with leading zeroes, is interpreted as an octal (base 8) number: you're telling it to add state ID 17 instead.

Randomness is due to the skill's Variance setting, default 20%. It's just under the formula box, next to the "Critical Hits: Yes/No" option.

Try this instead:

a.addState(21); 100 + a.mat * 4 - b.mdf * 2

Or, if you just want it to do 100 damage, ignoring the attacker's mat param and the defender's mdf param, try this:

a.addState(21); 100

Regardless, be careful if the skill can be used by actors with an Auto Battle trait: Auto Battle evaluates the formula of each available skill to decide which one to use.
Well, I forgot to mention that I've tried both "0021" and "21". Both of them didn't work. The variance is at 0%.
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
Welcome!

I had a whole thing typed up and caethyril posted it first :stickytongue:

I will add: it's better to use something like Yanfly's Skill Core and put this as a Post-Damage Eval notetag.

I don't like using plugins, but if this won't work then I might consider using it.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,485
Reaction score
3,514
First Language
EN
Primarily Uses
RMMZ
The formula is only evaluated if the skill hits. The "to hit" roll depends on the Hit Type:
  • Physical Hit - checks attacker's Hit Rate, then defender's Evasion Rate.
  • Magical Hit - checks defender's Magic Evasion.
  • Certain Hit - always hits.
For now, try setting it to Certain Hit. If that works, check that the skill user has at least 1 trait that gives them Hit Rate. Ex-params like Hit Rate and Evasion Rate all start at 0. By default all classes have a trait that gives +95 Hit Rate:

screenshot.png
If that still doesn't work, consider sharing a screenshot of your skill page in the database.
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
The formula is only evaluated if the skill hits. The "to hit" roll depends on the Hit Type:
  • Physical Hit - checks attacker's Hit Rate, then defender's Evasion Rate.
  • Magical Hit - checks defender's Magic Evasion.
  • Certain Hit - always hits.
For now, try setting it to Certain Hit. If that works, check that the skill user has at least 1 trait that gives them Hit Rate. Ex-params like Hit Rate and Evasion Rate all start at 0. By default all classes have a trait that gives +95 Hit Rate:

View attachment 252724

If that still doesn't work, consider sharing a screenshot of your skill page in the database.
I always had it set to "Certain hit". My character does hit the enemy, but the state is never applied.
 

Attachments

  • skill.PNG
    skill.PNG
    109.6 KB · Views: 5

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,550
Reaction score
5,313
First Language
English
Primarily Uses
RMMV
Make sure that state 21 is the one you think it is. That you don't have anything on the actor that would give them State Resist against 21. Does the state have an icon so you'll know it's applied?
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
Make sure that state 21 is the one you think it is. That you don't have anything on the actor that would give them State Resist against 21. Does the state have an icon so you'll know it's applied?
I didn't put an icon on it but in messages tab i put some random stuff so the game will tell me if it's applied. I don't recall the actor having anything that would make him resistant to state 21.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,485
Reaction score
3,514
First Language
EN
Primarily Uses
RMMZ
Huh...addState ignores state rates, so I think State Resist is the only relevant trait here.

Just to make sure: are you are using any plugins? If you have recently added, disabled, or removed any plugins, remember to save your project to apply Plugin Manager changes before testing.

For testing purposes, give the state an icon: that way you can be certain exactly when the state is present. Doing so will let you see if it's a problem with a State Resist trait or the actual state's traits.
  • If the state is getting added, a screenshot of its page in the database might help.

  • If the state is not getting added, check all trait sources for the user. For an actor, that means checking the Actor, Class, State, Weapon, and Armor database tabs. If any of those have a "State Resist: 21" trait then the actor will not be able to have that state.
Another thing to try: make another skill, Scope: User, that just adds state 21 through its Effects list. I guess that will have the same result as this one, i.e. the state will not be added, but it may be worth checking.
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
Huh...addState ignores state rates, so I think State Resist is the only relevant trait here.

Just to make sure: are you are using any plugins? If you have recently added, disabled, or removed any plugins, remember to save your project to apply Plugin Manager changes before testing.

For testing purposes, give the state an icon: that way you can be certain exactly when the state is present. Doing so will let you see if it's a problem with a State Resist trait or the actual state's traits.
  • If the state is getting added, a screenshot of its page in the database might help.

  • If the state is not getting added, check all trait sources for the user. For an actor, that means checking the Actor, Class, State, Weapon, and Armor database tabs. If any of those have a "State Resist: 21" trait then the actor will not be able to have that state.
Another thing to try: make another skill, Scope: User, that just adds state 21 through its Effects list. I guess that will have the same result as this one, i.e. the state will not be added, but it may be worth checking.
So I chose the scope to be "the user", and somehow it worked. The state go applied to the actor, but the thing is the actor lost the MP, not the enemy.
Here's the state's page, for testing purposes i just put random stuff there.
 

Attachments

  • ghwd.PNG
    ghwd.PNG
    105.3 KB · Views: 4

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,550
Reaction score
5,313
First Language
English
Primarily Uses
RMMV
I suggest again you look at the enemy in the database. Or make sure plugins are turned off for a test. There has to be something on the enemy that's preventing the state from applying.
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
Alright, now I've found out that the state is getting applied, but it seems to have no effect except from draining mana, what I mean is that it doesn't increase the user's magical attack. The actor even seemed to deal more damage without the state applied. Is there anything wrong with the state's traits?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,550
Reaction score
5,313
First Language
English
Primarily Uses
RMMV
it doesn't increase the user's magical attack. The actor even seemed to deal more damage without the state applied.
Well, that's what you put on it. It says M.Attack * 20%. That will always be a smaller number than what you started with, that's how percentages work. If your enemy had MAT 10 and you put this state on, 20% of 10 is a MAT of 2.

If you want to increase a parameter, it has to be a percentage over 100%.

I'm very confused about the entire thread up until this point - the state wasn't being applied, but now it is? What changed?
 

Merix

Villager
Member
Joined
Feb 8, 2023
Messages
8
Reaction score
0
First Language
Polish
Primarily Uses
RMMV
Well, that's what you put on it. It says M.Attack * 20%. That will always be a smaller number than what you started with, that's how percentages work. If your enemy had MAT 10 and you put this state on, 20% of 10 is a MAT of 2.

If you want to increase a parameter, it has to be a percentage over 100%.

I'm very confused about the entire thread up until this point - the state wasn't being applied, but now it is? What changed?
I think the state was always being applied, but I didn't notice because the percentage was a low number and I thought that the game will tell me that the state was applied to the actor through the messages tab, but it turns out it didn't. I put a high number in the percentages and it seems to work now. Sorry, I'm new to RPG Maker and I'm confused about how some of the stuff work. Thank you for your time.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
7,550
Reaction score
5,313
First Language
English
Primarily Uses
RMMV
That's why I asked above if it had an icon for you to visually confirm that the state was on there.

I don't use the battle log, but I don't think the messages on the state get displayed if you hijack the process by calling addState() in the damage formula - they pop up when you use the Effects list on a skill.

Glad you got it working.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,485
Reaction score
3,514
First Language
EN
Primarily Uses
RMMZ
addState does interface with the battler's action result. However, by default when logging the result (Window_BattleLog.prototype.displayActionResults), the engine typically only checks the target, not the subject. It checks the subject for damage popups, e.g. for Drain HP/MP, but not for added/removed states etc. That's probably why the state's "add" message didn't show up. I forgot about that, would've mentioned it earlier otherwise. :kaoslp:
 

Latest Threads

Latest Posts

Latest Profile Posts

I made the mistake of using CCleaner. Now I have to hack every account I have xD
Having some issues with some esthetic scripts. Mind checking my threads and help?
I've been working on character sprites :), although not far in development, I wanted to start getting sprites done before my art style changes again.
62661208_w4addaU2hBczYcr.png
62661121_AGK5FiAt2QwWjYL.png
Grading exams makes me swing between being full of pride for my students and doubting everything I did this semester xD
Has it really been 50 streams? At this point it's just guilting me into pushing out a prototype. :kaoswt:



I should probably just bite the bullet and send it out, then go with my original plan to provide weekly updates.

Forum statistics

Threads
129,726
Messages
1,204,690
Members
170,812
Latest member
Dawsmead
Top