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

Custom trainer battles

453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
This is the script I made that enables you to make custom trainer battles without editing the trainers
PBS file.

How to use
Make a new script in the script editor, name it however you like, say CustomTrainers
and copy and paste this code inside.

Spoiler:


To use it in the game, make a new event that looks like this:

Spoiler:


The game will enter the conditional branch if you won against the trainer, and that's where we
activate the self switch A on. And here's the second page of the event.

Spoiler:


The script code:
Spoiler:


You can change the number of pokemon the trainer has, the species, levels, everything. Once you
created a pokemon with createPokemon method, you can edit the pokemon's hp, IVs, EVs, stats,
and anything else.

For example, let's make a trainer that has only one pokemon, a pikachu, on level 13, and let's give
that pikachu some HP IVs, and let's make his hp half of his total hp. We'll set the id of the trainer
to 7, and make her name "Alice". The part of the event that changes is the script:

Spoiler:


Hope this comes in handy in your game too. I'm using this system instead of the original one.
No credits needed since half of the code is copied from essentials, but if you want, you can
give me half a credit!
 
Last edited:
129
Posts
14
Years
  • Age 24
  • Seen Sep 4, 2023
Would it be hard to implement a way for the trainer to use a random pokemon from a predefined array {pokemon1, pokemon2, pokemon3, ...}.

Thank you!
 
41
Posts
10
Years
Would it be hard to implement a way for the trainer to use a random pokemon from a predefined array {pokemon1, pokemon2, pokemon3, ...}.

Thank you!

Use too this parameters:
number poke into other number and add exetions
use a fix group in the script ex:(....Gorup1= 5,32,65,25... random pokemon Group1)
by Type (random pokemon(::FIRE,::BUG))

all with exceptions

thank you

wait update*-*
 
453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
Would it be hard to implement a way for the trainer to use a random pokemon from a predefined array {pokemon1, pokemon2, pokemon3, ...}.

Thank you!

Sure, it's not hard. Insert this method in the script.

Code:
# ------------------------------------------------------------------------------
# Returns a random element from a given array.
# ------------------------------------------------------------------------------
def randomElement(array)
  i = rand(array.length)
  return array[i]
end

Then, in the event, instead of writing createPokemon("PIKACHU", 13) you can write
createPokemon(randomElement(SomePool), 13), and you'll need to define 'SomePool',
either in the event script or in a global script (such as CustomTrainers) as,
Code:
SomePool = ["PIKACHU", "BULBASAUR", "SOME_OTHER_POKEMON"]

work fine *-*

thanks for this
olny descript the all funcions on your post for initials makers

Sorry, I don't understand. Do you want me to describe functions better?
 
41
Posts
10
Years
Sure, it's not hard. Insert this method in the script.

Code:
# ------------------------------------------------------------------------------
# Returns a random element from a given array.
# ------------------------------------------------------------------------------
def randomElement(array)
  i = rand(array.length)
  return array[i]
end

Then, in the event, instead of writing createPokemon("PIKACHU", 13) you can write
createPokemon(randomElement(SomePool), 13), and you'll need to define 'SomePool',
either in the event script or in a global script (such as CustomTrainers) as,
Code:
SomePool = ["PIKACHU", "BULBASAUR", "SOME_OTHER_POKEMON"]



Sorry, I don't understand. Do you want me to describe functions better?


Who add random pokes by Type?
you can send a script to implement this?
And with exceptions
Example:
createPokemon(randomType(SomePoolFire), 13)

SomePoolFire= [ (::FIRE);'charmander' , 'charmilion','charizand'] *This poke is the exception, can create all other pokes, ecept in "[...]"

Can make this?
thanks
 
453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
@miniking

Here, I've written a snippet that gives you all fire pokemon. Put it anywhere inside a global script, say CustomTrainers.

Code:
def allFireTypes
  dexdata=pbOpenDexData
  ret = []
  for i in 1...649
    pbDexDataOffset(dexdata, i, 8)
    type1 = dexdata.fgetb
    pbDexDataOffset(dexdata, i, 9)
    type2 = dexdata.fgetb
    if (isConst?(type1, PBTypes, :FIRE) || isConst?(type2, PBTypes, :FIRE))
      ret.push(getConstantName(PBSpecies, i))
    end
  end
  return ret
end

And then, to remove some pokemon from the array, that are listed in some other
array, use this (in an NPC event script, for example):

Code:
fire = allFireTypes()
except = ["RESHIRAM", "CHARIZARD"]
fire2 = fire.select {|p| !except.include?(p)}
p(fire2)

Array 'fire2' will contain all fire-type pokemon except for Reshiram and Charizard. You
can customize this however you wish :]
 

Dylanrockin

That guy
276
Posts
12
Years
  • Age 28
  • Seen Jun 9, 2016
Is there a possible way to edit their EV's as well? Nevermind I got a syntax error upon starting up the game :L on line 14 for some reason :L
 
Last edited:
453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
Is there a possible way to edit their EV's as well? Nevermind I got a syntax error upon starting up the game :L on line 14 for some reason :L

Yep, you can change anything you like :] Take a look at PokeBattle_Pokemon. Whatever you see
here (after attr_accessor) is changeable.

Spoiler:


So, for example, to change their EVs, you would say: pokemon.ev[0] = 125 (this will make their HP
evs be 125). The IVs and EVs are ordered like this: HP, Atk, Def, Speed, Sp Atk, and Sp Def

