• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Creating Custom Poke Flute Functionality

155
Posts
10
Years
    • Seen Jun 11, 2021
    I've attempted to do this in the past back when I was using v14 of Essentials, but I ended up breaking the game completely. What I was trying to do was to give it a different function from the Blue Flute.

    When used in battle, I wanted it to wake up all sleeping Pokemon at once in both your party and the enemy's party while playing a music effect for a duration (pausing the text for a certain amount of time like when you find an item), but if used while no Pokemon are asleep, the music effect won't play and it just wastes your turn with that "Now that's a catchy tune!" message.

    When used out of battle, I wanted it to wake up the Pokemon in your party, playing that same music effect. Can anyone help me?
     
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    I tried my hand at making it again now that I know more about what I'm doing, but now I'm getting a syntax error.
    Code:
    ItemHandlers::UseInField.add(:POKEFLUTE,proc{|item|
       if (pokemon.@status==PBStatuses::SLEEP)
         {
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("All sleeping Pokémon woke up.")
         }
       else
         {
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("Now that's a catchy tune!")
         }
       end
    })
    What do I need to do differently?
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Learn Ruby. You don't need the {} in if statements.
     
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Learn Ruby. You don't need the {} in if statements.
    Ack! Sorry. That was a little bit of a brainfart moment for me. Thanks for reminding me. (A little embarrassing since I've been using Essentials for a while now.)

    Though I'm still getting this error when I try to test it out:
    Code:
    Script 'PItem_ItemEffects' line 333: SyntaxError occurred.
    Also, I'm aware this won't wake up the Pokemon just yet as I haven't set it to do that. At the moment, I'm just testing the messages to see if it recognizes that they're asleep.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    The second line says pokemon.@status, where the @ is superfluous.
     
    Last edited:
    824
    Posts
    8
    Years
  • Code:
    ItemHandlers::UseInField.add(:POKEFLUTE,proc{|item|
       wake=false
       for pokemon in $Trainer.party
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       if wake
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("All sleeping Pokémon woke up."))
         for pokemon in $Trainer.party
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
       else
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("Now that's a catchy tune!"))
       end
    })

    pokemon.@status was your issue. Yes, it shows up as @status in PokeBattle_Pokemon, but the @ sign is essentially a shortened form of "self."
     
    Last edited:
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Thanks. Also, I noticed something else I did wrong. The messages needed a second ")" after it. Though now, for some reason, it's not giving me the option to use the Poke Flute in the field. I can still register the item to use it, but it won't let me select the "Use" option normally.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    the @ sign is essentially a shortened form of "self."
    Well, not really. There's a pretty fundamental difference between methods and variables.

    @status and self.status are only interchangeable in PokeBattle_Pokemon because attr_accessor(:status) creates a method called status which simply returns the value of the variable @status (which is initialised in def initialize).

    Thanks. Also, I noticed something else I did wrong. The messages needed a second ")" after it. Though now, for some reason, it's not giving me the option to use the Poke Flute in the field. I can still register the item to use it, but it won't let me select the "Use" option normally.
    The item's out of battle usability is 5, but should be 2 instead.
     
    Last edited:
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    The item's out of battle usability is 5, but should be 2 instead.
    I probably should have mentioned that I already did that.
    Code:
    511,POKEFLUTE,Poké Flute,Poké Flutes,8,7000,A flute that is said to instantly awaken any Pokémon. It has a lovely tone.,2,4,6,
    I figured out what was wrong. I only had a UseFromField defined. I needed a UseFromBag too. Though I also tried coding the battle function, but nothing happens when I use it. It doesn't even waste my turn.
    Code:
    ItemHandlers::UseInBattle.add(:POKEFLUTE,proc{|item|
       wake=false
       for pokemon in $Trainer.party && pbOpposingSide.party
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       if wake
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("All sleeping Pokémon woke up."))
         for pokemon in $Trainer.party
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
       else
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("Now that's a catchy tune!"))
       end
    })
     
    824
    Posts
    8
    Years
  • Code:
    ItemHandlers::UseInBattle.add(:POKEFLUTE,proc{|item|
       wake=false
       for pokemon in battle.party1
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       for pokemon in battle.party2
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       if wake
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("All sleeping Pokémon woke up."))
         for pokemon in battle.party1
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
         for pokemon in battle.party2
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
       else
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("Now that's a catchy tune!"))
       end
    })

    $Trainer.party is your party when out of battle. party1 is all the Pokemon on your side (including any allies not controlled by you).
     
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    I did it wrong again. I should have been using BattleUseOnBattler instead of UseInBattle.
    Code:
    ItemHandlers::BattleUseOnBattler.add(:POKEFLUTE,proc{|item,battler,scene|
       wake=false
       battle=battler.battle
       for pokemon in battle.party1
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       for pokemon in battle.party2
         wake=true if (pokemon.status==PBStatuses::SLEEP)
       end
       if wake
         Kernel.pbMessage(_INTL("{1} played the {2}.\\me[Pokeflute]\\wtnp[160]",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("All sleeping Pokémon woke up."))
         for pokemon in battle.party1
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
         for pokemon in battle.party2
           pokemon.status=0 if (pokemon.status==PBStatuses::SLEEP)
         end
       else
         Kernel.pbMessage(_INTL("{1} played the {2}.",$Trainer.name,PBItems.getName(item)))
         Kernel.pbMessage(_INTL("Now that's a catchy tune!"))
       end
    })
    Everything works properly now, except for one very minor detail. After using it from the bag, after it says "All sleeping Pokemon woke up.", it immediately says "Can't use that here." Other than that, it works perfectly.

    UPDATE: Figured out what was wrong. I needed to put "next 1" in the UseFromBag method. Everything works correctly now. Thank-you.
     
    Last edited:
    Back
    Top