• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] How to let the game know which sprites it should choose?

Faburisu

KitsuneNiban
  • 8
    Posts
    8
    Years
    • Seen Jan 15, 2018
    Okay so I added new forms of Pokémon to my game called "Alternative Shinies" (for now).
    Everything is working and they are in the game, I just can't figure out how to tell the game which sprites it should load for them.

    Example:

    The game uses "001s" as the sprite for shiny Bulbasaur, and "001sb" as the back sprite.

    I have called my sprites "XXXa" and "XXXab", I just can't figure out how to tell the game that it should load these sprites when an alternative shiny is created.

    I've literally spent hours trying to figure this out, so please, give me your advice. Thank you!
     
    You're gonna want this section of my Alolan Forms script:

    Code:
    ##############################################################
    # Appearance change
    ##############################################################
    class PokemonSprite < SpriteWrapper
      def setSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false[B],delta=false[/B])
        @_iconbitmap.dispose if @_iconbitmap
        @_iconbitmap=species>0 ? pbLoadSpeciesBitmap(species,female,form,shiny,shadow,back,egg[B],delta[/B]) : nil
        self.bitmap=@_iconbitmap ? @_iconbitmap.bitmap : nil
      end
    end
    
    class PokemonEggHatchScene
      def pbStartScene(pokemon)
        @sprites={}
        @pokemon=pokemon
        @nicknamed=false
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        addBackgroundOrColoredPlane(@sprites,"background","hatchbg",
           Color.new(248,248,248),@viewport)
        @sprites["pokemon"]=PokemonSprite.new(@viewport)
        @sprites["pokemon"].setSpeciesBitmap(@pokemon.species,@pokemon.isFemale?,
                                             (@pokemon.form rescue 0),@pokemon.isShiny?,
                                             false,false,true[B],(@pokemon.isDelta? rescue false)[/B]) # Egg sprite
        @sprites["pokemon"].x=Graphics.width/2-@sprites["pokemon"].bitmap.width/2
        @sprites["pokemon"].y=48+(Graphics.height-@sprites["pokemon"].bitmap.height)/2
        @sprites["hatch"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
        @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
        @sprites["overlay"].z=200
        @sprites["overlay"].bitmap=Bitmap.new(Graphics.width,Graphics.height)
        @sprites["overlay"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,
            Color.new(255,255,255))
        @sprites["overlay"].opacity=0
        pbFadeInAndShow(@sprites)
      end
    end
    
    def pbLoadPokemonBitmap(pokemon, back=false, scale=nil)
      return pbLoadPokemonBitmapSpecies(pokemon,pokemon.species,back,scale)
    end
    
    # Note: Returns an AnimatedBitmap, not a Bitmap
    def pbLoadPokemonBitmapSpecies(pokemon, species, back=false, scale=nil)
      ret=nil
      if scale==nil
        scale=1
        if defined?(POKEMONSPRITESCALE)
          scale=POKEMONSPRITESCALE if POKEMONSPRITESCALE != nil
        end
      end
      if pokemon.isEgg?
        bitmapFileName=sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
        if !pbResolveBitmap(bitmapFileName)
          bitmapFileName=sprintf("Graphics/Battlers/%03degg",species)
          if !pbResolveBitmap(bitmapFileName)
            bitmapFileName=sprintf("Graphics/Battlers/egg")
          end
        end
        bitmapFileName=pbResolveBitmap(bitmapFileName)
      else
        bitmapFileName=pbCheckPokemonBitmapFiles([species,back,
                                                  (pokemon.isFemale?),
                                                  pokemon.isShiny?,
                                                  (pokemon.form rescue 0),
                                                  (pokemon.isShadow? rescue false)[B],
                                                  (pokemon.isDelta? rescue false)[/B]])
        # Alter bitmap if supported
        alterBitmap=(MultipleForms.getFunction(species,"alterBitmap") rescue nil)
      end
      if bitmapFileName && alterBitmap
        animatedBitmap=AnimatedBitmap.new(bitmapFileName)
        copiedBitmap=animatedBitmap.copy
        animatedBitmap.dispose
        copiedBitmap.each {|bitmap|
           alterBitmap.call(pokemon,bitmap)
        }
        ret=copiedBitmap
        if defined?(DynamicPokemonSprite) # if EBS code exists
          animatedBitmap=AnimatedBitmapWrapper.new(bitmapFileName,scale)
          animatedBitmap.prepareStrip
          for i in 0...animatedBitmap.totalFrames
            alterBitmap.call(pokemon,animatedBitmap.alterBitmap(i))
          end
          animatedBitmap.compileStrip
          ret=animatedBitmap
        end
      elsif bitmapFileName
        ret=AnimatedBitmap.new(bitmapFileName)
        ret=AnimatedBitmapWrapper.new(bitmapFileName,scale) if defined?(DynamicPokemonSprite) # if EBS code exists
      end
      return ret
    end
    
    # Note: Returns an AnimatedBitmap, not a Bitmap
    def pbLoadSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false,delta=false)
      ret=nil
      if egg
        bitmapFileName=sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
        if !pbResolveBitmap(bitmapFileName)
          bitmapFileName=sprintf("Graphics/Battlers/%03degg",species)
          if !pbResolveBitmap(bitmapFileName)
            bitmapFileName=sprintf("Graphics/Battlers/egg")
          end
        end
        bitmapFileName=pbResolveBitmap(bitmapFileName)
      else
        bitmapFileName=pbCheckPokemonBitmapFiles([species,back,female,shiny,form,shadow[COLOR="black"],delta[/COLOR]])
      end
      if bitmapFileName
        ret=AnimatedBitmap.new(bitmapFileName)
      end
      return ret
    end
    
    def pbCheckPokemonBitmapFiles(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
      factors.push([6,params[6],false]) if params[6] && params[6]!=false     # delta
      tshadow=false
      tgender=false
      tshiny=false[B]
      tdelta=false[/B]
      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]
          when 6   # [B]delta[/B]
            [B]tdelta[/B]=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
          end
        end
        folder=""
        if defined?(DUALSCREENHEIGHT) # if BW data exists
          folder="Front/"  
          folder="Back/" if back
          folder="FrontShiny/" if tshiny
          folder="BackShiny/" if back && tshiny    
          folder+="Female/" if tgender
        end
        bitmapFileName=sprintf("Graphics/Battlers/%s%s%s%s%s%s%s%s",
           folder,
           getConstantName(PBSpecies,species),
           tgender ? "f" : "",
           tshiny ? "s" : "",
           [B]tdelta[/B] ? "[COLOR="Red"]d[/COLOR]" : "",
           back ? "b" : "",
           (tform!="" ? "_"+tform : ""),
           tshadow ? "_shadow" : "") rescue nil
        ret=pbResolveBitmap(bitmapFileName)
        return ret if ret
        bitmapFileName=sprintf("Graphics/Battlers/%s%03d%s%s%s%s%s%s",
           folder, species,
           tgender ? "f" : "",
           tshiny ? "s" : "",
           [B]tdelta[/B] ? "[COLOR="red"]d[/COLOR]" : "",
           back ? "b" : "",
           (tform!="" ? "_"+tform : ""),
           tshadow ? "_shadow" : "")
        ret=pbResolveBitmap(bitmapFileName)
        return ret if ret
      end
      return nil
    end
    
    def pbPokemonIconFile(pokemon)
      bitmapFileName=nil
      bitmapFileName=pbCheckPokemonIconFiles([pokemon.species,
                                              (pokemon.isFemale?),
                                              pokemon.isShiny?,
                                              (pokemon.form rescue 0),
                                              (pokemon.isShadow? rescue false)[B],
                                              pokemon.isDelta?[/B]],
                                              pokemon.isEgg?)
      return bitmapFileName
    end
    
    def pbCheckPokemonIconFiles(params,egg=false)
      species=params[0]
      if egg
        bitmapFileName=sprintf("Graphics/Icons/icon%segg",getConstantName(PBSpecies,species)) rescue nil
        if !pbResolveBitmap(bitmapFileName)
          bitmapFileName=sprintf("Graphics/Icons/icon%03degg",species) 
          if !pbResolveBitmap(bitmapFileName)
            bitmapFileName=sprintf("Graphics/Icons/iconEgg")
          end
        end
        return pbResolveBitmap(bitmapFileName)
      else
        factors=[]
        factors.push([4,params[4],false]) if params[4] && params[4]!=false     # shadow
        factors.push([1,params[1],false]) if params[1] && params[1]!=false     # gender
        factors.push([2,params[2],false]) if params[2] && params[2]!=false     # shiny
        factors.push([5,params[5],false]) if params[5] && params[5]!=false     # [B]delta[/B]
        factors.push([3,params[3].to_s,""]) if params[3] && params[3].to_s!="" &&
                                                            params[3].to_s!="0" # form
        tshadow=false
        tgender=false
        tshiny=false
        [B]tdelta[/B]=false
        tform=""
        for i in 0...2**factors.length
          for j in 0...factors.length
            case factors[j][0]
            when 1   # gender
              tgender=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
            when 2   # shiny
              tshiny=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
            when 3   # form
              tform=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
            when 4   # shadow
              tshadow=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
            when 5   # [B]delta
              tdelta[/B]=((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
            end
          end
          bitmapFileName=sprintf("Graphics/Icons/icon%s%s%s%s%s%s",
             getConstantName(PBSpecies,species),
             tgender ? "f" : "",
             tshiny ? "s" : "",
             [B]tdelta[/B] ? "[COLOR="red"]d[/COLOR]" : "",
             (tform!="" ? "_"+tform : ""),
             tshadow ? "_shadow" : "") rescue nil
          ret=pbResolveBitmap(bitmapFileName)
          return ret if ret
          bitmapFileName=sprintf("Graphics/Icons/icon%03d%s%s%s%s%s",
             species,
             tgender ? "f" : "",
             tshiny ? "s" : "",
             [B]tdelta[/B] ? "[COLOR="red"]d[/COLOR]" : "",
             (tform!="" ? "_"+tform : ""),
             tshadow ? "_shadow" : "")
          ret=pbResolveBitmap(bitmapFileName)
          return ret if ret
        end
      end
      return nil
    end

    I hope you can figure out how to adapt it to your needs
     
    Last edited:
    Ahh thank you! You're my hero haha! x3
     
    Last edited:
    Back
    Top