Thread: [Essentials Script] Pokemon Birthsigns
View Single Post
  #207    
Old October 11th, 2018 (7:22 AM).
Lucidious89 Lucidious89 is offline
     
    Join Date: Apr 2014
    Gender: Male
    Posts: 208
    Quote:
    Originally Posted by Marin View Post
    I hope this has made it a little more clear. If not, you could try looking at what alias is and how it's used online.
    Yes, I think this helped out a lot. By using what you wrote, and looking at other examples in the script, I ended up changing the original code:
    Code:
    def initialize(species,level,player=nil,withMoves=true)
        if species.is_a?(String) || species.is_a?(Symbol)
          species = getID(PBSpecies,species)
        end
        cname = getConstantName(PBSpecies,species) rescue nil
        if !species || species<1 || species>PBSpecies.maxValue || !cname
          raise ArgumentError.new(_INTL("The species number (no. {1} of {2}) is invalid.",species,PBSpecies.maxValue))
          return nil
        end
        @species       = species
        @name          = PBSpecies.getName(@species)
        @personalID    = rand(256)
        @personalID    |= rand(256)<<8
        @personalID    |= rand(256)<<16
        @personalID    |= rand(256)<<24
        @hp            = 1
        @totalhp       = 1
        @ev            = [0,0,0,0,0,0]
        @iv            = []
        for i in 0...6
          @iv[i]       = rand(32)
        end
        @moves         = []
        @status        = 0
        @statusCount   = 0
        @item          = 0
        @mail          = nil
        @fused         = nil
        @ribbons       = []
        @ballused      = 0
        @eggsteps      = 0
        #===========================================================================
        # Newly generated Pokemon have all flags set to neutral
        #===========================================================================
        @zodiacflag    = 0
        @leafflag      = 0
        @celestial     = false
        @blessed       = false
        #===========================================================================
        if player
          @trainerID   = player.id
          @ot          = player.name
          @otgender    = player.gender
          @language    = player.language
        else
          @trainerID   = 0
          @ot          = ""
          @otgender    = 2
        end
        if $game_map
          @obtainMap   = $game_map.map_id
          @obtainText  = nil
          @obtainLevel = level
        else
          @obtainMap   = 0
          @obtainText  = nil
          @obtainLevel = level
        end
        @obtainMode    = 0   # Met
        @obtainMode    = 4 if $game_switches && $game_switches[FATEFUL_ENCOUNTER_SWITCH]
        @hatchedMap    = 0
        @timeReceived  = pbGetTimeNow.to_i
        self.level     = level
        calcStats
        @hp            = @totalhp
        dexdata = pbOpenDexData
        pbDexDataOffset(dexdata,self.fSpecies,19)
        @happiness     = dexdata.fgetb
        dexdata.close
        if withMoves
          self.resetMoves
        else
          for i in 0...4
            @moves[i] = PBMove.new(0)
          end
        end
      end


    into this updated code:
    Code:
    alias birthsign_initialize initialize  
      def initialize(*args)
        birthsign_initialize(*args)
        #===========================================================================
        # Newly generated Pokemon have all flags set to neutral
        #===========================================================================
        @zodiacflag    = 0
        @leafflag      = 0
        @celestial     = false
        @blessed       = false
        #===========================================================================
      end

    Everything seems to work as intended. I tested this out against wild Unown, and I can see the difference. Previously, the way I had the code set up before would only spawn Unown in their default "A" form. But now they properly spawn in randomized forms. Ill update my script in the link with these changes. Perhaps there are other areas of my scripts I can utilize aliasing with to condense the code a bit?
    Reply With Quote