Is it a syntax error in my script? If so, what's on line 14? If it's in an event, make sure you typed
the script correctly.
 

Radical Raptr

#BAMFPokemonNerd
1,121
Posts
13
Years
First, this is amazing, and I finally got around to using it, and it should most definitly save me time, thank you.

Secondly, as for the syntax error, the part where you have the comment description thing, eg:

# ------------------------------------------------------------------------------
# species - Name of the species, e.g. "PIKACHU"
# level - Level
# moveset - Optional. Array of moves, e.g. [:MUDSLAP, :THUNDERBOLT, :VINEWHIP]
# If not specified, pokemon will be created with moves learned by leveling.
# The pokemon doesn't need to be able to learn the given moves, they can be
# arbitary.
# ------------------------------------------------------------------------------
you are missing the red, I noticed and changed it and it works fine - I don't know if that was the problem, but it happened to me before I changed it, but not after :P
 
378
Posts
10
Years
  • Seen Oct 18, 2017
Some of the lines with comments do not have "#" symbols. I had line 62, but apparently some had others. An alternate way of commenting multiple lines is a "=begin" command and an "=end" command. "=end" goes at the end of the section you want commented.
 

FlexxGaming

Pokemon XY PC Edition Developer
78
Posts
9
Years
  • Age 28
  • Seen Jul 16, 2015
Ooooh this is really nifty! Definitely going to use it for when I start programming the Battle Maison!
 
453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
I second this. Are double battles possible?

Yes, add another argument (true) to the customTrainerBattle call.
So instead of

Code:
customTrainerBattle(trainer, "Oh no!")

Write

Code:
customTrainerBattle(trainer, "Oh no!", [B]true[/B])

And you have a double battle :] Also make sure your opponent
has an even number of pokemon.
 
56
Posts
10
Years
  • Age 33
  • Seen Sep 29, 2015
Yes, add another argument (true) to the customTrainerBattle call.
So instead of

Code:
customTrainerBattle(trainer, "Oh no!")

Write

Code:
customTrainerBattle(trainer, "Oh no!", [B]true[/B])

And you have a double battle :] Also make sure your opponent
has an even number of pokemon.

Hmm, maybe I'm doing something wrong but it didn't work for me. Here is the instance I tried it on.

p0 = createPokemon("EKANS", 2)
p1 = createPokemon("RATTATA", 3)
party = [p0, p1]
trainer = createTrainer(37, "Dillon", party)
result = customTrainerBattle(trainer, "Maybe I was wrong.", true)
pbSet(1, result == BR_WIN ? 0 : 1)

When I tried it only Ekans was used.

Cheers!

indieoutloud
 
453
Posts
10
Years
  • Age 32
  • Seen Apr 17, 2024
Hmm, maybe I'm doing something wrong but it didn't work for me. Here is the instance I tried it on.

p0 = createPokemon("EKANS", 2)
p1 = createPokemon("RATTATA", 3)
party = [p0, p1]
trainer = createTrainer(37, "Dillon", party)
result = customTrainerBattle(trainer, "Maybe I was wrong.", true)
pbSet(1, result == BR_WIN ? 0 : 1)

When I tried it only Ekans was used.

Cheers!

indieoutloud

Make sure you also have two pokemon on your party.
I've tested it just now and it should work.
 
5
Posts
14
Years
  • Seen Feb 14, 2015
Hmmm, I'm having quite a few a problems with the pokemons stats. I have the following script to define a pokemon:

p0 = createPokemon("TYRANITAR",100)
p0.natureflag=PBNatures::JOLLY
p0.iv[1]=31
p0.ev[1]=252 (I've also set this to zero while experimenting)

party = [p0]
trainer = createTrainer(1,"Camila",party)
result = customTrainerBattle(trainer,"..")
pbSet(1, result == BR_WIN ? 0 : 1)

A jolly Tyranitar should have 304 attack with 0 Atk EVs and 367 Attack with 252 EVs at level 100. The game currently tells me Tyranitar's attack stat is less than 304 which is wrong.

Looking into where essentials calculates a pokemons stats I saw the found formula:

((((base*2+iv+(ev>>2))*level/100).floor+5)*pv/100).floor

Apparently ev>>2 is the binary right shift operator (not sure how exactly this works) which didn't really make sense to me as I always seen the formula with ev/4 in it.

Changing the formula to ev/4, I get that a jolly Tyranitar with 0EV's has an attack stat of 304 as desired. However, with 252 attacking EVs I still get the attack stat being 304.

Any idea what's going on?

P.S. After reading a bit, ev>>2 should be equivalent to ev/4 if I understand correctly, and I changed the forumla back to ev>>2 and it still yields the correct 304 stat, so I'm not sure what I did wrong to get an attack stat less than 304 was about. Regardless, the problem with the EVs not doing anything still exists.
 
Last edited:
5
Posts
14
Years
  • Seen Feb 14, 2015
Go figure, after hours of struggling with this problem, I figured it 30 minutes after posting.

Not sure if everyone else here figured this out, but its not mentioned in the previous posts so I'll post it anyways. Basically, the game doesn't recalculate a pokemon's stats after editing IVs, EVs, or natures. Thus, if you edit any of these outside the "createPokemon()" function, none of these changes will effect its battle stats in anyway. I verified this in battle with damage calculations.

I easily solved this problem by just adding the line "pokemon.calcStats" (or in the case I posted above p0.calcStats) after editing all the other stuff.
 
Back
Top