Yanfly Lunatic State code problem

Status
Not open for further replies.

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I have this snippet for Yanfly's Lunatic State script. It has been inserted at line 188 (default line number) i.e. just above where it says, "Stop editing past this point." So I'm sure it's in the right place.

Code:
when /TRANSFER[ ](\d+)[ ]TO_HERO[ ](.+)/i
      @pool = $game_party.battle_members
      @pool.delete(user)
      @pool = @pool.sample
      if $2.to_s.upcase == "RAND"
        @hero = @pool
      else
        @hero = $game_actors[$2.to_i]
      end # if
      return unless $game_party.battle_members.include?(@hero)
      return if @result.hp_damage <= 0
      dmg = [@result.hp_damage, $1.to_i].min
      @result.hp_damage = [@result.hp_damage - $1.to_i, 0].max
      @hero.hp -= dmg
      if $imported["YEA-BattleEngine"]
      text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:hp_dmg], dmg.group)
      @hero.create_popup(text, "HP_DMG")
      end # if
      @hero.perform_collapse_effect if @hero.hp <= 0
  
    when /TRANSFER[ ](\d+)%[ ]TO_HERO[ ](\d+)/i
      @pool = $game_party.battle_members
      @pool.delete(user)
      @pool = @pool.sample
      if $2.to_s.upcase == "RAND"
        @hero = @pool
      else
        @hero = $game_actors[$2.to_i]
      end # if
      return unless $game_party.battle_members.include?(@hero)
      return if @result.hp_damage <= 0
      return if @hero.dead?
      dmg = (@result.hp_damage * $1.to_i * 0.01).round
      @result.hp_damage = (@result.hp_damage * (100 - $1.to_i) * 0.01).round
      @hero.hp -= dmg

The instructions for using this snippet are:
#===NOTETAGS===================================================================
#---> States <---
#
# <transfer x to_hero y>
# <transfer x% to_hero y>

I have put the following note tag in a new State slot in the database.
<transfer 50% to_hero 3>

I then gave this state as a passive to actor 2.

However, when that actor receives damage, nothing is transferred to actor 3 and she takes the full 100%

Can anyone advise me what it is I've done incorrectly?
Thanks

EDIT
For the sake of clarity, I should mention that as well as giving it as a passive state, I have also tried inflicting it on Actor 2 at the beginning of battle. Makes no difference.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The reasons I can see that 50% of damage would not be transferred to actor 3 are:
- actor 3 is not in the battle party
- hp damage is 0 or less
- actor 3 is dead
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Actor 3 is in the party. I only have 5 in total and I put them all in for the purposes of this test.
HP damage was usually around 20
Actor 3 is alive and kicking. They all are, as this is a test against easy enemies.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Then I would temporarily replace this bit of code:
Code:
   when /TRANSFER[ ](\d+)%[ ]TO_HERO[ ](\d+)/i
     @pool = $game_party.battle_members
     @pool.delete(user)
     @pool = @pool.sample
     if $2.to_s.upcase == "RAND"
       @hero = @pool
     else
       @hero = $game_actors[$2.to_i]
     end # if
     return unless $game_party.battle_members.include?(@hero)
     return if @result.hp_damage <= 0
     return if @hero.dead?
     dmg = (@result.hp_damage * $1.to_i * 0.01).round
     @result.hp_damage = (@result.hp_damage * (100 - $1.to_i) * 0.01).round
     @hero.hp -= dmg
with this:
Code:
   when /TRANSFER[ ](\d+)%[ ]TO_HERO[ ](\d+)/i
     @pool = $game_party.battle_members
     @pool.delete(user)
     @pool = @pool.sample
     if $2.to_s.upcase == "RAND"
       @hero = @pool
     else
       @hero = $game_actors[$2.to_i]
     end # if
     p '@hero id is ' + @hero.id.to_s
     p 'checking if actor is in the party'
     return unless $game_party.battle_members.include?(@hero)
     p 'actor is in the party'
     p 'checking hp_damage > 0'
     return if @result.hp_damage <= 0
     p 'hp damage is > 0'
     p 'checking for @hero.dead?'
     return if @hero.dead?
     p '@hero is not dead'
     p 'original damage is ' + @result.hp_damage.to_s
     dmg = (@result.hp_damage * $1.to_i * 0.01).round
     p '@hero damage is ' + dmg.to_s
     @result.hp_damage = (@result.hp_damage * (100 - $1.to_i) * 0.01).round
     p 'target damage is now ' + @result.hp_damage.to_s
     @hero.hp -= dmg
     p '@hero hp is now ' + @hero.hp.to_s
and play with the console turned on, and it will show you where it's exiting. If it doesn't give ANY console output, it means the script isn't even running, which could indicate that another script has also overwritten the same class/method.

It appears that the damage will not be shown on the screen as a damage popup on actor 3, but the damage to actor 2 should show the adjusted figure.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz I replaced the section with yours, but still nothing happened.
Here is the console info. All the lines you see came up before the game opened the test map. Nothing at all appeared afterwards. This was the case with the original snippet and with the amended one.

