• 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

StCooler

Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    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.

    I must say, this is elegant :)
    However I still prefer my solution because it reduces the amount of scripting to make ^^"
     

    Sir William

    Chemist
  • 72
    Posts
    3
    Years
    • Seen Apr 14, 2021
    Paste this code somewhere:
    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
      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(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.

    Can we make the boss to dynamax or gmax and even ultra burst ?
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Can we make the boss to dynamax or gmax and even ultra burst ?

    Ultra-Burst is something you activate by using a specific Z-move. You can force a battle against the Ultra-Burst Necrozma though.

    As for Dynamax and Gigantamax, it would add a few parameters to the function. Here is the result:
    (EDIT: My code had some issues, now it works).

    Spoiler:
     
    Last edited:

    Sir William

    Chemist
  • 72
    Posts
    3
    Years
    • Seen Apr 14, 2021
    Ultra-Burst is something you activate by using a specific Z-move. You can force a battle against the Ultra-Burst Necrozma though.

    As for Dynamax and Gigantamax, it would add a few parameters to the function. Here is the result:

    Spoiler:
    Thanks can I force a battle against specific deoxy forms ?
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    Paste this code somewhere:
    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
      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(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.

    Where should I exactly put this code ?
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Where should I exactly put this code ?

    If you're talking about the script:
    In RPG Maker, open the Script Editor (Tools > Script Editor, or pressF11 on Windows). On the left, there is a list of scripts. Scroll to the end, you will find one named "Main". You may also have an empty script with a "visual" name like "==========" or "====[Main]=====", it depends on your version.
    Click on Main, or if you have it, the script with the visual name, and click Insert. You have created a new script. Now paste the script I gave in it.

    If you're talkning about the use of it:
    pbControlledWildBattle(species, level, moves, ability, nature, gender, item, shiny) should be called in an Event, just like stated in this Docs.
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    If you're talking about the script:
    In RPG Maker, open the Script Editor (Tools > Script Editor, or pressF11 on Windows). On the left, there is a list of scripts. Scroll to the end, you will find one named "Main". You may also have an empty script with a "visual" name like "==========" or "====[Main]=====", it depends on your version.
    Click on Main, or if you have it, the script with the visual name, and click Insert. You have created a new script. Now paste the script I gave in it.

    If you're talkning about the use of it:
    pbControlledWildBattle(species, level, moves, ability, nature, gender, item, shiny) should be called in an Event, just like stated in this Docs.
    Thanks because of you I got much knowledge .
    One more question I have pasted the updated code which can make the boss dmax or gmax also . So in an event script command I should paste this in order to execute the code ?
    Spoiler:
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Thanks because of you I got much knowledge .
    One more question I have pasted the updated code which can make the boss dmax or gmax also . So in an event script command I should paste this in order to execute the code ?
    Spoiler:
    No, you have to add a few lines so you can actually take into account the dmax and gmax values.
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    No, you have to add a few lines so you can actually take into account the dmax and gmax values.

    Oh but I am talking about this code
    Spoiler:

    I use it and the scenario was like raid battle but the wild pokemon sprite was neither enlarged nor red but pokemon was behaving same like raid den pokemon. One more thing when I set gmax true the pokemon was having gmax factor but was not using any gmax moves also sprites were normal ones not gmax .
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Oh but I am talking about this code
    <CODE>
    I use it and the scenario was like raid battle but the wild pokemon sprite was neither enlarged nor red but pokemon was behaving same like raid den pokemon. One more thing when I set gmax true the pokemon was having gmax factor but was not using any gmax moves also sprites were normal ones not gmax .

    Whoops, sorry, I forgot I implemented this function for Dynamax and Gigantamax lol
    Are you able to generate a normal Max Raid Battle?
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    Whoops, sorry, I forgot I implemented this function for Dynamax and Gigantamax lol
    Are you able to generate a normal Max Raid Battle?

    From normal Max raid battle you mean Max Raid event battle by the code pbMaxRaid or Max raid wild boss battle from your code ?
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    By the code pbMaxRaid

    Yes I am able to do so by pbMaxRaid code but my question is that when I set true at the places of dynamax and gmax there is scene like raid den but pokemon sprites are of same size and same colour and even if I set gmax true they just normal sprites .
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Yes I am able to do so by pbMaxRaid code but my question is that when I set true at the places of dynamax and gmax there is scene like raid den but pokemon sprites are of same size and same colour and even if I set gmax true they just normal sprites .

    I don't know what the issue is. I'll check it out.
    However, if you want a fast Max Raid battle, without caring about the details, you can use this code, I tested and it works:

    Code:
    def pbMaxRaidBattleSimple(species, lvl, gmax)
      # species = PBSpecies constant (of the form: PBSpecies::KABUTOPS for example)
      # lvl = Pokémon level (will be converted to a rank level).
      # gmax = boolean
      pbResetRaidSettings
      setBattleRule("canLose")
      setBattleRule("cannotRun")
      setBattleRule("noPartner")
      setBattleRule(sprintf("%dv%d",MAXRAID_SIZE,1))
      
      s = pbGetSpeciesFromFSpecies(species)
      # f,g = pbGetMaxRaidForm(s[0],rand(10),nil,nil)
      s, r = pbGetMaxRaidSpecies(species,1,nil)
      
      $game_switches[MAXRAID_SWITCH] = true 
      $game_variables[MAXRAID_PKMN] = [s[0], s[1], s[2], lvl,gmax]
      pbWildBattleCore(species, lvl)
      pbResetBattle
      pbResetRaidSettings
      $PokemonTemp.clearBattleRules
      for i in $Trainer.party; i.heal; end
    end

    Here you can only control the species, the level and the gmax factor.

    EDIT: This code works. I only forgot to "make dynamax" lol.

    Code:
    def pbControlledWildBattle(species, level, moves = nil, ability = nil, 
                              nature = nil, gender = nil, item = nil, shiny = nil, 
                              dynamax = false, gmax = false, dyn_level = 5,
                              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
      
      # Handle the dynamax and gmax forms.
      dynamax = dynamax || gmax
      if dynamax
        pbResetRaidSettings
        setBattleRule(sprintf("%dv%d",MAXRAID_SIZE,1))
        $game_switches[MAXRAID_SWITCH] = true 
        storedPkmn = pbMapInterpreter.get_character(0).id + MAXRAID_PKMN
        pkmn.giveGMaxFactor if pkmn.hasGmax? && gmax
        pkmn.makeDynamax
        pkmn.setDynamaxLvl(dyn_level)
        $game_variables[storedPkmn] = pkmn
      end 
      
      # 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
      
      # Reset dynamax stuff.
      pbResetRaidSettings
      
      return (decision!=2 && decision!=5)
    end

    I'm also editting my old post, because the old function would not work.
     
    Last edited:
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    Hi , Thanks for the code I will try this code .
    One more thing I would like to ask is how to set no. of pokemons for a particular boss battle and is there any way so that partners can help in boss battles .



    And yes there is news I am learning ruby from marin's tutorial .
    One more thing which I would like to ask is which essentials code should I touch first if I am a beginner ?
     
    Last edited:

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Hi , Thanks for the code I will try this code .
    One more thing I would like to ask is how to set no. of pokemons for a particular boss battle and is there any way so that partners can help in boss battles .
    I am not sure I understand. You want a variation of this script to fight several Pokémons are once with a partner? (2v2 style, like in Pokémon DPP with Cheryl in Eterna Forest?)

    And yes there is news I am learning ruby from marin's tutorial .
    One more thing which I would like to ask is which essentials code should I touch first if I am a beginner ?
    What do you mean "which Essentials code"?
    You mean which version of Essentials? Just work on whatever version you're using.
     
  • 24
    Posts
    3
    Years
    • Seen Jul 14, 2021
    I am not sure I understand. You want a variation of this script to fight several Pokémons are once with a partner? (2v2 style, like in Pokémon DPP with Cheryl in Eterna Forest?)
    Well I was wondering if partner trainer can help player in boss battles but I think that would be hard to implement , what do you say ?

    What do you mean "which Essentials code"?
    You mean which version of Essentials? Just work on whatever version you're using.
    Since you are an ruby expert so I thought you can tell which script of essentials v18.dev is easy for ruby beginners to edit and learn .
     

    StCooler

    Mayst thou thy peace discover.
  • 9,311
    Posts
    4
    Years
    • Seen yesterday
    Well I was wondering if partner trainer can help player in boss battles but I think that would be hard to implement , what do you say ?
    It's easy but you need to register a partner at some point (but it's not even scripting at this point). See the docs for more information.

    Since you are an ruby expert so I thought you can tell which script of essentials v18.dev is easy for ruby beginners to edit and learn .
    I suggest you start by making new items / abilities first, then moves. It will teach you to look at the right places, to take inspiration from existing items / abilities / moves and you will progressively learn how the battle system works.
     
    Back
    Top