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

PvP Script

1,748
Posts
14
Years
  • Okay, well it's not EXACTLY PvP, it's actually just player vs. player's party controlled by an AI. script... But close enough... right?


    Code:
    ################################################################################
    # PvP Script
    # By Hansiec
    # Credits Required
    ################################################################################
    # NOTICE: By PvP this does NOT really mean player vs player, it's more like
    #         player vs other player's party controlled by an AI.
    #
    # To use:
    #   * Create a folder in your game's folder called "Trainers" (otherwise there
    #       WILL be errors)
    #   * Call "PVP.open"
    #
    ################################################################################
    
    class TrainerPackage
      attr_accessor :trainer
      attr_accessor :start_speech
      attr_accessor :lose_speech
      attr_accessor :win_speech
      attr_accessor :game_code
    end
    
    module PVP
      def self.open
        loop do
          commands = []
          commands[cmdDump=commands.length] = "Create Trainer Data"
          commands[cmdBattle=commands.length] = "Battle a Trainer"
          commands[cmdExit=commands.length] = "Exit"
          choice = Kernel.pbMessage(_INTL("Welcome to the PVP station, how may I help you?"),
          commands, 0, nil, 0)
          if choice == cmdDump
            if PVPCore.createTrainerFile
              Kernel.pbMessage(_INTL("Successfully made trainer data to: Trainers/#{$Trainer.name}'s Trainer.tpk"))
            else
              Kernel.pbMessage(_INTL("Could not make trainer data"))
            end
          elsif choice == cmdBattle
            files = ["Cancel"]
            Dir.chdir("Trainers"){
              Dir.glob("*.tpk"){|f|
                files.push(f)
              }
            }
            choice = Kernel.pbMessage(_INTL("select a trainer file"), files, -1, nil, 0)
            if choice >= 1
              file = "Trainers/" + files[choice]
              trainer = PVPCore.loadTrainer(file)
              if trainer
                PVPCore.battleTrainer(trainer)
              else
                Kernel.pbMessage(_INTL("Cannot load trainer file..."))
              end
            end
          elsif choice == cmdExit
            break
          end
        end
      end
    end
    
    module PVPCore
      # Pokemon that cannot, no matter what be accepted.
      BLACK_LIST = [
        PBSpecies::MEWTWO,
        PBSpecies::MEW,
        PBSpecies::HOOH,
        PBSpecies::LUGIA,
        PBSpecies::CELEBI,
        PBSpecies::KYOGRE,
        PBSpecies::GROUDON,
        PBSpecies::RAYQUAZA,
        PBSpecies::DEOXYS,
        PBSpecies::JIRACHI,
        PBSpecies::DIALGA,
        PBSpecies::PALKIA,
        PBSpecies::GIRATINA,
        PBSpecies::HEATRAN,
        PBSpecies::DARKRAI,
        PBSpecies::SHAYMIN,
        PBSpecies::ARCEUS,
        PBSpecies::ZEKROM,
        PBSpecies::RESHIRAM,
        PBSpecies::KYUREM,
        PBSpecies::LANDORUS,
        PBSpecies::MELOETTA,
        PBSpecies::KELDEO,
        PBSpecies::GENESECT
      ]
      
      def self.partyEligible?(party=$Trainer.party)
        for i in party
          if BLACK_LIST.include?(i.species) || i.egg?
            return false
          end
        end
        return true
      end
      
      def self.getBannedPokemonString
        string = PBSpecies.getName(BLACK_LIST[0])
        for i in 1...BLACK_LIST.length-1
          string += ", " + PBSpecies.getName(BLACK_LIST[i])
        end
        string += ", and " + PBSpecies.getName(BLACK_LIST[BLACK_LIST.length - 1])
      end
      
      def self.createTrainerFile
        pre=Kernel.pbMessageFreeText("Enter the speech for when you are challenged", "Battle me, Now!", false, 256)
        win=Kernel.pbMessageFreeText("Enter the speech for when you win", "I win!", false, 256)
        lose=Kernel.pbMessageFreeText("Enter the speech for when you lost", "I Lost...", false, 256)
        return dumpTrainer(pre, win, lose)
      end
        
      def self.dumpTrainer(pre, win, lose)
        f = File.open("Game.ini")
        lines = f.readlines()
        s = lines[3]
        len = s.size
        title = (s[6,len - 7])
        f.close
        if !partyEligible?
          Kernel.pbMessage(_INTL("Sorry, but the trainer file could not be created.\n"+
          "This may be because you have a banned pokemon or an egg in your party."+
          "\n Banned Pokemon Are: "+getBannedPokemonString + "."))
          return false
        end
        tp = TrainerPackage.new
        tp.trainer = $Trainer
        tp.game_code = title
        tp.start_speech = pre
        tp.win_speech = win
        tp.lose_speech = lose
        save_data(tp, "Trainers/#{$Trainer.name}'s Trainer.tpk")
        return true
      rescue
        return nil
      end
      
      def self.loadTrainer(file)
        f = File.open("Game.ini")
        lines = f.readlines()
        s = lines[3]
        len = s.size
        title = (s[6,len - 7])
        f.close
        tp = load_data(file)
        return false if tp.game_code != title
        return [tp.trainer, tp.start_speech, tp.lose_speech, tp.win_speech]
      rescue
        return nil
      end
      
      def self.battleTrainer(file)
        trainer = file
        trainer = loadTrainer(file) if !file.is_a?(Array)
        return false if !trainer
        Kernel.pbMessage(_INTL(trainer[1]))
        return pbOrganizedBattleEx(trainer[0],nil,trainer[2],trainer[3])
      end
      
    end


    To use, simply call: "PVP.open", ALSO, BE SURE TO CREATE A FOLDER CALLED "Trainers" OR THIS SCRIPT WILL FAIL!
     
    Last edited:
    423
    Posts
    13
    Years
    • Seen Aug 31, 2023
    ok one question how do we get other trainers info file? and does this allow mega evolution?
     
    1,748
    Posts
    14
    Years
  • ok one question how do we get other trainers info file? and does this allow mega evolution?

    Just say "Create Trainer Data" as an option, you're actually going to have to post the file somewhere where people can download it (I was to lazy to implement a server like I did with my GTS system) and then you insert it into the "Trainers" folder you had to create to use the script. As for mega evolutions maybe, maybe not. It depends on your essentials version and if and Organised Battle allows it (the battles used normally for Battling other players, Battle Tower trainers, ect.)
     
    423
    Posts
    13
    Years
    • Seen Aug 31, 2023
    ok fair enough sounds ok and i guess could also be used offline if you have trainer data already saved
     

    venom12

    Pokemon Crystal Rain Relased
    476
    Posts
    17
    Years
    • Age 33
    • Seen Dec 28, 2023
    OMG MAN :O I didnt expected that :D My remake with those features will be awesome :D Thanks man.
     

    Skystrike

    [i]As old as time itself.[/i]
    1,641
    Posts
    15
    Years
  • This looks great! I'll be using this one too.
    You sure are coming out with a few scripts...what's next?
     
    Last edited:
    302
    Posts
    13
    Years
    • Seen Aug 25, 2014
    So... Forgive me for not quite understanding what you just posted, but how does this work?

    I get the folder creation and all, but when you say "simply call: 'PVP.open'" what do you mean? Is it a script call through the event editor, or something else?

    Also, how will other players be able to extract their team data from the game?
     

    venom12

    Pokemon Crystal Rain Relased
    476
    Posts
    17
    Years
    • Age 33
    • Seen Dec 28, 2023
    So... Forgive me for not quite understanding what you just posted, but how does this work?

    I get the folder creation and all, but when you say "simply call: 'PVP.open'" what do you mean? Is it a script call through the event editor, or something else?

    Also, how will other players be able to extract their team data from the game?

    For the open script just use call script from event command on page 3.

    For the data extract simply they will use command "Creata Trainer Data" from this script.
     
    1,748
    Posts
    14
    Years
  • For Pokémon eligibility, make sure to check for eggs too.

    Dang, this was at the bottom of my head when making this, thanks for pointing it out though!


    Edit: I just added checks against eggs, and now if you don't have an eligible pokemon, it will tell you that one or more pokemon are not eligible.
     
    Last edited:
    60
    Posts
    13
    Years
    • Seen Jun 2, 2023
    I constantly get a "Could not make trainer data" error, what did I do wrong, I did everything I should.
     
    60
    Posts
    13
    Years
    • Seen Jun 2, 2023
    Perhaps it's because of some other scripts I'm using... I could try it on a clean Pokemon Essentials and see if it works.
     
    Back
    Top