Console.png

I put a silly icon on the state to make sure Actor 2 had it, and it showed in battle okay.
The HP bar on actor 3 never changed, even when actor 2 took damage, and that should have happened, even though there's no damage pop up.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
That indicates the script snippet is not being run at all.

From what I can tell, you have to set up an apply/erase/leave/react/shock/begin/while or close effect under the state in order for it to be considered, but I don't see in your post if you've said you set it up that way.

It also may be that you have <> in your notes, but it's not part of the regular expression being tested (I think it's looking for an exact match, but I could be wrong).

I wonder if it might work if you changed the note tag to this:
Code:
<apply effect: transfer 50% to_hero 3>
If not, where it says "Stop editting past this point", please insert the following line after the else below that instruction, above the call to lunatic_state_extension:
Code:
p 'handler not found for ' + effect.upcase
and see what the console says.
 
  • Like
Reactions: Kes

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
How many other states does the actor have? Include passives in the list. Yanfly Lunatic states has a bug that it runs all states as many times as you have states, due to Yanfly using a nested for loop by accident. So if your actor has 5 states present, that lunatic code will run 5 times.

In fact, this caused me fits for a long time with my damage block states, as it would say 25 in the code, but then I found out that if the actor is blinded and confused, then adds damage block, they blocked 125 damage, not 25 (the 125 is because all actors have 2 passive states too, so that is 5 states total, 25 * 5 = 125).
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz I made the substitution, but it still had no effect. I put in the line you suggested, and nothing came up on the console at all.

@bgillisp Actor 2 has 1 passive skill. In the test no other states are present. But if you include other actors as well, there is a total of 5 passives.

EDIT
I think I've cracked it.
@Shaz I decided to go through all the possibilities you listed, not just apply effect, and what was needed was <react effect: transfer 50% to hero 3>

That leads to his HP bar going down at the very end of the turn, irrespective of when actor 2 gets hit. But I can live with that.
It does lead to a slightly strange damage pop up for actor 2, which shows minuses, almost like a calculation, but dealing with that would, I suppose, require looking at how Yanfly's Battle Engine generates the pop up.

As an aside, I can now say with quiet confidence that applying a hit rate of 999% (which I did to actor 2 to try and speed things up) does not mean that the actor is hit most of the time, or even much more than half the time. Seems a bit useless to me.
 
Last edited:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Great! Now I do propose one more test. Inflict a 2nd state on that actor (can just be a dummy state, doesn't have to do anything) and make sure it is only 50% HP that is transferred. If so then you are good and managed to avoid the issue I ran into.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@bgillisp I should be so lucky!
It's difficult to work out exactly because of the strange damage pop up. For example, it shows
upload_2018-5-26_15-21-2.png

What's that supposed to mean? Dunno. Maybe it's supposed to be 7 damage minus 50% rounded up to - 4, and then another -4, but that doesn't tie in exactly with the HP numbers.

Although actor 2's HP bar goes down a bit, actor 3's goes down a lot more, so he's obviously taking more than 50%. In this particular instance actor 2 went from 118 to 114 (4 damage), actor 3 went from 140 to 129 (11 damage). Of course, this 11 might be the top line of the pop up calculation (7 + 4)
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Hmmm...it does look like the bug I hit. To be sure, inflict 5 states and see if you get -4 -4 -4 -4 -4. If so then yep, it is running as many times as you have total states. If that is the case I'll have to send you the edit I did to fix this.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
That's a little different than what I expected, as it is doing 50% of 50% each time. Regardless, hold on. I'll PM you the fix as I don't know if I can post it as it is an edit of Yanfly's script and they don't want reposting.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz and @bgillisp All is now working perfectly thanks to your help.
My poor rejected suitor can now continue to show his undying (we hope) affection in the most practical way possible in an RPG.

I am most grateful to you both.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,660
Reaction score
563
First Language
English
Primarily Uses
RMVXA
I hope so, Inquiring minds want to know.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Roninator2 Assuming that "Inquiring minds want to know" = how was it done, it was a combination of the suggestions Shaz made in the posts above together with the edit bgillisp made to Yanfly's script.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,660
Reaction score
563
First Language
English
Primarily Uses
RMVXA
Yes, but i was hoping that bgillisp's edit could have been made available. I have some lunatic scripts in my project, and this just makes me wonder that I will eventually run into the same problem when I, at some point, get around to the stage you are at with the game creation in order to test it.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
@Roninator2 : I don't know if I can post it publically as I had to redo some code, but at the same time Yanfly doesn't want their scripts posted anywhere else than their site, but they are also no longer maintaining their ACE scripts, even if they do still have bugs. Maybe @Archeia can weigh in on this?
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,141
Reaction score
15,473
First Language
Filipino
Primarily Uses
RMMZ
@Roninator2 : I don't know if I can post it publically as I had to redo some code, but at the same time Yanfly doesn't want their scripts posted anywhere else than their site, but they are also no longer maintaining their ACE scripts, even if they do still have bugs. Maybe @Archeia can weigh in on this?
Should be fine really.
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top