• 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.

[Scripting Question] Changing Music Effect for Key Item

GPK

11
Posts
6
Years
    • Seen Dec 20, 2018
    Hello PokéCommunity!

    I have composed several different Music Effects for receiving an item, a theme when the player receives a regular item, an egg, a TM, an HM, a Mega Stone, and a Key Item.

    Is there any way I can make it so that way when the player receives say a Key Item, that a script will know that that is a key item, and play a different ME instead?
     
    1,682
    Posts
    8
    Years
    • Online now
    You'll need to edit def Kernel.pbItemBall and def Kernel.pbReceiveItem in script section PField_Field, specifically the \\me[Item get]'s to change it for the items.
    It works the same way as the normal event commands, with the text in the square brackets ("[" and "]") being the name of the file in the ME folder.
    But you'll need to modify those commands to check the type of item it's going into. Something like this could work:
    Code:
    def Kernel.pbReceiveItem(item,quantity=1)
      if item.is_a?(String) || item.is_a?(Symbol)
        item = getID(PBItems,item)
      end
      return false if !item || item<=0 || quantity<1
      itemname = (quantity>1) ? PBItems.getNamePlural(item) : PBItems.getName(item)
      pocket = pbGetPocket(item)
      music="Item get" # change this to your default
      if pbIsTechnicalMachine?(item)
        music ="TM get"
      elsif pbIsHiddenMachine?(item)
        music = "HM get"
      elsif pbIsKeyItem?(item)
        music = "Key get"
      elsif pbIsMegaStone?(item)
        music = "MegaStone get"
      end
      if isConst?(item,PBItems,:LEFTOVERS)
        Kernel.pbMessage(_INTL("\\me[{1}]You obtained some \\c[1]{2}\\c[0]!\\wtnp[30]",music,itemname))
      elsif pbIsMachine?(item)   # TM or HM
        Kernel.pbMessage(_INTL("\\me[{1}]You obtained \\c[1]{2} {3}\\c[0]!\\wtnp[30]",music,itemname,PBMoves.getName(pbGetMachine(item))))
      elsif quantity>1
        Kernel.pbMessage(_INTL("\\me[{1}]You obtained {2} \\c[1]{3}\\c[0]!\\wtnp[30]",music,quantity,itemname))
      elsif ['a','e','i','o','u'].include?(itemname[0,1].downcase)
        Kernel.pbMessage(_INTL("\\me[{1}]You obtained an \\c[1]{2}\\c[0]!\\wtnp[30]",music,itemname))
      else
        Kernel.pbMessage(_INTL("\\me[{1}]You obtained a \\c[1]{2}\\c[0]!\\wtnp[30]",music,itemname))
      end
      if $PokemonBag.pbStoreItem(item,quantity)   # If item can be added
        Kernel.pbMessage(_INTL("You put the {1} away\\nin the <icon=bagPocket{2}>\\c[1]{3} Pocket\\c[0].",
           itemname,pocket,PokemonBag.pocketNames()[pocket]))
        return true
      end
      return false   # Can't add the item
    end
    rinse and repeat for the other one.
    As for pokemon eggs, the script doesn't normally make sounds or any fanfare when you get it, though you can do it yourself.
    Code:
    def pbGenerateEgg(pokemon,text="")
      return false if !pokemon || !$Trainer || $Trainer.party.length>=6
      if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
        pokemon = getID(PBSpecies,pokemon)
      end
      if pokemon.is_a?(Integer)
        pokemon = PokeBattle_Pokemon.new(pokemon,EGGINITIALLEVEL,$Trainer)
      end
      # Get egg steps
      dexdata = pbOpenDexData
      pbDexDataOffset(dexdata,pokemon.fSpecies,21)
      eggsteps = dexdata.fgetw
      dexdata.close
      # Set egg's details
      pokemon.name       = _INTL("Egg")
      pokemon.eggsteps   = eggsteps
      pokemon.obtainText = text
      pokemon.calcStats
      # Add egg to party
      $Trainer.party[$Trainer.party.length] = pokemon
      Kernel.pbMessage(_INTL("\\me[Egg get]{1} received a Pokémon egg.\1",$Trainer.name))
      return true
    end
    IDK, something like that, I basically copied the text said when you get a pokemon normally.
     

    GPK

    11
    Posts
    6
    Years
    • Seen Dec 20, 2018
    Thanks! It works!

    It was kind of weird though, I didn't have to repeat when I went to script it the second time, it just worked from the other one I guess
     
    Back
    Top