[RMVX ACE] GAIN STATE ON CRITICAL HIT FOR ALL SKILLS? HELP PLEASE!

Posts

Pages: 1
I've been trying to implement a system in my game where if you score a critical hit, you gain a positive state while the foe gains a negative state.

From what I understand, this can be done for individual skills with the damage formula

if b.result.critical; a.add_state(30); end; a.atk * 4 - b.def * 2

but to implement this for every single command in the skill list seems a bit high-handed. I was wondering if there was a way to implement this for all skills, either by a script or notetags (which seem a lot less troublesome to copy paste).

I thought maybe Yanfly's Lunatic Mode https://yanflychannel.wordpress.com/rmvxa/battle-scripts/lunatic-objects/ might help but I don't have enough scripting knowledge to translate what I barely understand into code that his script understands.

Any help would be totally appreciated. Thanks in advance!
AGHHHH PANIC
SunflowerGames
The most beautiful user on RMN!
13323

Sometimes the best way is to do it the hard way.
Implementing unnecessary scripts to short cut things can cause you other problems.
Oh... I guess I'll just have to do it then.

I assumed there may have been a script out there available that loads skill formulae onto each other, like how Yanfly had a script that could load troop events into each other.

Mannnn...
In Game_Battler, look for apply_critical (somewhere around line 380) and insert this line:
user.add_state(1)

Also, in case you want the state to apply to the target instead, replace 'user' with 'self'.

It should work, I think.
Red_Nova
Sir Redd of Novus: He who made Prayer of the Faithless that one time, and that was pretty dang rad! :D
9192
author=Nivlacart
if b.result.critical; a.add_state(30); end; a.atk * 4 - b.def * 2

Woah wait what? You can do that?

author=karins_soulkeeper
In Game_Battler, look for apply_critical (somewhere around line 380) and insert this line:
user.add_state(1)
Also, in case you want the state to apply to the target instead, replace 'user' with 'self'.

It should work, I think.

Woah wait what? You can do that?


This is awesome.

EDIT:

Karins, I tried your approach and the game crashed, giving me a NameError. I don't think the game recognizes what "user" is.

EDIT 2: Oh yeah, I guess user would be defined under the Lunatic Objects package. Without it, the game doesn't know what user would be, right? i r dum. Nope. Lunatic Objects not needed at all. i r rly dum

EDIT 3: Karins, there's a step that needs to be taken before adding the line you specified. In Game_Battler, go to line 357 (the method make_damage_value) and change it from this:

value = apply_critical(value) if @result.critical
to this:

value = apply_critical(user, value) if @result.critical

Just add "user" in the parameters list. Then, the game will apply the state to the user.

If you want to apply the state to the target instead, you don't need either 'user' or 'self'. Just add_state(state) will do.
author=Red_Nova
EDIT:
Karins, I tried your approach and the game crashed, giving me a NameError. I don't think the game recognizes what "user" is.

EDIT 2: Oh yeah, I guess user would be defined under the Lunatic Objects package. Without it, the game doesn't know what user would be, right? i r dum.
Aaaah! You're right. I didn't notice that 'user' was local, not global *proceeds to slap self*

You're going to have to redefine apply_critical a bit to make it work.
def apply_critical(user, damage)
  user.add_state(id)
  return damage * 3
end
Also, you'll have to edit make_damage_value (around line 350) to compensate for the changes.
value = item.damage.eval(user, self, $game_variables)
  value *= item_element_rate(user, item)
  value *= pdr if item.physical?
  value *= mdr if item.magical?
  value *= rec if item.damage.recover?
  value = apply_critical(user, value) if @result.critical # <= this is the only line that was changed
  value = apply_variance(value, item.damage.variance)
  value = apply_guard(value)
  @result.make_damage(value.to_i, item)

Edit: I type really slow...

Edit2: I just prefer adding 'self' when an object refers to itself. Mostly to avoid confusion; since RGSS don't always use the 'return' keyword, having just an 'add_state' makes it seem like it's returning that.
Red_Nova
Sir Redd of Novus: He who made Prayer of the Faithless that one time, and that was pretty dang rad! :D
9192
Hold up. There's a slight problem with this approach.

Karins' solution works fine when adding/removing states to and from enemies, but issues arise when trying to do the same for the user. Specifically, when using a skill that targets more than one battler. For example: my current project has a state that enables a critical hit. Upon inflicting a critical hit, I wanted to remove that state from the character using the skill so criticals can't be spammed.

Here's where the issue lies: If a character with this state uses a skill that, for example, hits all enemies, only the first enemy will be hit with a critical, because the state will be removed after damage is calculated the first time.

As of right now, I can't find a clean fix to this problem. Perhaps it's worth looking into?

I know this is sorta off topic, but if this problem occurs when removing a state, then there could be some potential problems for anyone wanting to add states.
Red, I think you'll have to transfer the remove_state somewhere in the battle manager. There should be a method there that's called after each turn. With my approach, it will add/remove as soon as damage is dealt. With the battla manager one, it will add/remove after the entirity of the action is performed (thus solving the issue you raised).

But I'm not sure, and I can't really verify it right now as I'm not on the computer.

Edit: Alternatively, you could remove it via the troop's event pages (which is really, really inefficient on the dev's part).

Have a switch to toggle ON if criticals occur, set the troop event page's condition to Actor State X and trigger to Action End. Then have a conditional check if the switch is on. If it is, then remove the state and turn the switch off; Else, do nothing.
Welp, this works for what I wanted. Thanks again, karin and Red!

Although is there a way for a critical to remove a state too?

Like, if the player criticals the enemy with the positive state, he'll lose the state or gain the negative state?
Red_Nova
Sir Redd of Novus: He who made Prayer of the Faithless that one time, and that was pretty dang rad! :D
9192
Sure. Just replace add_state(state) with remove_state(state) and you're golden.
Ooooooh! Thanks, Red!

Oh damn, but now my game seems incredibly imbalanced. How do I set it to
if state(30) is applied,
remove state(30)

else
add state (29)?

lol I don't know how to translate it into the language OTL
Red_Nova
Sir Redd of Novus: He who made Prayer of the Faithless that one time, and that was pretty dang rad! :D
9192
You pretty much already had it.

if state?(30)
  remove_state(30)
else
  add_state(29)
end
Works like a charm! Thank you so much, Red!!
Never mind I screwed up on something it working fine just ignore this
Pages: 1