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

[Eventing Question] How to create a One Pokemon vs One Pokemon Battle

  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    Is there a way to make One on One battles in base Essentials v19.1? Like you choose a Pokemon and that is the only Pokemon you can use, similar to the Pokemon Showdown 1v1 category.

    The setBattleRule 1v1 just forces the battle into a single battle. I reckon it would probably involve the pbChoosePokemon command and then using the variable as the player's team, but I do not know how to set up that last part.
    Or there is probably a simpler way.
    Any help would be appreciated.
     
  • 1,409
    Posts
    10
    Years
    • Seen today
    Try this code that I whipped up real quick. Paste this somewhere in your game script above Main.
    Code:
    def pbOneVsOneTrainerBattle(choose, trainerID, trainerName, endSpeech = nil, 
                                doubleBattle = false, trainerPartyID = 0, canLose = false, outcomeVar = 1)
      if choose
        pbChooseAblePokemon(1, 2)
      else
        $Trainer.party.each_with_index do |pkmn, i|
          next if pkmn.egg? || pkmn.hp == 0
          $game_variables[1] = i
          break
        end
      end
      if $game_variables[1] >= 0 
        oldparty = []
        $Trainer.party.each_with_index do |pkmn, i|
          next if i == $game_variables[1]
          oldparty.push(pkmn)
          $Trainer.party[i] = nil
        end
        $Trainer.party.compact!
        pbTrainerBattle(trainerID, trainerName, endSpeech, doubleBattle, trainerPartyID, canLose, outcomeVar)
        oldparty.each { |pkmn| $Trainer.party.push(pkmn) }
      end
    end
    It functions exactly like pbTrainerBattle does, except it has an extra argument in the beginning that you can set true or false.
    When "true", the event will make you select a party member to use in battle.
    When "false", the event will default in selecting the first able Pokemon in your party to do battle with.
    All other Pokemon in your party will be temporarily deleted and then the Trainer battle will initiate as normal.
    Then, once the battle is concluded, the deleted party members are re-added to the party.

    An example of using this code in an event would look like:
    Code:
    pbOneVsOneTrainerBattle(true, :YOUNGSTER, "Ben")

    Note that the inputted trainers will still have their full parties, its only the player's party that will be reduced to one member. So you'll have to make sure that the trainers you enter in the code also only have a party of 1 if that's what you want. Also note that if you allow the player to select a specific party member, but they cancel the selection before choosing one, you'll have to account for what happens in the event if that happens.
     
    Last edited:
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    It works, thank you!
    I changed it slightly, adding an "uncancel" true/false argument.

    Code:
    def pbOnevsOneTrainerBattle(choose, uncancel, trainerID, trainerName, endSpeech = nil, 
                                doubleBattle = false, trainerPartyID = 0, canLose = false, outcomeVar = 1)

    Code:
     if choose
        pbChooseAblePokemon(1, 2)
      else
        $Trainer.party.each_with_index do |pkmn, i|
          next if pkmn.egg? || pkmn.hp == 0
          $game_variables[1] = i
          break
        end
      end
      if uncancel
        if $game_variables[-1]
          $Trainer.party.each_with_index do |pkmn, i|
            next if pkmn.egg? || pkmn.hp == 0
            $game_variables[1] = i
            break
          end
        end
      end
    It makes you pick the first able Pokemon in the party if you decide to cancel. I mostly did that because I couldn't figure out how to register a "cancel" and manipulate an event when that happens, but I figured that out later.

    Well done, you'll definitely be getting credit for it, and thanks for the help!
     
  • 1,409
    Posts
    10
    Years
    • Seen today
    Ah i see. You didnt need to create a new argument for that solution though, you could have just used an "else" after the if statement that checks if the game variable is greater than or equal to zero, and then input your code if it isn't.
     
    Back
    Top