Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old August 20th, 2014 (5:23 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
     
    Join Date: Sep 2010
    Gender: Male
    Posts: 1,692
    Code:
    #===============================================================================
    # * Egg Hatch Animation - by FL (Credits will be apreciated)
    #===============================================================================
    #
    # This script is for Pokémon Essentials. It's a egg hatch animation that
    # works even with special eggs like Manaphy egg.
    #
    #===============================================================================
    #
    # To this script works, put it above main and put a picture (a 5 frames
    # sprite sheet) with egg sprite height and 5 times the egg sprite width at
    # Graphics/Pictures/hatchsheet.
    #
    #===============================================================================
    
    class PokemonEggHatchScene
      def pbStartScene(pokemon)
        @sprites={} 
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @pokemon=pokemon
        @pokemon.eggsteps=1 # Just for drawing the egg
        addBackgroundOrColoredPlane(@sprites,"background","evolutionbg",
           Color.new(248,248,248),@viewport)
        @sprites["pokemon"]=PokemonSprite.new(@viewport)
        @sprites["pokemon"].setPokemonBitmap(@pokemon)
        @sprites["pokemon"].[email protected]["pokemon"].bitmap.width/2
        @sprites["pokemon"].[email protected]["pokemon"].bitmap.height/2
        @sprites["hatch"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
        @sprites["msgwindow"]=Kernel.pbCreateMessageWindow(@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
        # Initialize the pokémon
        @pokemon.eggsteps=0
        @pokemon.name=PBSpecies.getName(@pokemon.species)
        @pokemon.trainerID=$Trainer.id
        @pokemon.ot=$Trainer.name
        @pokemon.happiness=120
        @pokemon.timeEggHatched=pbGetTimeNow
        @pokemon.obtainMode=1 # hatched from egg
        @pokemon.hatchedMap=$game_map.map_id
        pbFadeInAndShow(@sprites)
      end
    
      def pbMain
        hatchSheet=AnimatedBitmap.new(_INTL("Graphics/Pictures/hatchsheet"))
        pbBGMPlay("evolv")
        # Egg animation
        updateScene(60)
        pbPositionHatchMask(hatchSheet,0)
        pbSEPlay("ballshake")
        swingEgg(2)
        updateScene(12)
        pbPositionHatchMask(hatchSheet,1)
        pbSEPlay("ballshake")
        swingEgg(2)
        updateScene(24)
        pbPositionHatchMask(hatchSheet,2)
        pbSEPlay("ballshake")
        swingEgg(4,2)
        updateScene(6)
        pbPositionHatchMask(hatchSheet,3)
        pbSEPlay("ballshake")
        swingEgg(8,4)
        updateScene(6)
        pbPositionHatchMask(hatchSheet,4)
        pbSEPlay("recall")
        # Fade and change the sprite
        fadeSpeed=15
        for i in 1..(255/fadeSpeed)
          @sprites["overlay"].opacity=i*fadeSpeed
          updateScene
        end  
        updateScene(40)
        @sprites["pokemon"].setPokemonBitmap(@pokemon)
        @sprites["hatch"].visible=false
        for i in 1..(255/fadeSpeed)
          @sprites["overlay"].opacity=255-i*fadeSpeed
          updateScene
        end
        # Finish scene
        frames=pbCryFrameLength(@newspecies)
        pbBGMStop()
        pbPlayCry(@pokemon)
        frames.times do
          Graphics.update
        end
        pbMEPlay("004-Victory04")
        speciesname = @pokemon.name
        Kernel.pbMessageDisplay(@sprites["msgwindow"],
           _INTL("\\se[]{1} hatched from the Egg!\\wt[80]",speciesname))
        $Trainer.seen[@pokemon.species]=true
        $Trainer.owned[@pokemon.species]=true
        pbSeenForm(@pokemon)
        if Kernel.pbConfirmMessage(
            _INTL("Would you like to nickname the newly hatched {1}?",speciesname))
          nickname=pbEnterText(_INTL("{1}'s nickname?",speciesname),0,10)
          pokemon.name=nickname if nickname!=""
        end
        @sprites["msgwindow"].text=""
      end
      
      def pbPositionHatchMask(hatchSheet,index)
        frames = 5
        frameWidth = hatchSheet.width/frames
        rect = Rect.new(frameWidth*index,0,frameWidth,hatchSheet.height)
        @sprites["hatch"].bitmap.blt(@sprites["pokemon"].x,@sprites["pokemon"].y,
            hatchSheet.bitmap,rect)
      end  
          
      def swingEgg(speed,swingTimes=1) # Only accepts 2, 4 or 8 for speed.
        limit = 8
        targets = [@sprites["pokemon"].x-limit,@sprites["pokemon"].x+limit,
            @sprites["pokemon"].x]
        swingTimes.times do   
          usedSpeed=speed
          for target in targets
            usedSpeed*=-1    
            while(target != @sprites["pokemon"].x)
              @sprites["pokemon"].x+=usedSpeed
              @sprites["hatch"].x+=usedSpeed
              updateScene
            end  
          end
        end
      end  
    
      def updateScene(frames=1) # Can be used for "wait" effect
        frames.times do
          Graphics.update
          Input.update
          self.update
        end
      end  
      
      def update
        pbUpdateSpriteHash(@sprites)
      end
      
      def pbEndScene
        Kernel.pbDisposeMessageWindow(@sprites["msgwindow"])
        pbFadeOutAndHide(@sprites) { update }
        pbDisposeSpriteHash(@sprites)
        @viewport.dispose
      end
    end
    
    class PokemonEggHatchScreen
      def initialize(scene)
        @scene=scene
      end
    
      def pbStartScreen(pokemon)
        @scene.pbStartScene(pokemon)
        @scene.pbMain
        @scene.pbEndScene
      end
    end
    
    def pbHatch(pokemon)
      Kernel.pbMessage(_INTL("Huh?\1"))
      pbFadeOutIn(99999) {
        scene=PokemonEggHatchScene.new
        screen=PokemonEggHatchScreen.new(scene)
        screen.pbStartScreen(pokemon)
      }
    end
    Attached Thumbnails
    hatchsheet.png‎   egghatchscreen.png‎  
    __________________
    Reply With Quote

    Relevant Advertising!

      #2    
    Old August 20th, 2014 (12:33 PM).
    Lexxilion's Avatar
    Lexxilion Lexxilion is offline
       
      Join Date: Jul 2014
      Gender: Male
      Nature: Careful
      Posts: 63
      I'm looking forward to using this and testing it out =] You are better equipped for this than me =]
      Reply With Quote
        #3    
      Old September 27th, 2014 (8:07 AM).
      xTHx's Avatar
      xTHx xTHx is offline
         
        Join Date: Dec 2013
        Gender: Male
        Nature: Calm
        Posts: 15
        Hey FL!
        You script have an error on the line 51, and that makes the game end.
        Reply With Quote
          #4    
        Old September 27th, 2014 (8:30 AM).
        mej71's Avatar
        mej71 mej71 is offline
        • Moderator
         
        Join Date: Mar 2014
        Location: Omnipresence
        Gender: Male
        Posts: 1,202
        Quote:
        Originally Posted by xTHx View Post
        Hey FL!
        You script have an error on the line 51, and that makes the game end.
        Nope, that'd be the forum's formatting that messes up code. Click Thread Tools, and then Show Printable Version, and copy that instead.
        Reply With Quote
          #5    
        Old September 28th, 2014 (1:16 PM).
        DrimerDS's Avatar
        DrimerDS DrimerDS is offline
           
          Join Date: Aug 2014
          Location: México
          Gender: Male
          Nature: Calm
          Posts: 20
          Pokémon Essentials does not include a hatch anim?
          When i test ur code i'll edit my message
          __________________
          Reply With Quote
            #6    
          Old October 2nd, 2014 (4:12 AM).
          FL's Avatar
          FL FL is offline
          Pokémon Island Creator
             
            Join Date: Sep 2010
            Gender: Male
            Posts: 1,692
            Quote:
            Originally Posted by Drimer View Post
            Pokémon Essentials does not include a hatch anim?
            When i test ur code i'll edit my message
            Few hours after your post, Essentials v14 came with this script integrated.
            __________________
            Reply With Quote
              #7    
            Old December 30th, 2014 (4:10 AM).
            Jacopo Mii Jacopo Mii is offline
               
              Join Date: May 2014
              Gender: Male
              Posts: 18
              How can I change the script to use a different image for the egg?
              Reply With Quote
                #8    
              Old December 30th, 2014 (7:14 AM).
              Savordez's Avatar
              Savordez Savordez is offline
              How does my profile have over 700 views like seriously
                 
                Join Date: Dec 2013
                Location: dunno
                Gender: Male
                Nature: Relaxed
                Posts: 106
                If you're using essentials v14, the egg sprite can be found in Battlers\egg.png.
                __________________
                Reply With Quote
                  #9    
                Old December 30th, 2014 (10:38 AM).
                Jacopo Mii Jacopo Mii is offline
                   
                  Join Date: May 2014
                  Gender: Male
                  Posts: 18
                  Yes, I already know this
                  But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
                  How can I do?
                  Reply With Quote
                    #10    
                  Old January 12th, 2015 (6:50 AM).
                  Jacopo Mii Jacopo Mii is offline
                     
                    Join Date: May 2014
                    Gender: Male
                    Posts: 18
                    Up (I am violating the rules of the forum? If yes, sorry )
                    Reply With Quote
                      #11    
                    Old January 13th, 2015 (3:08 PM).
                    FL's Avatar
                    FL FL is offline
                    Pokémon Island Creator
                       
                      Join Date: Sep 2010
                      Gender: Male
                      Posts: 1,692
                      Quote:
                      Originally Posted by Jacopo Mii View Post
                      Yes, I already know this
                      But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
                      How can I do?
                      Change first line [email protected]["pokemon"].setPokemonBitmap(@pokemon)' into [email protected]["pokemon"].bitmap=BitmapCache.load_bitmap("Graphics/Battlers/490egg")' (change for your egg path). You can change the image loaded checking @pokemon variable attributes (like @pokemon.species).
                      __________________
                      Reply With Quote
                        #12    
                      Old January 18th, 2015 (4:09 AM).
                      Enigmatic Emolga's Avatar
                      Enigmatic Emolga Enigmatic Emolga is offline
                      L'énigmatique
                         
                        Join Date: Oct 2012
                        Location: Somewhere in England
                        Gender: Male
                        Nature: Naive
                        Posts: 30
                        After an egg hatches, the BGM of the map the player is in doesn't start playing again unless the player leaves and re-enters the map. Any way to fix this?
                        __________________
                        Emolga: The Sky Squirrel Pokémon

                        Black: The energy made in its cheeks' electric pouches is stored inside its membranes and released while it is gliding.
                        White: They live on treetops and glide using the inside of a cape-like membrane while discharging electricity.

                        Youtube
                        deviantArt
                        Reply With Quote
                          #13    
                        Old January 18th, 2015 (4:36 AM).
                        FL's Avatar
                        FL FL is offline
                        Pokémon Island Creator
                           
                          Join Date: Sep 2010
                          Gender: Male
                          Posts: 1,692
                          Quote:
                          Originally Posted by Enigmatic Emolga View Post
                          After an egg hatches, the BGM of the map the player is in doesn't start playing again unless the player leaves and re-enters the map. Any way to fix this?
                          After line 'def pbEndScene' add line '$game_map.autoplay'.
                          __________________
                          Reply With Quote
                          Reply
                          Quick Reply

                          Sponsored Links
                          Thread Tools

                          Posting Rules
                          You may not post new threads
                          You may not post replies
                          You may not post attachments
                          You may not edit your posts

                          BB code is On
                          Smilies are On
                          [IMG] code is On
                          HTML code is Off

                          Forum Jump


                          All times are GMT -8. The time now is 5:20 AM.