The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script PvP Script

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old January 26th, 2014 (6:45 PM). Edited November 12th, 2014 by Umbra.
Umbra's Avatar
Umbra Umbra is offline
  • Platinum Tier
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 20
Gender: Female
Nature: Calm
Posts: 1,742
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!
Reply With Quote

Relevant Advertising!

  #2    
Old January 26th, 2014 (7:31 PM).
p.claydon p.claydon is offline
     
    Join Date: Jan 2011
    Gender:
    Posts: 335
    ok one question how do we get other trainers info file? and does this allow mega evolution?
    __________________
    Still learning how to sprite but if you want to look at my progress then here you go
    http://pclaydon.deviantart.com/gallery/
    Reply With Quote
      #3    
    Old January 26th, 2014 (7:41 PM).
    Umbra's Avatar
    Umbra Umbra is offline
    • Platinum Tier
     
    Join Date: Aug 2009
    Location: Nearby my feet.
    Age: 20
    Gender: Female
    Nature: Calm
    Posts: 1,742
    Quote:
    Originally Posted by p.claydon View Post
    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.)
    Reply With Quote
      #4    
    Old January 26th, 2014 (7:44 PM).
    p.claydon p.claydon is offline
       
      Join Date: Jan 2011
      Gender:
      Posts: 335
      ok fair enough sounds ok and i guess could also be used offline if you have trainer data already saved
      __________________
      Still learning how to sprite but if you want to look at my progress then here you go
      http://pclaydon.deviantart.com/gallery/
      Reply With Quote
        #5    
      Old January 26th, 2014 (7:45 PM).
      Umbra's Avatar
      Umbra Umbra is offline
      • Platinum Tier
       
      Join Date: Aug 2009
      Location: Nearby my feet.
      Age: 20
      Gender: Female
      Nature: Calm
      Posts: 1,742
      Quote:
      Originally Posted by p.claydon View Post
      ok fair enough sounds ok and i guess could also be used offline if you have trainer data already saved
      Yes, I don't see why you need an internet connection for a file saved on your computer
      Reply With Quote
        #6    
      Old January 26th, 2014 (9:36 PM).
      Cuflock's Avatar
      Cuflock Cuflock is offline
         
        Join Date: Mar 2012
        Posts: 11
        Thanks! It works very good, and It's awesome!
        Reply With Quote
          #7    
        Old January 27th, 2014 (1:21 AM).
        Luka S.J.'s Avatar
        Luka S.J. Luka S.J. is offline
        Jealous Croatian
           
          Join Date: Dec 2008
          Location: Croatia
          Age: 23
          Gender: Male
          Nature: Adamant
          Posts: 1,087
          For Pokémon eligibility, make sure to check for eggs too.
          Reply With Quote
            #8    
          Old January 27th, 2014 (2:48 AM).
          venom12's Avatar
          venom12 venom12 is offline
          Pokemon Crystal Rain Relased
             
            Join Date: Sep 2006
            Age: 26
            Gender: Male
            Nature: Adamant
            Posts: 528
            Send a message via Windows Live Messenger to venom12
            OMG MAN :O I didnt expected that :D My remake with those features will be awesome :D Thanks man.
            Reply With Quote
              #9    
            Old January 27th, 2014 (5:35 AM). Edited January 27th, 2014 by Skystrike.
            Skystrike's Avatar
            Skystrike Skystrike is offline
            • Silver Tier
             
            Join Date: Sep 2008
            Location: internet
            Gender: Male
            Nature: Quiet
            Posts: 1,533
            This looks great! I'll be using this one too.
            You sure are coming out with a few scripts...what's next?
            Reply With Quote
              #10    
            Old January 27th, 2014 (4:50 PM).
            Ratty524's Avatar
            Ratty524 Ratty524 is offline
               
              Join Date: Jan 2011
              Gender: Male
              Nature: Calm
              Posts: 303
              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?
              Reply With Quote
                #11    
              Old January 27th, 2014 (4:55 PM).
              venom12's Avatar
              venom12 venom12 is offline
              Pokemon Crystal Rain Relased
                 
                Join Date: Sep 2006
                Age: 26
                Gender: Male
                Nature: Adamant
                Posts: 528
                Send a message via Windows Live Messenger to venom12
                Quote:
                Originally Posted by Ratty524 View Post
                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.
                Reply With Quote
                  #12    
                Old January 27th, 2014 (6:34 PM). Edited January 27th, 2014 by Umbra.
                Umbra's Avatar
                Umbra Umbra is offline
                • Platinum Tier
                 
                Join Date: Aug 2009
                Location: Nearby my feet.
                Age: 20
                Gender: Female
                Nature: Calm
                Posts: 1,742
                Quote:
                Originally Posted by Luka S.J. View Post
                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.
                Reply With Quote
                  #13    
                Old January 31st, 2014 (10:52 AM).
                bartyboy6's Avatar
                bartyboy6 bartyboy6 is offline
                   
                  Join Date: Sep 2010
                  Gender: Male
                  Posts: 56
                  I constantly get a "Could not make trainer data" error, what did I do wrong, I did everything I should.
                  Reply With Quote
                    #14    
                  Old January 31st, 2014 (4:23 PM).
                  Umbra's Avatar
                  Umbra Umbra is offline
                  • Platinum Tier
                   
                  Join Date: Aug 2009
                  Location: Nearby my feet.
                  Age: 20
                  Gender: Female
                  Nature: Calm
                  Posts: 1,742
                  Quote:
                  Originally Posted by bartyboy6 View Post
                  I constantly get a "Could not make trainer data" error, what did I do wrong, I did everything I should.
                  Did you add the "Trainers" folder in the root of your game (the root is the folder that contains Game.exe, Game.rpgproj, and all the sub-folders for resources)
                  Reply With Quote
                    #15    
                  Old February 1st, 2014 (6:53 AM).
                  bartyboy6's Avatar
                  bartyboy6 bartyboy6 is offline
                     
                    Join Date: Sep 2010
                    Gender: Male
                    Posts: 56
                    I did but it still gives me this error...
                    Reply With Quote
                      #16    
                    Old February 1st, 2014 (10:15 AM).
                    Rayd12smitty's Avatar
                    Rayd12smitty Rayd12smitty is offline
                    Shadow Maker
                       
                      Join Date: Dec 2011
                      Gender: Male
                      Posts: 647
                      Quote:
                      Originally Posted by bartyboy6 View Post
                      I did but it still gives me this error...
                      Do you have a legendary or egg in your party?
                      __________________
                      Reply With Quote
                        #17    
                      Old February 1st, 2014 (4:04 PM).
                      Umbra's Avatar
                      Umbra Umbra is offline
                      • Platinum Tier
                       
                      Join Date: Aug 2009
                      Location: Nearby my feet.
                      Age: 20
                      Gender: Female
                      Nature: Calm
                      Posts: 1,742
                      Quote:
                      Originally Posted by bartyboy6 View Post
                      I did but it still gives me this error...
                      Again what Rayd12Smitty said, if you have a legendary or an egg it won't work otherwise I have no clue, I don't get any errors and no one else has had one (that I know of)
                      Reply With Quote
                        #18    
                      Old February 2nd, 2014 (2:01 AM).
                      bartyboy6's Avatar
                      bartyboy6 bartyboy6 is offline
                         
                        Join Date: Sep 2010
                        Gender: Male
                        Posts: 56
                        I have a Latios, but it's not on the banned list last time I checked...
                        Reply With Quote
                          #19    
                        Old February 2nd, 2014 (4:02 PM).
                        Umbra's Avatar
                        Umbra Umbra is offline
                        • Platinum Tier
                         
                        Join Date: Aug 2009
                        Location: Nearby my feet.
                        Age: 20
                        Gender: Female
                        Nature: Calm
                        Posts: 1,742
                        Quote:
                        Originally Posted by bartyboy6 View Post
                        I have a Latios, but it's not on the banned list last time I checked...
                        I have no idea what your problem could be
                        Reply With Quote
                          #20    
                        Old February 3rd, 2014 (3:39 AM).
                        bartyboy6's Avatar
                        bartyboy6 bartyboy6 is offline
                           
                          Join Date: Sep 2010
                          Gender: Male
                          Posts: 56
                          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.
                          Reply With Quote
                            #21    
                          Old February 3rd, 2014 (4:24 PM).
                          Umbra's Avatar
                          Umbra Umbra is offline
                          • Platinum Tier
                           
                          Join Date: Aug 2009
                          Location: Nearby my feet.
                          Age: 20
                          Gender: Female
                          Nature: Calm
                          Posts: 1,742
                          Quote:
                          Originally Posted by bartyboy6 View Post
                          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.
                          I don't think it's really that, all my scripts are highly flexible, they should support modifications to any and all of the classes used by them... But you could try, I could be wrong
                          Reply With Quote
                            #22    
                          Old February 3rd, 2014 (6:14 PM).
                          ShadowFiendZX's Avatar
                          ShadowFiendZX ShadowFiendZX is offline
                          Gym Leader
                             
                            Join Date: Jan 2013
                            Location: Hamden Connecticut
                            Age: 20
                            Gender: Male
                            Nature: Serious
                            Posts: 59
                            I decided to try this script, same thing. "Could not make trainer" I was using a bulbasaur, sandslash, and abra.
                            __________________
                            BEHOLD THE FLOPPY MAGIKARP IN ALL ITS GLORY AND WISDOM

                            Reply With Quote
                              #23    
                            Old February 3rd, 2014 (6:15 PM).
                            Umbra's Avatar
                            Umbra Umbra is offline
                            • Platinum Tier
                             
                            Join Date: Aug 2009
                            Location: Nearby my feet.
                            Age: 20
                            Gender: Female
                            Nature: Calm
                            Posts: 1,742
                            Okay, I found the error, it was something with my script, it should work fine now
                            Reply With Quote
                              #24    
                            Old February 5th, 2014 (11:20 AM).
                            dydd90's Avatar
                            dydd90 dydd90 is offline
                               
                              Join Date: Dec 2013
                              Location: Italy
                              Gender: Male
                              Posts: 238
                              It is a very interesting script thank you friend
                              __________________


                              Reply With Quote
                                #25    
                              Old February 16th, 2014 (1:11 PM).
                              felixcruzer felixcruzer is offline
                                 
                                Join Date: May 2012
                                Gender: Male
                                Posts: 16
                                i got a very early version of this script, i try it now again i hope the creator fixed these brute bugs

                                regards
                                Reply With Quote
                                Reply
                                Quick Reply

                                Sponsored Links
                                Thread Tools

                                Posting Rules
                                You may not post new threads
                                You may not post replies
                                You may not post attachments
                                You may not edit your posts

                                BB code is On
                                Smilies are On
                                [IMG] code is On
                                HTML code is Off

                                Forum Jump


                                All times are GMT -8. The time now is 12:14 AM.