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

[Essentials v15+] Difficulty Mode

1,224
Posts
10
Years
  • Add this as a new section above the Main
    Code:
    class PokeBattle_Trainer
      
      alias diff_skill skill
      def skill
        ret=diff_skill
        case $PokemonSystem.difficulty
        when 0
          #do nothing
        when 1
          case ret
          when 0
            ret+=5
          when PBTrainerAI.minimumSkill...PBTrainerAI.mediumSkill
            ret = PBTrainerAI.mediumSkill
          when PBTrainerAI.mediumSkill...PBTrainerAI.highSkill
            ret = PBTrainerAI.highSkill
          else
            ret = PBTrainerAI.bestSkill
          end
        when 2
          case ret
          when 0
            ret = PBTrainerAI.mediumSkill
          when PBTrainerAI.minimumSkill...PBTrainerAI.mediumSkill
            ret = PBTrainerAI.highSkill
          when PBTrainerAI.mediumSkill...PBTrainerAI.highSkill
            ret = PBTrainerAI.bestSkill
          else
            ret = PBTrainerAI.bestSkill
          end
        end
        return ret
      end
      
    end
    
    Events.onTrainerPartyLoad+=proc {|sender,e|
       if e[0] # Trainer data should exist to be loaded, but may not exist somehow
         trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
         items=e[0][1]   # An array of the trainer's items they can use
         party=e[0][2]   # An array of the trainer's Pokémon
         case $PokemonSystem.difficulty
         when 0
           #do nothing
         when 1
           levels=0
           types=[]
           stats=[]
           for i in 0...party.length
             types.push(party[i].type1)
             types.push(party[i].type2)
             bst=(party[i].baseStats).dup
             bst=bst.inject{|sum,x| sum + x }
             stats.push(bst)
             levelchange=party[i].level/10.floor
             levelchange*=2 if levelchange<3
             party[i].level+=levelchange
             party[i].level+=rand(3)
             party[i].level=MAXIMUMLEVEL if party[i].level>MAXIMUMLEVEL
             party[i].level=1 if party[i].level<1
             party[i].calcStats
             levels+=party[i].level
             movelist=party[i].getMoveList
             moves=[]
             for k in 0...movelist.length
               for j in 0...party[i].moves.length
                 if movelist[k][1]==party[i].moves[j]
                   moves.push(party[i].moves[j])
                 end
               end
             end
             moves.uniq!
             party[i].resetMoves if moves.length==3
           end
           levels=levels/party.length
           if party.length<6 && levels>30 && rand(100)<75
             #Add another strong pokemon
             count = Hash.new(0)
             types.each {|word| count[word] += 1}
             type=(count.sort_by { |k,v| v }.last) #Type to look for
             bst=(stats.inject{|sum,x| sum + x })/party.length  #BST to look for
             acceptable_pokes=[]
             backup_pokes=[]
             scn=PokemonPokedexScene.new
             dex=scn.pbGetDexList #Get all pokemon in region
             for i in 0...dex.length
               dexdata=pbOpenDexData
               pbDexDataOffset(dexdata,dex[i][0],8)
               type1=dexdata.fgetb
               type2=dexdata.fgetb
               curstats=[
                   dexdata.fgetb, # HP
                   dexdata.fgetb, # Attack
                   dexdata.fgetb, # Defense
                   dexdata.fgetb, # Speed
                   dexdata.fgetb, # Special Attack
                   dexdata.fgetb  # Special Defense
               ]
               dexdata.close
               curstats=(curstats.inject{|sum,x| sum + x })
               if (-20..20).include?(bst-curstats)
                 if type1==type || type2==type
                   acceptable_pokes.push(dex[i][0]) #Pokemon's number
                 else
                   backup_pokes.push(dex[i][0])
                 end
               end
             end
             #remove legendaries here, has to be specified
             if acceptable_pokes.length==0
               if backup_pokes.length>0
                 p=PokeBattle_Pokemon.new(backup_pokes[rand(backup_pokes.length)],levels,trainer)
                 party.push(p)
               end
             else
               p=PokeBattle_Pokemon.new(acceptable_pokes[rand(acceptable_pokes.length)],levels,trainer)
               party.push(p)
             end
           end
         when 2
           levels=0
           types=[]
           stats=[]
           for i in 0...party.length
             types.push(party[i].type1)
             types.push(party[i].type2)
             bst=(party[i].baseStats).dup
             bst=bst.inject{|sum,x| sum + x }
             stats.push(bst)
             levelchange=party[i].level/10.floor
             if levelchange<6
               levelchange*=2 
               levelchange+=rand(3)
             else
               levelchange+=rand(5)
             end
             party[i].level+=levelchange         
             party[i].level=MAXIMUMLEVEL if party[i].level>MAXIMUMLEVEL
             party[i].level=1 if party[i].level<1
             party[i].calcStats
             levels+=party[i].level
             movelist=party[i].getMoveList
             moves=[]
             for k in 0...movelist.length
               for j in 0...party[i].moves.length
                 if movelist[k][1]==party[i].moves[j]
                   moves.push(party[i].moves[j])
                 end
               end
             end
             moves.uniq!
             party[i].resetMoves if moves.length==4
           end
           levels=levels/party.length         
           if party.length<6 && rand(100)<75
             #Add another strong pokemon
             count = Hash.new(0)
             types.each {|word| count[word] += 1}
             type=(count.sort_by { |k,v| v }.last) #Type to look for
             bst=(stats.inject{|sum,x| sum + x })/party.length  #BST to look for
             acceptable_pokes=[]
             backup_pokes=[]
             scn=PokemonPokedexScene.new
             dex=scn.pbGetDexList #Get all pokemon in region
             for i in 0...dex.length
               dexdata=pbOpenDexData
               pbDexDataOffset(dexdata,dex[i][0],8)
               type1=dexdata.fgetb
               type2=dexdata.fgetb
               curstats=[
                   dexdata.fgetb, # HP
                   dexdata.fgetb, # Attack
                   dexdata.fgetb, # Defense
                   dexdata.fgetb, # Speed
                   dexdata.fgetb, # Special Attack
                   dexdata.fgetb  # Special Defense
               ]
               dexdata.close
               curstats=(curstats.inject{|sum,x| sum + x })
               if (-20..20).include?(bst-curstats)
                 if type1==type || type2==type
                   acceptable_pokes.push(dex[i][0]) #Pokemon's number
                 else
                   backup_pokes.push(dex[i][0])
                 end
               end
             end
             #remove legendaries here, has to be specified
             if acceptable_pokes.length==0
               if backup_pokes.length>0
                 p=PokeBattle_Pokemon.new(backup_pokes[rand(backup_pokes.length)],levels,trainer)
                 party.push(p)
               end
             else
               p=PokeBattle_Pokemon.new(acceptable_pokes[rand(acceptable_pokes.length)],levels,trainer)
               party.push(p)
             end
             if party.length<6 && rand(100)<50
               if acceptable_pokes.length==0
                 if backup_pokes.length>0
                   p=PokeBattle_Pokemon.new(backup_pokes[rand(backup_pokes.length)],levels,trainer)
                   party.push(p)
                 end
               else
                 p=PokeBattle_Pokemon.new(acceptable_pokes[rand(acceptable_pokes.length)],levels,trainer)
                 party.push(p)
               end
             end
           end
         end
       end
    }

    Make sure to add the difficulty variable to your options (basically a copy+paste of the other options, make sure to initialize the variables. You may have to start a new game.)
    On easy difficulty, it does nothing. On medium difficulty it increases trainer pokemon's levels (scaling according to their current level), and has the possibility of adding another pokemon to the trainer's party, assuming the trainer's pokemon average level 30. The pokemon it adds will be of similar BST to the average of the trainer's current mons, and it will attempt to add a similar typed pokemon if possible(most common type occurrence). On hard difficulty it is the same thing, but with slightly higher levels, no level requirement to add pokemon to the trainer's party, and it can add up to two pokemon as opposed to one.

    Requires v15+
     
    Last edited:
    59
    Posts
    8
    Years
    • Seen Aug 9, 2020
    This is so great! Will give it a test and will come here, if I encounter any malfunction to report.
     
    68
    Posts
    11
    Years
    • Seen Jan 17, 2017
    i have this error :S
    i add the script,
    i add this line in the options script
    Spoiler:


    it look like this,
    Spoiler:


    when i select the 0, it work! , if i select the 1 then add 5 lvl to the enemy pokemon, but when i selec 2, i have this error when the battle started :s
    Spoiler:
     
    1,224
    Posts
    10
    Years
  • i have this error :S
    i add the script,
    i add this line in the options script
    Spoiler:


    it look like this,
    Spoiler:


    when i select the 0, it work! , if i select the 1 then add 5 lvl to the enemy pokemon, but when i selec 2, i have this error when the battle started :s
    Spoiler:

    You need to initialize the variable and create a getter/setter method for it
    Code:
    attr_accessor :difficulty
     
    824
    Posts
    8
    Years
  • You have to start a new game

    You don't actually have to start a new game - I've been adding options to my game as well. You just have to enter the options menu and "jiggle" the option in question before testing it.

    Now, I will admit that saying "start a new game" is easier to explain than "jiggle the option".
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    It means you're not using Essentials v15 or newer. The solution should be obvious.
     

    pokefan41

    RMXP Game Developer
    143
    Posts
    13
    Years
    • Seen Oct 20, 2023
    yes it is, although it would've helped to have a more concrete tutorial on how to insert this particular script into Essentials. Not knowing much about programming made this very hard. the only thing that helped me was the posts made earlier showing exactly what to put where.

    Also, it would've been nice to know I needed the latest build of essentials for this to work. Not having that important piece of information will offset a lot of people who don't have the latest build, someone like myself who's trying to stick to one build to actually get a game built instead of upgrading every 6 or so months because of new features added.
     

    pokefan41

    RMXP Game Developer
    143
    Posts
    13
    Years
    • Seen Oct 20, 2023
    I don't want to come off as mean or rude here, but unlike some other members here, I know very little about how the scripts are installed and used by essentials. I would've been asking the same questions about how to make it work like the other user did before.

    I have steered away from scripting in the past because of my illiteracy to them, and my self-determined inability to make them work right. To be completely honest, I would love to learn how to script in RPGXP, but i have no idea where to get started with it. I can't even remember what language is used.
     
    1,224
    Posts
    10
    Years
  • In fairness I think it's a safe bet to say essentials is pretty much done being upgraded. All of the functionality is there, and anything we'll be getting from here on out are maybe just additions to attack editor, or easier to use editor functions, etc. Honestly so long as you have an essentials version since the script reorganization(v.14 I think, maybe it was 15 though), I'd say you're safe regarding any kind of script addition for the inevitable future.

    In addition, this is clearly a script for a game/demo that is near completion and has enough content to make multiple run-throughs meaningful. I think it goes without saying that anyone in that scenario should by now know how to use this, relatively easy to use imo, script.

    v15.1 was the script reorganization, and is currently the latest version. I don't think that's necessarily true, it depends on what the script edits. The reason this only works on the latest version is because it utilizes a feature that was added in v15, which is the trainer modifiers (similar to the wild encounter modifiers that have been in for a while, used to force a shiny encounter or whatever. This is the trainer counterpart). I added a note to the main post to indicate that it does require the newest version. I also highly doubt this is the final upgrade of Essentials, there's always things that can be made easier to use or performance improvements even if no new features are added. Though I would recommend keeping up to date with the newest version, as long as you mark your changes it's not really that hard. You could also use diffchecker to figure out what you added if you forgot things.

    @pokefan41: The script language used is RGSS, which is essentially Ruby
     

    pokefan41

    RMXP Game Developer
    143
    Posts
    13
    Years
    • Seen Oct 20, 2023
    I understand now. I got the script working. I will definitly be using it in my game.
     

    pokefan41

    RMXP Game Developer
    143
    Posts
    13
    Years
    • Seen Oct 20, 2023
    I hate to bring up an old topic, but I'm having problems with this script. every time i try to use hard mode the game crashes. I have no idea what's going on with it. I know to help you guys need some more info, and maybe screens of my scripts, but I have no idea what i need to show.
     
    Back
    Top