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

Pokemon Contest scripts (in development)

  • 1,224
    Posts
    10
    Years
    This is not yet even close to a completed script, posting it here so that others who have expressed interest can view it and collaborate (since it goes over the character limit of most forums). Feel free to use this as a basis for your own/ give input on mine. I will update this post as I move forward in the coding. Will move to the scripts and tutorials section when it becomes more complete.

    What the script currently does: lets you determine opponent pokemon and lets you choose yours to enter in the contest. Does an intro sort of thing. Goes through a first round using randomly selected moves of the pokemon (user move selection coming soon), though it does output any scoring for the moves nor the move animations yet.

    What it doesn't do: A lot

    Update 1: Displays hearts based on the moves base damage/20, or gives it one heart if the basedamage is 0

    You need these for it to work. Name each of them "hearts_.png", the _ being the number of hearts there are, including zero.

    Code:
    class PokeContestScene
      attr_reader :index
      attr_reader :name
      attr_accessor :selected
      attr_reader(:basedamage)
      
      def update
        pbUpdateSpriteHash(@sprites)
      end
      def pbStartContest(chosen,opponent1,opponent1level,opponent2,opponent2level,opponent3,opponent3level)
        pbBGMPlay("021-Field04")
        @lastcmd=[0,0,0,0]
        @pkmn1=$Trainer.party[chosen]
        @pkmn2=PokeBattle_Pokemon.new(opponent1,opponent1level,$Trainer)
        @pkmn3=PokeBattle_Pokemon.new(opponent2,opponent2level,$Trainer)
        @pkmn4=PokeBattle_Pokemon.new(opponent3,opponent3level,$Trainer)
        @pkmn2.form=0
        @pkmn3.form=0
        @pkmn4.form=0
        @fastest=@pkmn1
        @second=@pkmn2
        @third=@pkmn3
        @fourth=@pkmn4
        @firstnumber=0
        @secondnumber=0
        @thirdnumber=0
        @fourthnumber=0
        @pkmn1hearts=0
        @pkmn2hearts=0
        @pkmn3hearts=0
        @pkmn4hearts=0
        @sprites["Judge"]=IconSprite.new(0,0,@viewport)
        @sprites["Judge"].setBitmap("Graphics/Characters/trainer017")
        Kernel.pbMessage(_INTL("Judge: \\c[1]Welcome to today's Pokemon Contest\nIt's heartwarming to see all these young trainers here to show off their Pokemon's skills!")) #add variable to say contest type later
        Kernel.pbMessage(_INTL("\\c[1]I'm going to be the judge for this competition, so let's get started!"))
        pbDisposeSprite(@sprites,"Judge")
        sleep(1.0/3.0)
        Graphics.update
        @sprites["RoundOne"]=IconSprite.new(0,0,@viewport)
        @sprites["RoundOne"].setBitmap("Graphics/Pictures/Contest/Roundone")
        sleep(1.0/2.0)
        Graphics.update
        roundoneupdown=0
        for i in 0...9
          if roundoneupdown==0 or roundoneupdown==1 or roundoneupdown==4 or roundoneupdown==5 or roundoneupdown==8 or roundoneupdown==9
        @sprites["RoundOne"].y+=6
         else
        @sprites["RoundOne"].y-=6
         end
        roundoneupdown+=1
        Graphics.update
        sleep(1.0/8.0)
        end
        sleep(1)
        pbDisposeSprite(@sprites,"RoundOne")
        @sprites["overlay"]=BitmapSprite.new(
        Graphics.width,Graphics.height,@viewport)
        pbSetSystemFont(@sprites["overlay"].bitmap)
        pbFindFastestOrderRanking
        pbDisplayFastest
        pbDrawTextRoundOne
        Kernel.pbMessage(_INTL("Judge: \\c[1]Alright {1}, let's see what you can do!",@fastest.name))
        i=rand(@fastest.moves.length)
        movedata=PBMoveData.new(@fastest.moves[i].id)
        @currentbasedamage=movedata.basedamage
        @currentpoke=@fastest
        @currentmove=PBMoves.getName(@fastest.moves[i].id)
        Kernel.pbMessage(_INTL("{1} used {2}",@fastest.name,@currentmove))
        @fastestlastmove=@currentmove
        pbHearts
        pbAssignHearts
        pbDisplayAddingPositiveHearts
        Graphics.update
        sleep(1.0/10.0)
        Kernel.pbMessage(_INTL("Judge: \\c[1]Good job {1}, now onto the next pokemon!",@fastest.name))
        sleep(1.0/10.0)
        pbDisposeSprite(@sprites,"pokemon#{@firstnumber}")
        Graphics.update
        sleep(1.0/10.0)
        Kernel.pbMessage(_INTL("Judge: \\c[1]Next up we have {1}!",@second.name))
        pbDisplaySecondFastest
        Graphics.update
        sleep(1.0/10.0)
        i=rand(@second.moves.length)
        movedata=PBMoveData.new(@second.moves[i].id)
        @currentbasedamage=movedata.basedamage
        @currentpoke=@second
        @currentmove=PBMoves.getName(@second.moves[i].id)
        Kernel.pbMessage(_INTL("{1} used {2}",@second.name,@currentmove))
        @secondlastmove=@currentmove
        pbHearts
        pbAssignHearts
        pbDisplayAddingPositiveHearts
        Graphics.update
        sleep(1.0/10.0)
        pbDisposeSprite(@sprites,"pokemon#{@secondnumber}")
        Graphics.update
        sleep(1.0/10.0)
        Kernel.pbMessage(_INTL("Judge: \\c[1]Next up we have {1}!",@third.name))
        pbDisplayThirdFastest
        Graphics.update
        sleep(1.0/10.0)
        i=rand(@third.moves.length)
        movedata=PBMoveData.new(@third.moves[i].id)
        @currentbasedamage=movedata.basedamage
        @currentpoke=@third
        @currentmove=PBMoves.getName(@third.moves[i].id)
        Kernel.pbMessage(_INTL("{1} used {2}",@third.name,@currentmove))
        @thirdlastmove=@currentmove
         pbHearts
        pbAssignHearts
        pbDisplayAddingPositiveHearts
        Graphics.update
        sleep(1.0/10.0)
        pbDisposeSprite(@sprites,"pokemon#{@thirdnumber}")
        Graphics.update
        sleep(1.0/10.0)
        Kernel.pbMessage(_INTL("Judge: \\c[1]Next up we have {1}!",@fourth.name))
        pbDisplayFourthFastest
        Graphics.update
        sleep(1.0/10.0)
        i=rand(@fourth.moves.length)
        movedata=PBMoveData.new(@fourth.moves[i].id)
        @currentbasedamage=movedata.basedamage
        @currentpoke=@fourth
        @currentmove=PBMoves.getName(@fourth.moves[i].id)
        Kernel.pbMessage(_INTL("{1} used {2}",@fourth.name,@currentmove))
        @fourthlastmove=@currentmove
         pbHearts
        pbAssignHearts
        pbDisplayAddingPositiveHearts
        Graphics.update
        sleep(1.0/10.0)
      end
      def pbAssignHearts
        if @currentpoke==@pkmn1
          @pkmn1hearts=@hearts
        elsif @currentpoke==@pkmn2
          @pkmn2hearts=@hearts
        elsif @currentpoke==@pkmn3
          @pkmn3hearts=@hearts
        else
          @pkmn4hearts=@hearts
        end
      end
      
      def pbDrawTextRoundOne
        overlay=@sprites["overlay"].bitmap
        overlay.clear 
        pokeone=_INTL("{1}",@fastest.name)
        poketwo=_INTL("{1}",@second.name)
        pokethree=_INTL("{1}",@third.name)
        pokefour=_INTL("{1}",@fourth.name)
        baseColor=Color.new(72,72,72)
        shadowColor=Color.new(160,160,160)
        textPositions=[
           [pokeone,353,5,false,baseColor,shadowColor],
           [poketwo,353,100,false,baseColor,shadowColor],
           [pokethree,353,195,false,baseColor,shadowColor],
           [pokefour,353,290,false,baseColor,shadowColor],
        ]
        pbDrawTextPositions(overlay,textPositions)
      end
      
      def initialize
        @sprites={} 
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @sprites["background"]=IconSprite.new(0,0,@viewport)
        @sprites["background"].setBitmap("Graphics/Pictures/Contest/contestbg")
      end
      def pbInputUpdate
        Input.update
        if Input.trigger?(Input::B) && @abortable && !@aborted
          @aborted=true
          @battle.pbAbort
        end
      end
      
      def pbHearts
        if @currentbasedamage>0
        @hearts=(@currentbasedamage/20).floor+ 1
        else @hearts=1
        end
      end
      
      def pbDisplayAddingPositiveHearts
        if @currentpoke==@pkmn1
          if @currentpoke==@fastest
             for i in 0..@pkmn1hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["firstpokehearts"]=IconSprite.new(408,51,@viewport)
            @sprites["firstpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@second
           for i in 0..@pkmn1hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["secondpokehearts"]=IconSprite.new(408,145,@viewport)
            @sprites["scondepokehearts"].setBitmap(heartfile)
            i+=1
          end
          elsif @currentpoke==@third
           for i in 0..@pkmn1hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["thirdpokehearts"]=IconSprite.new(408,241,@viewport)
            @sprites["thirdpokehearts"].setBitmap(heartfile)
            i+=1
          end
        else
           for i in 0..@pkmn1hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["fourthpokehearts"]=IconSprite.new(358,336,@viewport)
            @sprites["fourthpokehearts"].setBitmap(heartfile)
            i+=1
          end
        end
      elsif @currentpoke==@pkmn2
        if @currentpoke==@fastest
            for i in 0..@pkmn2hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["firstpokehearts"]=IconSprite.new(408,51,@viewport)
            @sprites["firstpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@second
          for i in 0..@pkmn2hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["secondpokehearts"]=IconSprite.new(408,145,@viewport)
            @sprites["secondpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@third
          for i in 0..@pkmn2hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["thirdpokehearts"]=IconSprite.new(408,241,@viewport)
            @sprites["thirdpokehearts"].setBitmap(heartfile)
            i+=1
          end
        else
          for i in 0..@pkmn2hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["fourthpokehearts"]=IconSprite.new(408,336,@viewport)
            @sprites["fourthpokehearts"].setBitmap(heartfile)
            i+=1
          end
        end
    elsif @currentpoke==@pkmn3
        if @currentpoke==@fastest
            for i in 0..@pkmn3hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["firstpokehearts"]=IconSprite.new(408,51,@viewport)
            @sprites["firstpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@second
          for i in 0..@pkmn3hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["secondpokehearts"]=IconSprite.new(408,145,@viewport)
            @sprites["secondpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@third
          for i in 0..@pkmn3hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["thirdpokehearts"]=IconSprite.new(408,241,@viewport)
            @sprites["thirdpokehearts"].setBitmap(heartfile)
            i+=1
          end
        else
          for i in 0..@pkmn3hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["fourthpokehearts"]=IconSprite.new(408,336,@viewport)
            @sprites["fourthpokehearts"].setBitmap(heartfile)
            i+=1
          end
        end
      else
        if @currentpoke==@fastest
            for i in 0..@pkmn4hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["firstpokehearts"]=IconSprite.new(408,151,@viewport)
            @sprites["firstpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@second
          for i in 0..@pkmn4hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["secondpokehearts"]=IconSprite.new(408,145,@viewport)
            @sprites["secondpokehearts"].setBitmap(heartfile)
            i+=1
          end
        elsif @currentpoke==@third
          for i in 0..@pkmn4hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["thirdpokehearts"]=IconSprite.new(408,241,@viewport)
            @sprites["thirdpokehearts"].setBitmap(heartfile)
            i+=1
          end
        else
          for i in 0..@pkmn4hearts
              heartfile=sprintf("Graphics/Pictures/Contest/heart%d",i)
            Graphics.update
            sleep(1.0/7.0)
            @sprites["fourthpokehearts"]=IconSprite.new(408,336,@viewport)
            @sprites["fourthpokehearts"].setBitmap(heartfile)
            i+=1
          end
        end
      end
    end
      
     def pbFindFastestOrderRanking  #Finds the fastest pokemon in the contest
       dexdata=pbOpenDexData
       pbDexDataOffset(dexdata,@pkmn1.species,13)
       basespeed1=dexdata.fgetb
       pokespeed1=basespeed1
       pbDexDataOffset(dexdata,@pkmn2.species,13)
       basespeed2=dexdata.fgetb
       pokespeed2=basespeed2
       pbDexDataOffset(dexdata,@pkmn3.species,13)
       basespeed3=dexdata.fgetb
       pokespeed3=basespeed3
       pbDexDataOffset(dexdata,@pkmn4.species,13)
       basespeed4=dexdata.fgetb
       pokespeed4=basespeed4
       dexdata.close
       fastest = [basespeed1, basespeed2, basespeed3, basespeed4]
       fastest=fastest.sort.reverse
      @firstnumber=(fastest[0]== pokespeed1)? 1 : ((fastest[0]==pokespeed2) ? 2 : ((fastest[0]==pokespeed3)? 3: 4))
      @fastest=(fastest[0]== pokespeed1)? @pkmn1 : ((fastest[0]==pokespeed2) ? @pkmn2 : ((fastest[0]==pokespeed3)? @pkmn3 : @pkmn4))
      @secondnumber=(fastest[1]== pokespeed1)? 1 : ((fastest[1]==pokespeed2) ? 2 : ((fastest[1]==pokespeed3)? 3: 4))
      @second=(fastest[1]== pokespeed1)? @pkmn1 : ((fastest[1]==pokespeed2) ? @pkmn2 : ((fastest[1]==pokespeed3)? @pkmn3 : @pkmn4))
      @thirdnumber=(fastest[2]== pokespeed1)? 1 : ((fastest[2]==pokespeed2) ? 2 : ((fastest[2]==pokespeed3)? 3: 4))
      @third=(fastest[2]== pokespeed1)? @pkmn1 : ((fastest[2]==pokespeed2) ? @pkmn2 : ((fastest[2]==pokespeed3)? @pkmn3 : @pkmn4))
      @fourthnumber=(fastest[3]== pokespeed1)? 1 : ((fastest[3]==pokespeed2) ? 2 : ((fastest[3]==pokespeed3)? 3: 4))
      @fourth=(fastest[3]== pokespeed1)? @pkmn1 : ((fastest[3]==pokespeed2) ? @pkmn2 : ((fastest[3]==pokespeed3)? @pkmn3 : @pkmn4))
    end
    
    def pbDisplayFastest  #Displays the sprite of the fastest pokemon, as per FindFastest
      @sprites["pokemon#{@firstnumber}"]=PokemonSprite.new(@viewport)
        @sprites["pokemon#{@firstnumber}"].setPokemonBitmap(@fastest,true)
        @sprites["pokemon#{@firstnumber}"].mirror=true
        pokemony=Graphics.height/2-32
        pokemonyadjust=pokemony-32 
        pbPositionPokemonSprite(@sprites["pokemon#{@firstnumber}"],178,112)
    end
    def pbDisplaySecondFastest
      @sprites["pokemon#{@secondnumber}"]=PokemonSprite.new(@viewport)
        @sprites["pokemon#{@secondnumber}"].setPokemonBitmap(@second,true)
        @sprites["pokemon#{@secondnumber}"].mirror=true
        pokemony=Graphics.height/2-32
        pokemonyadjust=pokemony-32 
        pbPositionPokemonSprite(@sprites["pokemon#{@secondnumber}"],178,112)
      end
      def pbDisplayThirdFastest
      @sprites["pokemon#{@thirdnumber}"]=PokemonSprite.new(@viewport)
        @sprites["pokemon#{@thirdnumber}"].setPokemonBitmap(@third,true)
        @sprites["pokemon#{@thirdnumber}"].mirror=true
        pokemony=Graphics.height/2-32
        pokemonyadjust=pokemony-32 
        pbPositionPokemonSprite(@sprites["pokemon#{@thirdnumber}"],178,112)
      end
      def pbDisplayFourthFastest
      @sprites["pokemon#{@fourthnumber}"]=PokemonSprite.new(@viewport)
        @sprites["pokemon#{@fourthnumber}"].setPokemonBitmap(@fourth,true)
        @sprites["pokemon#{@fourthnumber}"].mirror=true
        pokemony=Graphics.height/2-32
        pokemonyadjust=pokemony-32 
        pbPositionPokemonSprite(@sprites["pokemon#{@fourthnumber}"],178,112)
      end
      
      def pbMoveButtons
        pokemon=@pkmn1
        pokename=pokemon.name
      @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
      @viewport.z=99999
      @sprites["moves"]=IconSprite.new(0,257,@viewport)
      @sprites["moves"].setBitmap("Graphics/Pictures/Contest/moves")
      base=Color.new(248,248,248)
        shadow=Color.new(104,104,104)
        @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
        overlay=@sprites["overlay"].bitmap
        pbSetSmallFont(overlay)
      textpos=[
           [_INTL("MOVES"),12,225,0,base,shadow]]
      imagepos=[]
        yPos=258
        xPos=2
        count=0
        for i in 0...pokemon.moves.length
          if pokemon.moves[i].id>0 
            imagepos.push(["Graphics/Pictures/types",xPos,yPos+2,0,
               pokemon.moves[i].type*28,64,28])
            textpos.push([PBMoves.getName(pokemon.moves[i].id),xPos+68,yPos+2,0,
               Color.new(64,64,64),Color.new(176,176,176)])
          else
            textpos.push(["-",316,yPos,0,Color.new(64,64,64),Color.new(176,176,176)])
          end
          count=count+1
          yPos+=64 if count<=1
          yPos=258 if count==2
          yPos=322 if count==3
          xPos=170 if count>1
        end
      pbDrawTextPositions(overlay,textpos)
      pbDrawImagePositions(overlay,imagepos)
      end
      def pbEndScene
        $game_map.autoplay
        pbFadeOutAndHide(@sprites) { update }
        pbDisposeSpriteHash(@sprites)
        @viewport.dispose
      end
      def middleScene
         loop do
        Graphics.update
        Input.update
        self.update
        if Input.trigger?(Input::C) 
          pbMoveButtons
        end 
         if Input.trigger?(Input::B)
           break
         end
         end
    end
    end
    
    class PokeContest
      def initialize(scene)
        @scene=scene
      end
    
      def pbStartContest(chosen,opponent1,opponent1level,opponent2,opponent2level,opponent3,opponent3level)
        @scene.pbStartContest(chosen,opponent1,opponent1level,opponent2,opponent2level,opponent3,opponent3level)
        @scene.middleScene
        @scene.pbEndScene
      end
    end
    
     
    def pbContest(opponent1,opponent1level,opponent2,opponent2level,opponent3,opponent3level)
      scene=PokemonScreen_Scene.new
      screen=PokemonScreen.new(scene,$Trainer.party)
      screen.pbStartScene(_INTL("Choose a Pokémon?"),false)
      chosen=screen.pbChoosePokemon
      if chosen>=0
      scene=PokeContestScene.new
      screen=PokeContest.new(scene)
      return screen.pbStartContest(chosen,opponent1,opponent1level,opponent2,opponent2level,opponent3,opponent3level)
    else
      return false
      end
    end

    You will need these , put them in a new folder in Graphics/Pictures named Contest. Name the files Roundone.png, contestbg.png, and moves.png respectively.

    As I said before, this is a work in progress. And I also know my coding is kinda messy, so I apologize if it is confusing. If this is the wrong section, please move it or delete it, but I did not see any other section that would be fit.
     
    Last edited:

    Nickalooose

    --------------------
  • 1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    Impressive, hope something comes off this... It's about time contests were worked on... In a past game I made Olympic Games... Running, Weight Training, Fighting, things like that basically... I probably could've made that public and you could've used that as a base, but no idea where that is anymore since I've started a new game which has zero need for this... If I find it and can contribute, I'll do so :D
     
  • 1,224
    Posts
    10
    Years
    So I'm thinking the easiest thing would be to edit the compiler so that you can assign the heart values , effects, and descriptions in moves.txt. That way it's user friendly to add in new moves and new contest effects.

    However, I've never touched the compiler before, so I don't quite know where to begin. Anybody know how to help me or point me in the right direction there?
     

    Nickalooose

    --------------------
  • 1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    You can search record[12] or any number less than that really, in Compiler... Once you're there, it's pretty straight forward, I can't help you any further than that I'm afraid because I have no idea how to work out the random letters you have to edit, but after you've figured that out, you should be able to edit the moves.txt to accompany that.
     
  • 1,224
    Posts
    10
    Years
    Here's what I believed the code should be changed into


    Code:
    class PBMoveDataOld
      attr_reader :function,:basedamage,:type,:accuracy
      attr_reader :totalpp,:addlEffect,:target,:priority
      attr_reader :flags
      attr_reader :contestType,:category
      attr_reader :hearts,:contestfunction
    
      def initialize(moveid)
        movedata=pbRgssOpen("Data/rsattacks.dat")
        movedata.pos=moveid*9
        @function=movedata.fgetb
        @basedamage=movedata.fgetb
        @type=movedata.fgetb
        @accuracy=movedata.fgetb
        @totalpp=movedata.fgetb
        @addlEffect=movedata.fgetb
        @target=movedata.fgetb
        @priority=movedata.fgetsb
        @flags=movedata.fgetb
        @hearts=movedata.fgetb
        @contestfunction=movedata.fgetb
        movedata.close
      end
    
      def category
        return 2 if @basedamage==0
        return @type<10 ? 0 : 1
      end
    end
    
    
    
    def pbCompileMoves
      records=[]
      movenames=[]
      movedescs=[]
      movedata=[]
      contestdesc=[]
      maxValue=0
      haveRsAttacks=pbRgssExists?("Data/rsattacks.dat")
      pbCompilerEachPreppedLine("PBS/moves.txt"){|line,lineno|
         thisline=line.clone
         record=[]
         flags=0
         begin
           record=pbGetCsvRecord(line,lineno,[0,"vnsxueeuuuxises",
              nil,nil,nil,nil,nil,PBTypes,["Physical","Special","Status"],
              nil,nil,nil,nil,nil,nil,["Cool","Beauty","Cute","Smart","Tough"],nil,nil,nil,nil
           ])
           pbCheckWord(record[3],_INTL("Function code"))
           flags|=1 if record[12][/a/]
           flags|=2 if record[12][/b/]
           flags|=4 if record[12][/c/]
           flags|=8 if record[12][/d/]
           flags|=16 if record[12][/e/]
           flags|=32 if record[12][/f/]
           flags|=64 if record[12][/g/]
           flags|=128 if record[12][/h/]
           flags|=256 if record[12][/i/]
           flags|=512 if record[12][/j/]
           flags|=1024 if record[12][/k/]
           flags|=2048 if record[12][/l/]
           flags|=4096 if record[12][/m/]
           flags|=8192 if record[12][/n/]
           flags|=16384 if record[12][/o/]
           flags|=32768 if record[12][/p/]
         rescue
           oldmessage=$!.message
           raise if !haveRsAttacks
           begin
             oldrecord=pbGetCsvRecord(thisline,lineno,[0,"unss",nil,nil,nil,nil])
           rescue
             raise $!.message+"\r\n"+oldmessage
           end
           oldmovedata=PBMoveDataOld.new(oldrecord[0])
           flags=oldmovedata.flags
           record=[oldrecord[0],oldrecord[1],oldrecord[2],
              oldmovedata.function,
              oldmovedata.basedamage,
              oldmovedata.type,
              oldmovedata.category,
              oldmovedata.accuracy,
              oldmovedata.totalpp,
              oldmovedata.addlEffect,
              oldmovedata.target,
              oldmovedata.priority,
              oldmovedata.flags,
              0, # No contest type defined
              oldrecord[3],
              oldmovedata.hearts,
              oldmovedata.contestfunction,
              oldrecord[4]]
         end
         pbCheckWord(record[3],_INTL("Function code"))
         pbCheckByte(record[4],_INTL("Base damage"))
         if record[6]==2 && record[4]!=0
           raise _INTL("Status moves must have a base damage of 0, use either Physical or Special\r\n{1}",FileLineData.linereport)
         end
         if record[6]!=2 && record[4]==0
           print _INTL(
              "Warning: Physical and special moves can't have a base damage of 0, changing to a Status move\r\n{1}",FileLineData.linereport)
           record[6]=2
         end
         pbCheckByte(record[7],_INTL("Accuracy"))
         pbCheckByte(record[8],_INTL("Total PP"))
         pbCheckByte(record[9],_INTL("Additional Effect"))
         pbCheckWord(record[10],_INTL("Target"))
         pbCheckSignedByte(record[11],_INTL("Priority"))
         pbCheckByte(record[15],_INTL("Hearts"))
         pbCheckByte(record[16],_INTL("Contest Function"))
         maxValue=[maxValue,record[0]].max
         movedata[record[0]]=[
            record[3],  # Function code
            record[4],  # Damage
            record[5],  # Type
            record[6],  # Category
            record[7],  # Accuracy
            record[8],  # Total PP
            record[9],  # Effect chance
            record[10], # Target
            record[11], # Priority
            flags,      # Flags
            record[13],  # Contest type
            record[15], #Hearts
            record[16]  #Contest Function
         ].pack("vCCCCCCvCvCCv")
         movenames[record[0]]=record[2]  # Name
         movedescs[record[0]]=record[14] # Description
         contestdescs[record[0]]=record[17] #Contest Description
         records.push(record)
      }
      defaultdata=[0,0,0,0,0,0,0,0,0,0,0,0,0].pack("vCCCCCCvCvCCv")
      File.open("Data/moves.dat","wb"){|file|
         for i in 0...movedata.length
           file.write(movedata[i] ? movedata[i] : defaultdata)
         end
      }
      MessageTypes.setMessages(MessageTypes::Moves,movenames)
      MessageTypes.setMessages(MessageTypes::MoveDescriptions,movedescs)
      code="class PBMoves\r\n"
      for rec in records
        code+="#{rec[1]}=#{rec[0]}\r\n"
      end
      code+="\r\ndef self.getName(id)\r\nreturn pbGetMessage(MessageTypes::Moves,id)\r\nend"
      code+="\r\ndef self.getCount\r\nreturn #{records.length}\r\nend"
      code+="\r\ndef self.maxValue\r\nreturn #{maxValue}\r\nend\r\nend"
      eval(code)
      pbAddScript(code,"PBMoves")
    end

    and here's the error I'm getting lol

    Code:
    Exception: NoMethodError
    Message: undefined method `<' for nil:NilClass
    Compiler:1105:in `pbCheckByte'
    Compiler:1242:in `pbCompileMoves'
    Compiler:1174:in `pbCompilerEachPreppedLine'
    Compiler:632:in `each_line'
    Compiler:632:in `pbCompilerEachPreppedLine'
    Compiler:629:in `open'
    Compiler:629:in `pbCompilerEachPreppedLine'
    Compiler:1174:in `pbCompileMoves'
    Compiler:3999:in `pbCompileAllData'
    Compiler:4129

    This error seems to occur before before it reads the .txt, so that's not the problem. And as far as my untrained eyes see, my code format resembles the rest so I'm not quite sure how to proceed.
     

    Derxwna Kapsyla

    Derxwna "The Badman" Kapsyla
  • 437
    Posts
    12
    Years
    So I'm thinking the easiest thing would be to edit the compiler so that you can assign the heart values , effects, and descriptions in moves.txt. That way it's user friendly to add in new moves and new contest effects.

    However, I've never touched the compiler before, so I don't quite know where to begin. Anybody know how to help me or point me in the right direction there?

    I personally wouldn't have it modify moves.txt, simply so compatibility when Essentials updates doesn't break if the Script isn't compatible with the newest version. I'd make something like contest.txe, where you define what each move does, as well as what it can combo with - That's another thing about contests you'd have to take into account, certain moves combo into one another. You don't want to define that in moves.txt, it'd start to get really messy. I would imagine a standard entry looking something like this:
    [WHIRLWIND]
    Description=02 ; As contests moves use preset descriptions, 02 would reference that specific description in the scripts for it. This particular one would say "Scrambles the contest order for the next round".
    Appeal=4 ; Self-explanatory; How many hearts the move gives out in the contest. Must be a Non-0 Value(?)
    Jam=1 ; Self-explanatory; How many hearts it detracts from the person who used a move before them. Can be set to a value of 0. If it fails it usually does nothing, except in the rare instances where it backfires and it causes the user to lose that amount of hearts on appeal. This was only present in RSE's contest system.
    Combos=SKYATTACK,GUST,WINGATTACK,HYPERBEAM,SPIKES
    I'm pretty sure that's all the relevant information for Contests... My friend is actually working on contests for his Rom Hack at present moment, so most of the information about how the contest structure works is fresh in mind.
     

    ~JV~

    Dev of Pokémon Uranium
  • 684
    Posts
    16
    Years
    Here's what I believed the code should be changed into


    Code:
    class PBMoveDataOld
      attr_reader :function,:basedamage,:type,:accuracy
      attr_reader :totalpp,:addlEffect,:target,:priority
      attr_reader :flags
      attr_reader :contestType,:category
      attr_reader :hearts,:contestfunction
    
      def initialize(moveid)
        movedata=pbRgssOpen("Data/rsattacks.dat")
        movedata.pos=moveid*9
        @function=movedata.fgetb
        @basedamage=movedata.fgetb
        @type=movedata.fgetb
        @accuracy=movedata.fgetb
        @totalpp=movedata.fgetb
        @addlEffect=movedata.fgetb
        @target=movedata.fgetb
        @priority=movedata.fgetsb
        @flags=movedata.fgetb
        @hearts=movedata.fgetb
        @contestfunction=movedata.fgetb
        movedata.close
      end
    
      def category
        return 2 if @basedamage==0
        return @type<10 ? 0 : 1
      end
    end
    
    
    
    def pbCompileMoves
      records=[]
      movenames=[]
      movedescs=[]
      movedata=[]
      contestdesc=[]
      maxValue=0
      haveRsAttacks=pbRgssExists?("Data/rsattacks.dat")
      pbCompilerEachPreppedLine("PBS/moves.txt"){|line,lineno|
         thisline=line.clone
         record=[]
         flags=0
         begin
           record=pbGetCsvRecord(line,lineno,[0,"vnsxueeuuuxises",
              nil,nil,nil,nil,nil,PBTypes,["Physical","Special","Status"],
              nil,nil,nil,nil,nil,nil,["Cool","Beauty","Cute","Smart","Tough"],nil,nil,nil,nil
           ])
           pbCheckWord(record[3],_INTL("Function code"))
           flags|=1 if record[12][/a/]
           flags|=2 if record[12][/b/]
           flags|=4 if record[12][/c/]
           flags|=8 if record[12][/d/]
           flags|=16 if record[12][/e/]
           flags|=32 if record[12][/f/]
           flags|=64 if record[12][/g/]
           flags|=128 if record[12][/h/]
           flags|=256 if record[12][/i/]
           flags|=512 if record[12][/j/]
           flags|=1024 if record[12][/k/]
           flags|=2048 if record[12][/l/]
           flags|=4096 if record[12][/m/]
           flags|=8192 if record[12][/n/]
           flags|=16384 if record[12][/o/]
           flags|=32768 if record[12][/p/]
         rescue
           oldmessage=$!.message
           raise if !haveRsAttacks
           begin
             oldrecord=pbGetCsvRecord(thisline,lineno,[0,"unss",nil,nil,nil,nil])
           rescue
             raise $!.message+"\r\n"+oldmessage
           end
           oldmovedata=PBMoveDataOld.new(oldrecord[0])
           flags=oldmovedata.flags
           record=[oldrecord[0],oldrecord[1],oldrecord[2],
              oldmovedata.function,
              oldmovedata.basedamage,
              oldmovedata.type,
              oldmovedata.category,
              oldmovedata.accuracy,
              oldmovedata.totalpp,
              oldmovedata.addlEffect,
              oldmovedata.target,
              oldmovedata.priority,
              oldmovedata.flags,
              0, # No contest type defined
              oldrecord[3],
              oldmovedata.hearts,
              oldmovedata.contestfunction,
              oldrecord[4]]
         end
         pbCheckWord(record[3],_INTL("Function code"))
         pbCheckByte(record[4],_INTL("Base damage"))
         if record[6]==2 && record[4]!=0
           raise _INTL("Status moves must have a base damage of 0, use either Physical or Special\r\n{1}",FileLineData.linereport)
         end
         if record[6]!=2 && record[4]==0
           print _INTL(
              "Warning: Physical and special moves can't have a base damage of 0, changing to a Status move\r\n{1}",FileLineData.linereport)
           record[6]=2
         end
         pbCheckByte(record[7],_INTL("Accuracy"))
         pbCheckByte(record[8],_INTL("Total PP"))
         pbCheckByte(record[9],_INTL("Additional Effect"))
         pbCheckWord(record[10],_INTL("Target"))
         pbCheckSignedByte(record[11],_INTL("Priority"))
         pbCheckByte(record[15],_INTL("Hearts"))
         pbCheckByte(record[16],_INTL("Contest Function"))
         maxValue=[maxValue,record[0]].max
         movedata[record[0]]=[
            record[3],  # Function code
            record[4],  # Damage
            record[5],  # Type
            record[6],  # Category
            record[7],  # Accuracy
            record[8],  # Total PP
            record[9],  # Effect chance
            record[10], # Target
            record[11], # Priority
            flags,      # Flags
            record[13],  # Contest type
            record[15], #Hearts
            record[16]  #Contest Function
         ].pack("vCCCCCCvCvCCv")
         movenames[record[0]]=record[2]  # Name
         movedescs[record[0]]=record[14] # Description
         contestdescs[record[0]]=record[17] #Contest Description
         records.push(record)
      }
      defaultdata=[0,0,0,0,0,0,0,0,0,0,0,0,0].pack("vCCCCCCvCvCCv")
      File.open("Data/moves.dat","wb"){|file|
         for i in 0...movedata.length
           file.write(movedata[i] ? movedata[i] : defaultdata)
         end
      }
      MessageTypes.setMessages(MessageTypes::Moves,movenames)
      MessageTypes.setMessages(MessageTypes::MoveDescriptions,movedescs)
      code="class PBMoves\r\n"
      for rec in records
        code+="#{rec[1]}=#{rec[0]}\r\n"
      end
      code+="\r\ndef self.getName(id)\r\nreturn pbGetMessage(MessageTypes::Moves,id)\r\nend"
      code+="\r\ndef self.getCount\r\nreturn #{records.length}\r\nend"
      code+="\r\ndef self.maxValue\r\nreturn #{maxValue}\r\nend\r\nend"
      eval(code)
      pbAddScript(code,"PBMoves")
    end

    and here's the error I'm getting lol

    Code:
    Exception: NoMethodError
    Message: undefined method `<' for nil:NilClass
    Compiler:1105:in `pbCheckByte'
    Compiler:1242:in `pbCompileMoves'
    Compiler:1174:in `pbCompilerEachPreppedLine'
    Compiler:632:in `each_line'
    Compiler:632:in `pbCompilerEachPreppedLine'
    Compiler:629:in `open'
    Compiler:629:in `pbCompilerEachPreppedLine'
    Compiler:1174:in `pbCompileMoves'
    Compiler:3999:in `pbCompileAllData'
    Compiler:4129

    This error seems to occur before before it reads the .txt, so that's not the problem. And as far as my untrained eyes see, my code format resembles the rest so I'm not quite sure how to proceed.

    You're getting this error because "def Category" is returning False, change the <10 to <12 and it should work just fine.
     
  • 1,224
    Posts
    10
    Years
    While that sounds good, I have two problems with that.

    1. I am having difficulties editing a small part of the current compiler, I fear much more difficulties making a new .txt that has to be compiled.

    2. Linking the two moves from both moves.txt and contest.txt sounds difficult, unless I guess I can just compare the internal names. Then it might not be. But my first point is my main concern.

    Edit: Directed at Derxwna's post
     
    Last edited:
  • 1,224
    Posts
    10
    Years
    You're getting this error because "def Category" is returning False, change the <10 to <12 and it should work just fine.

    I still get the same error.

    This is the def where the error occurs

    Code:
    def pbCheckByte(x,valuename)
      if x<0 || x>255
        raise _INTL("The value \"{1}\" must be from 0 through 255 (0x00-0xFF in hex), got a value of {2}\r\n{3}",
           valuename,x,FileLineData.linereport)
      end
    end

    and this is the line that calls the def when the error occurs

    Code:
    pbCheckByte(record[15],_INTL("Hearts"))

    I might be wrong and it is reading the moves.txt when it happens. If so, this is an example of what I've change my moves to ( and I have changed all of them).



    Code:
    1,MEGAHORN,Megahorn,000,120,BUG,Physical,85,10,0,00,0,abef,Cool,"Using its tough and impressive horn, the user rams into the target with no letup.",2,000,""
     

    Derxwna Kapsyla

    Derxwna "The Badman" Kapsyla
  • 437
    Posts
    12
    Years
    While that sounds good, I have two problems with that.

    1. I am having difficulties editing a small part of the current compiler, I fear much more difficulties making a new .txt that has to be compiled.

    2. Linking the two moves from both moves.txt and contest.txt sounds difficult, unless I guess I can just compare the internal names. Then it might not be. But my first point is my main concern.

    Edit: Directed at Derxwna's post

    I'm pretty sure I saw a tutorial or a guide on the forum somewhere about how to add a new text file to be read by the compiler. If I can come across it again, I'll edit this post and link it here.
     

    FL

    Pokémon Island Creator
  • 2,454
    Posts
    13
    Years
    • Seen May 25, 2024
    this may sounds a good add-on. I agree with Derxwna Kapsyla, look at trainers and trainertypes that use something similar.

    I still get the same error.

    This is the def where the error occurs

    Code:
    def pbCheckByte(x,valuename)
      if x<0 || x>255
        raise _INTL("The value \"{1}\" must be from 0 through 255 (0x00-0xFF in hex), got a value of {2}\r\n{3}",
           valuename,x,FileLineData.linereport)
      end
    end

    and this is the line that calls the def when the error occurs

    Code:
    pbCheckByte(record[15],_INTL("Hearts"))

    I might be wrong and it is reading the moves.txt when it happens. If so, this is an example of what I've change my moves to ( and I have changed all of them).



    Code:
    1,MEGAHORN,Megahorn,000,120,BUG,Physical,85,10,0,00,0,abef,Cool,"Using its tough and impressive horn, the user rams into the target with no letup.",2,000,""
    x (record[15]) is nil. I suggest you to print the entire record array ('p "record",record') of the id that trigger the problem.
     

    ~JV~

    Dev of Pokémon Uranium
  • 684
    Posts
    16
    Years
    I still get the same error.

    This is the def where the error occurs

    Code:
    def pbCheckByte(x,valuename)
      if x<0 || x>255
        raise _INTL("The value \"{1}\" must be from 0 through 255 (0x00-0xFF in hex), got a value of {2}\r\n{3}",
           valuename,x,FileLineData.linereport)
      end
    end

    and this is the line that calls the def when the error occurs

    Code:
    pbCheckByte(record[15],_INTL("Hearts"))

    I might be wrong and it is reading the moves.txt when it happens. If so, this is an example of what I've change my moves to ( and I have changed all of them).



    Code:
    1,MEGAHORN,Megahorn,000,120,BUG,Physical,85,10,0,00,0,abef,Cool,"Using its tough and impressive horn, the user rams into the target with no letup.",2,000,""

    I didn't test it, but taking a look at the code more carefully I noticed you didn't edit this line:

    Code:
     defaultdata=[0,0,0,0,0,0,0,0,0,0,0,0,0].pack("vCCCCCCvCvCCv")

    You should add entries in this array (and packing method) that correspond to the ones you added.
     
  • 1,224
    Posts
    10
    Years
    I decided to do what Derxwna Kapsyla and FL suggested, and make an entirely new .txt. Working on typing it up (all the gen 3 and prior moves , in the middle of modifying gen 4 and up moves to fit gen 3 contests). Then onto figuring out how to compile it.
     

    mewlover22

    Pokemon Creator
  • 455
    Posts
    15
    Years
    sounds great looking forward to this script i may add this to my game if it works well i have always like contest from gen 3 not gen 4.
     
  • 1,224
    Posts
    10
    Years
    Update: Finished the .txt file, and wrote a compiling method for it

    Code:
    def pbCompileContestMoves
      records=[]
      contestmovenames=[]
      contestmovedescs=[]
      contestmovedata=[]
      maxValue=0
      haveRsAttacks=pbRgssExists?("Data/rsattacks.dat")
      pbCompilerEachPreppedLine("PBS/contestmoves.txt"){|line,lineno|
         thisline=line.clone
         record=[]
         flags=0
    
           record=pbGetCsvRecord(line,lineno,[0,"vnseUUxs",
              nil,nil,nil,["Cool","Beauty","Cute","Smart","Tough"],nil,nil,nil,nil
           ])
         
         maxValue=[maxValue,record[0]].max
         contestmovedata[record[0]]=[
            record[3],  # Contest Type
            record[4],  # Hearts
            record[5],  # Jam
            record[6]   # Function Code
         ].pack("CCCv")
         contestmovenames[record[0]]=record[2]  # Name
         contestmovedescs[record[0]]=record[7] # Description
         records.push(record)
         }
      defaultdata=[0,0,0,0].pack("CCCv")
      File.open("Data/contestmoves.dat","wb"){|file|
         for i in 0...contestmovedata.length
           file.write(contestmovedata[i] ? contestmovedata[i] : defaultdata)
         end
      }
      MessageTypes.setMessages(MessageTypes::Moves,contestmovenames)
      MessageTypes.setMessages(MessageTypes::MoveDescriptions,contestmovedescs)
      code="class PBContestMoves\r\n"
      for rec in records
        code+="#{rec[1]}=#{rec[0]}\r\n"
      end
      code+="\r\ndef self.getName(id)\r\nreturn pbGetMessage(MessageTypes::ContestMoves,id)\r\nend"
      code+="\r\ndef self.getCount\r\nreturn #{records.length}\r\nend"
      code+="\r\ndef self.maxValue\r\nreturn #{maxValue}\r\nend\r\nend"
      eval(code)
      pbAddScript(code,"PBContestMoves")
    end

    any criticisms on it before I move further? The game runs, though that doesn't necessarily mean it works perfectly.
     
  • 32
    Posts
    11
    Years
    • Seen Aug 2, 2014
    I really hope you can get these sorted - and maybe added to the next version of Essentials!
     
  • 1,748
    Posts
    14
    Years
    Looking at the code you've posted, it looks like you're duplicating a lot of unneeded data such as a move's name and description, you could load all the info you need from Moves.txt and only keep the bare minimum inside ContestMoves.txt (this will cut down a lot of time in adding all the contest data for the moves)
     
    Back
    Top