Yanfly Lunatic State code problem

Discussion in 'RGSSx Script Support' started by Kes, May 26, 2018.

Thread Status:
Not open for further replies.
  1. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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: May 26, 2018
    #1
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    37,817
    Likes Received:
    11,523
    Location:
    Australia
    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
     
    #2
  3. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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.
     
    #3
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    37,817
    Likes Received:
    11,523
    Location:
    Australia
    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.
     
    #4
    Kes likes this.
  5. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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.
     
    #5
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    37,817
    Likes Received:
    11,523
    Location:
    Australia
    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.
     
    #6
    Kes likes this.
  7. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,315
    Likes Received:
    12,536
    Location:
    USA
    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).
     
    #7
    Kes likes this.
  8. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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: May 26, 2018
    #8
  9. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,315
    Likes Received:
    12,536
    Location:
    USA
    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.
     
    #9
  10. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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)
     
    #10
  11. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,315
    Likes Received:
    12,536
    Location:
    USA
    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.
     
    #11
  12. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    First Language:
    English
    Primarily Uses:
    RMVXA
    #12
  13. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,315
    Likes Received:
    12,536
    Location:
    USA
    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.
     
    #13
  14. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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.
     
    #14
  15. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,742
    Likes Received:
    381
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    I hope so, Inquiring minds want to know.
     
    #15
  16. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,977
    Likes Received:
    10,677
    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.
     
    #16
  17. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,742
    Likes Received:
    381
    Location:
    Canada
    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.
     
    #17
  18. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,315
    Likes Received:
    12,536
    Location:
    USA
    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?
     
    #18
  19. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,636
    Likes Received:
    14,384
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    Should be fine really.
     
    #19
Thread Status:
Not open for further replies.

Share This Page