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

[Scripting Question] Event Encounters Customization

83
Posts
5
Years
    • She/It/Mew
    • Seen Feb 22, 2023
    I'm not sure if I've asked about this before, but I need some help regarding legendary/event encounters. There are a lot of bosses in my game and I want to be able to customize them so that they can be more difficult. I want to be able to give them a specific moveset, specific items, change their ability, etc. Now is there any way I can do this? I've been asking around on different threads for some time and I'm sorry if I'm being annoying abt this, but I really need to know.
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I'm not sure if I've asked about this before, but I need some help regarding legendary/event encounters. There are a lot of bosses in my game and I want to be able to customize them so that they can be more difficult. I want to be able to give them a specific moveset, specific items, change their ability, etc. Now is there any way I can do this? I've been asking around on different threads for some time and I'm sorry if I'm being annoying abt this, but I really need to know.

    The function pbWildBattleCore() can take an instance of PokeBattle_Pokemon. A possible solution is is to create an instance of PokeBattle_Pokemon, and modify it to make it like you want it to be. You can change the moves, the abilities, and so on, and then call the function pbWildBattleCore() and give it the instance of PokeBattle_Pokemon you wanted.
    You can also factor this code into a function.
     
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    How would I create a instance of smth? I don't really know what an instance is... Could you maybe give me an example of what you're talking about?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Paste this code somewhere:
    (EDITED because there was a mistake. This code now works).
    Code:
    def pbControlledWildBattle(species, level, moves = nil, ability = nil, 
                              nature = nil, gender = nil, item = nil, shiny = nil, 
                              outcomeVar=1, canRun=true, canLose=false)
      # Create an instance
      species = getConst(PBSpecies, species)
      pkmn = PokeBattle_Pokemon.new(species, level)
      
      # Give moves.
      # Should be a list of moves:
      if moves
        for i in 0...4
          pkmn.moves[i] = PBMove.new(getConst(PBMoves,moves[i])) if moves[i]
        end 
      end 
      
      # Give ability
      # NOTE that the ability should be 0, 1 or 2.
      pkmn.setAbility(ability) if [0, 1, 2].include?(ability)
      
      # Give nature
      pkmn.setNature(nature) if nature
      
      # Give gender
      # 0 if male, 1 if female.
      pkmn.setGender(gender) if gender
      
      # Give item 
      pkmn.item = item if item 
      
      # Shiny or not.
      pkmn.makeShiny if shiny
      
      # Start the battle.
      # This is copied from pbWildBattle. 
      
      # Potentially call a different pbWildBattle-type method instead (for roaming
      # Pokémon, Safari battles, Bug Contest battles)
      handled = [nil]
      Events.onWildBattleOverride.trigger(nil,species,level,handled)
      return handled[0] if handled[0]!=nil
      # Set some battle rules
      setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
      setBattleRule("cannotRun") if !canRun
      setBattleRule("canLose") if canLose
      # Perform the battle
      decision = pbWildBattleCore(pkmn)
      # Used by the Poké Radar to update/break the chain
      Events.onWildBattleEnd.trigger(nil,species,level,decision)
      # Return false if the player lost or drew the battle, and true if any other result
      return (decision!=2 && decision!=5)
    end

    And then, in your event, call the function:
    Code:
    pbControlledWildBattle(species, level, moves, ability, nature, gender, item, shiny)
    • species should be of the form :KABUTOPS (with the semicolon)
    • level should be an integer, for example 98
    • moves should be a list of elements [:FLAMETHROWER, :EARTHQUAKE]. Should have 1 to 4 moves in the list.
    • ability should be either 0, 1 or 2 (0 or 1 are the normal abilities, and 2 is the hidden ability)
    • nature should be a constant like PBNatures::ADAMANT
    • gender should be 0 for male, 1 for female.
    • item should be of the form PBItems::LIFEORB
    • shiny should be true or false
    • outcomeVar: honestly I don't know what this is.
    • canRun should be true or false (whether or not you can run from battle)
    • canLose should be true or false (whether or not you can lose the battle without being sent to the PokéCenter)
    Just use this function pbControlledWildBattle instead of pbWildBattle. It's the same usage, with just more arguments to give.
     
    Last edited:
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    I keep getting this error message

    ---------------------------
    PKMNZ
    ---------------------------
    [Pokémon Essentials version 18.1.dev]

    Exception: RuntimeError

    Message: Script error within event 61 (coords 21,0), map 3 (MAP003):

    Exception: SyntaxError

    Message: (eval):1:in `pbExecuteScript'compile error
    (eval):1: syntax error
    pbControlledWildBattle(:ZYGARDE_2, 70, [:COREENFORCER, :CRUNCH, :STONEEDGE, :EARTHQUAKE,] 0, PBNatures::ADAMANT, 0, PBItems::LIFEORB, false)
    ^



    ***Full script:

    pbControlledWildBattle(:ZYGARDE_2, 70, [:COREENFORCER, :CRUNCH, :STONEEDGE, :EARTHQUAKE,] 0, PBNatures::ADAMANT, 0, PBItems::LIFEORB, false)



    Backtrace:





    Backtrace:

    Interpreter:246:in `pbExecuteScript'

    Interpreter:658:in `command_111'

    Interpreter:272:in `execute_command'

    Interpreter:155:in `update'

    Interpreter:102:in `loop'

    Interpreter:158:in `update'

    Scene_Map:162:in `update'

    Scene_Map:160:in `loop'

    Scene_Map:169:in `update'

    Scene_Map:229:in `main'



    This exception was logged in

    C:\Users\USERNAME\Saved Games\PKMNZ\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------

    What's the solution?
     
    233
    Posts
    5
    Years
    • Seen Oct 9, 2023
    You put the comma after :EARTHQUAKE in the wrong place. It should look like this:
    Code:
    pbControlledWildBattle(:ZYGARDE_2, 70, [:COREENFORCER, :CRUNCH, :STONEEDGE, :EARTHQUAKE], 0, PBNatures::ADAMANT, 0, PBItems::LIFEORB, false)
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    You put the comma after :EARTHQUAKE in the wrong place. It should look like this:
    Code:
    pbControlledWildBattle(:ZYGARDE_2, 70, [:COREENFORCER, :CRUNCH, :STONEEDGE, :EARTHQUAKE], 0, PBNatures::ADAMANT, 0, PBItems::LIFEORB, false)

    +1.

    Besides, it's a bit sad to give Earthquake to Zygarde while it has Thousand Arrows :P
     
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    Now it's giving this error message

    ---------------------------
    PKMNZ
    ---------------------------
    [Pokémon Essentials version 18.1.dev]

    Exception: RuntimeError

    Message: Script error within event 61 (coords 21,0), map 3 (MAP003):

    Exception: TypeError

    Message: PBMove:37:in `[]'Symbol as array index



    ***Full script:

    pbControlledWildBattle(:ZYGARDE_2, 70, [:COREENFORCER, :CRUNCH, :STONEEDGE, :EARTHQUAKE], 0, PBNatures::ADAMANT, 0, PBItems::LIFEORB, false)



    Backtrace:

    Interpreter:197:in `pbExecuteScript'

    PBMove:37:in `pbGetMoveData'

    PBMove:58:in `initialize'

    Event_Battle_Custom:11:in `new'

    Event_Battle_Custom:11:in `pbControlledWildBattle'

    Event_Battle_Custom:10:in `each'

    Event_Battle_Custom:10:in `pbControlledWildBattle'

    (eval):1:in `pbExecuteScript'

    Interpreter:658:in `eval'

    Interpreter:197:in `pbExecuteScript'





    Backtrace:

    Interpreter:246:in `pbExecuteScript'

    Interpreter:658:in `command_111'

    Interpreter:272:in `execute_command'

    Interpreter:155:in `update'

    Interpreter:102:in `loop'

    Interpreter:158:in `update'

    Scene_Map:162:in `update'

    Scene_Map:160:in `loop'

    Scene_Map:169:in `update'

    Scene_Map:229:in `main'



    This exception was logged in

    C:\Users\USERNAME\Saved Games\PKMNZ\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------


    (Also i gave it earthquake bcz it has stone edge for coverage against flying types but i get it lol)
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Now it's giving this error message
    <ERROR>
    It's because I didn't realise it does not convert a move constant :MOVE into its value PBMoves::MOVE.
    It should be better:
    EDIT: There was a mistake here, I solved it.
    Code:
    def pbControlledWildBattle(species, level, moves = nil, ability = nil, 
                              nature = nil, gender = nil, item = nil, shiny = nil, 
                              outcomeVar=1, canRun=true, canLose=false)
      # Create an instance
      species = getConst(PBSpecies, species)
      pkmn = PokeBattle_Pokemon.new(species, level)
      
      # Give moves.
      # Should be a list of moves:
      if moves
        for i in 0...4
          pkmn.moves[i] = PBMove.new(getConst(PBMoves,moves[i])) if moves[i]
        end 
      end 
      
      # Give ability
      # NOTE that the ability should be 0, 1 or 2.
      pkmn.setAbility(ability) if [0, 1, 2].include?(ability)
      
      # Give nature
      pkmn.setNature(nature) if nature
      
      # Give gender
      # 0 if male, 1 if female.
      pkmn.setGender(gender) if gender
      
      # Give item 
      pkmn.item = item if item 
      
      # Shiny or not.
      pkmn.makeShiny if shiny
      
      # Start the battle.
      # This is copied from pbWildBattle. 
      
      # Potentially call a different pbWildBattle-type method instead (for roaming
      # Pokémon, Safari battles, Bug Contest battles)
      handled = [nil]
      Events.onWildBattleOverride.trigger(nil,species,level,handled)
      return handled[0] if handled[0]!=nil
      # Set some battle rules
      setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
      setBattleRule("cannotRun") if !canRun
      setBattleRule("canLose") if canLose
      # Perform the battle
      decision = pbWildBattleCore(pkmn)
      # Used by the Poké Radar to update/break the chain
      Events.onWildBattleEnd.trigger(nil,species,level,decision)
      # Return false if the player lost or drew the battle, and true if any other result
      return (decision!=2 && decision!=5)
    end
     
    Last edited:
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    Okay so the battle itself works but for some reason zygarde is in its 50% form, is there a way to fix that?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Okay so the battle itself works but for some reason zygarde is in its 50% form, is there a way to fix that?

    I'm tired of this Symbol / value duality XD
    It was again because Essentials does not naturally convert :ZYGARDE_2 into PBSpecies::ZYGARDE_2.

    I tested and it seems to work:

    Code:
    def pbControlledWildBattle(species, level, moves = nil, ability = nil, 
                              nature = nil, gender = nil, item = nil, shiny = nil, 
                              outcomeVar=1, canRun=true, canLose=false)
      # Create an instance
      species = getConst(PBSpecies, species)
      pkmn = PokeBattle_Pokemon.new(species, level)
      
      # Give moves.
      # Should be a list of moves:
      if moves
        for i in 0...4
          pkmn.moves[i] = PBMove.new(getConst(PBMoves,moves[i])) if moves[i]
        end 
      end 
      
      # Give ability
      # NOTE that the ability should be 0, 1 or 2.
      pkmn.setAbility(ability) if [0, 1, 2].include?(ability)
      
      # Give nature
      pkmn.setNature(nature) if nature
      
      # Give gender
      # 0 if male, 1 if female.
      pkmn.setGender(gender) if gender
      
      # Give item 
      pkmn.item = item if item 
      
      # Shiny or not.
      pkmn.makeShiny if shiny
      
      # Start the battle.
      # This is copied from pbWildBattle. 
      
      # Potentially call a different pbWildBattle-type method instead (for roaming
      # Pokémon, Safari battles, Bug Contest battles)
      handled = [nil]
      Events.onWildBattleOverride.trigger(nil,species,level,handled)
      return handled[0] if handled[0]!=nil
      # Set some battle rules
      setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
      setBattleRule("cannotRun") if !canRun
      setBattleRule("canLose") if canLose
      # Perform the battle
      decision = pbWildBattleCore(pkmn)
      # Used by the Poké Radar to update/break the chain
      Events.onWildBattleEnd.trigger(nil,species,level,decision)
      # Return false if the player lost or drew the battle, and true if any other result
      return (decision!=2 && decision!=5)
    end

    (The only new line is this "species = getConst(PBSpecies, species)" at the beginning)
     
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    Oh and one more. There are two things I'm concerned about regarding the script.
    A: Is there a way to make it so that you cant throw pokeballs at a boss pokemon
    B: (This isnt that big of a deal so dont worry too much about this) Is there any way to use your script but give the pokemon a chance to be shiny so if someone wanted to shinyhunt them then they could? Again if there isnt then thats not too big of a deal.
     
    Last edited:
    14
    Posts
    3
    Years
    • Seen Jun 24, 2023
    Hi,
    i replaced:
    Code:
    if trainerBattle? && !(pbIsSnagBall?(ball) && battler.shadowPokemon?)
          @scene.pbThrowAndDeflect(ball,1)
          pbDisplay(_INTL("The Trainer blocked your Poké Ball! Don't be a thief!"))
          return 
    end
    in PokeBattle_BattleCommon with:
    Code:
    if trainerBattle? && !(pbIsSnagBall?(ball) && battler.shadowPokemon?)
          @scene.pbThrowAndDeflect(ball,1)
          pbDisplay(_INTL("The Trainer blocked your Poké Ball! Don't be a thief!"))
          return
    else
          if $game_switches[400]==true
            @scene.pbThrowAndDeflect(ball,1)
            pbDisplay(_INTL("{1} blocked the ball!",battler.pokemon.name))
            return
          end
      end

    Now you only have to set a certain Switch (ID400 in my Example) and the Ball should be blocked.
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Oh and one more. There are two things I'm concerned about regarding the script.
    A: Is there a way to make it so that you cant throw pokeballs at a boss pokemon
    In the function I gave above, you can set a certain game variable to true before pbWilBattleCore, and then set it to false afterwards: .
    Code:
      # Perform the battle
      $game_variables[something] = true
      decision = pbWildBattleCore(pkmn)
      $game_variables[something] = false
    where "something" is an available variable number.

    Then, in the file PITem_BattleItemEffects, find this battle handler:
    Code:
    ItemHandlers::CanUseInBattle.addIf(proc { |item| pbIsPokeBall?(item) },   # Poké Balls
      proc { |item,pokemon,battler,move,firstAction,battle,scene,showMessages|
    and add this:
    Code:
      if $game_variables[something]
        scene.pbDisplay(_INTL("You cannot catch a boss lol.")) if showMessages
        next false
      end
    where "something" is the same vairable number as before.


    B: (This isnt that big of a deal so dont worry too much about this) Is there any way to use your script but give the pokemon a chance to be shiny so if someone wanted to shinyhunt them then they could? Again if there isnt then thats not too big of a deal.
    Actually you can force the Pokémon being shiny, it's in the parameters. The rest of the generation of the Pokémon is untouched, so the chances of having a shiny Pokémon will be the same as in the rest of your game.

    PS: Who shiny hunts in fangames? XD
     
    83
    Posts
    5
    Years
    • She/It/Mew
    • Seen Feb 22, 2023
    So if shiny is set to "false" then theres still a chance that they can be shiny?

    "PS: Who shiny hunts in fangames? XD"

    Honestly yeah, good point.
     
    124
    Posts
    3
    Years
  • I think StCooler's method is "cool" (pun intended), but here's how you could do the same thing using encounter modifiers.
    Code:
    Events.onWildPokemonCreate += proc { |_sender, e|
      pokemon = e[0]
        if $game_switches[99]
          if isConst?(pokemon.species,PBSpecies,:ZYGARDE)
            pokemon.form = 2
            pokemon.setAbility(0)
            pokemon.pbLearnMove(:COREENFORCER)
            pokemon.pbLearnMove(:CRUNCH)
            pokemon.pbLearnMove(:STONEEDGE)
            pokemon.pbLearnMove(:EARTHQUAKE)
            pokemon.setNature(:ADAMANT)
            pokemon.setItem(:LIFEORB)
            if rand(100)<1 # 1% chance of being shiny
              pokemon.makeShiny
            end
          end
        end
    }
    You can put this anywhere in PField_EncounterModifiers. In your event, just before the battle with Zygarde, turn switch 99 ON. Then, do pbWildBattle(:ZYGARDE,70). After the battle, turn switch 99 OFF (but this doesn't matter too much unless you have another Zygarde battle somewhere).

    This approach is more flexible I think. You can edit pretty much anything about the Pokémon. Note at the end of the code block I added a 1 in 100 chance of the Zygarde being shiny. You can increase the 100 to decrease the odds of finding a shiny.
     
    Back
    Top