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

[Eventing Question] Changing Event Graphic based on Party Pokemon

24
Posts
11
Years
    • Seen Apr 7, 2022
    In a game I'm working on, there are various events that allow your Pokemon to interact with the environment, kind of like HMs, except instead of checking for a certain move, the event checks that you have a certain type of Pokemon.

    The current event I'm working on allows the player to burn down vines if they have a fire Pokemon in their party. After creating the event, I decided it would be cool if the player could actually send out their Pokemon to burn down the vines, like so:


    Spoiler:


    However, in this instance, I have just made the event use Houndour, because I knew that's what I had in my party. I was wondering if there was a way that my event can check for the first Fire Pokemon in the player's party and use the graphic for that Pokemon for the event?
     
    1,682
    Posts
    8
    Years
    • Seen yesterday
    returns pokemon object that has type
    Code:
    def pbCheckType(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        type = getID(PBTypes,type)
      end
      for i in $Trainer.party
        next if i.egg?
        return i if i.hasType?(type)
      end
      return nil
    end

    Code that loads pokemon overworld file (my file structure is put all the overworlds in characters/pkmn)
    Code:
    def pbPokemonOverworldFile(params)
      species = params[0]
      back    = params[1]
      factors = []
      factors.push([5,params[5],false]) if params[5] && params[5]!=false     # shadow
      factors.push([2,params[2],false]) if params[2] && params[2]!=false     # gender
      factors.push([3,params[3],false]) if params[3] && params[3]!=false     # shiny
      factors.push([4,params[4].to_s,""]) if params[4] && params[4].to_s!="" &&
                                                          params[4].to_s!="0" # form
      tshadow = false
      tgender = false
      tshiny  = false
      tform   = ""
      for i in 0...2**factors.length
        for j in 0...factors.length
          case factors[j][0]
          when 2   # gender
            tgender = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
          when 3   # shiny
            tshiny = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
          when 4   # form
            tform = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
          when 5   # shadow
            tshadow = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
          end
        end
        bitmapFileName = sprintf("pkmn/%s%s%s%s%s%s",
           getConstantName(PBSpecies,species),
           (tgender) ? "f" : "",
           (tshiny) ? "s" : "",
           (back) ? "b" : "",
           (tform!="") ? "_"+tform : "",
           (tshadow) ? "_shadow" : "") rescue nil
        ret = pbResolveBitmap("Graphics/Characters/"+bitmapFileName)
        return bitmapFileName if ret
        bitmapFileName = sprintf("pkmn/%03d%s%s%s%s%s",
           species,
           (tgender) ? "f" : "",
           (tshiny) ? "s" : "",
           (back) ? "b" : "",
           (tform!="") ? "_"+tform : "",
           (tshadow) ? "_shadow" : "")
        ret = pbResolveBitmap("Graphics/Characters/"+bitmapFileName)
        return bitmapFileName if ret
      end
      return ""
    end
    Calling the above code (returns the file name that you set the event graphic to.)
    Code:
    event.character_name=pbPokemonOverworldFile([pkmn.species,false,(pkmn.isFemale?),
           pkmn.isShiny?,(pkmn.form rescue 0),(pkmn.isShadow? rescue false)])
    Set the event variable by grabbing it directly, so event X is pulled with $game_map.events[X]. Alternatively, stuff the graphic setting code in a helper method, and pass get_character(X) as well as the pokemon object.

    This is kind of scattered, I know, kind of ripping out bits and pieces of code from my other projects. The bitmap and graphic code is tested and works, but I can't guarantee the same for the type check. It's a modification of the move check though, so probably works.
     
    24
    Posts
    11
    Years
    • Seen Apr 7, 2022
    I appreciate the response Vendily! I'm not that savvy with scripts and whatnot,but I'd love to learn some things here, so I'd appreciate if you helped me out a bit more. I'm not really understanding where I should be putting the bits of code you wrote. And then how to go about calling everything in my event... ?
     
    1,682
    Posts
    8
    Years
    • Seen yesterday
    Sorry, yeah, guess more explanation is in order, huh?
    Well those first two methods, they are top level, so you can just make a new script section and plop them in, easy peasy.

    The helper method, we need two things for that, the pokemon object, and the event that we want to apply the graphic to.
    Code:
    def pbSetPokemonEventGraphic(pkmn,event)
      event.character_name=pbPokemonOverworldFile([pkmn.species,false,(pkmn.isFemale?),
           pkmn.isShiny?,(pkmn.form rescue 0),(pkmn.isShadow? rescue false)])
    end

    now that we have a helper method all set up, we can get to the event stuff.
    first we need to get the pokemon object, which you said is the first fire type.
    Code:
    pkmn=pbCheckType(:FIRE)
    This method can return nil though so in the event, you should put a conditional branch with the script condition pbHasType?(:FIRE) if you haven't already and stick the checktype in there.
    Now we need to set the graphic, so it's helper method time.
    To set the graphic of the event with id X, we need to pass get_character(X) to it. NO PADDED ZEROS! It's event id 4, not 004! Else ruby thinks it's an octal and your 010 becomes 8.
    Code:
    pbSetPokemonEventGraphic(pkmn,get_character(X))
    If the event that transforms into a pokemon is the event you activate, you can also make it get_character(0). (While not necessary for this tutorial, the player is get_character(-1))
    rest of the event is basically the same as what you have, pokemon moves, flame, you put it away, no variables for that.

    Never been much of a tester, so while it should work, let me know if something funky happens.
     
    Last edited:
    1
    Posts
    7
    Years
    • Seen Oct 24, 2022
    Know this is a bit old, but managed to mostly get this working in v19.1, though have an extremely odd issue where it's throwing up an error only when checking certain types, not all types. Any help would be appreciated
    Spoiler:


    Here is the modified script, it was only a couple changes made
    Spoiler:
     
    Back
    Top