- 288
- Posts
- 6
- Years
- Seen Feb 3, 2025
I have already been working on this on a different thread, but now that this script is pretty much complete (I have done a decent amount of testing with it), I thought I'd share it in the scripts section and explain how to implement it (should work for v17.2 but haven't tested it with other versions). These scripts change the way movesets are generated to include a bit more variability. It can be annoying to have to use heart scales to get moves that you missed at earlier levels, but these scripts provide the possibility of Pokemon spawning with these moves. Also, there will be a little more randomness when fighting trainers who don't have their movesets already defined for them. The part that controls all this is def resetMoves in Pokebattle_Pokemon. There are a few ways you can include this in your game. In my game, I'm using separate moveset generation for trainer move generation and wild move generation, but you can keep it the same for both.
It is important to note that normally, a Pokemon's moveset will be determined as the last 4 moves before and up to the Pokemon's current level as defined in pokemon.txt. There are 3 variations that I made:
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen):
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen) but guarantees the first move slot to be occupied by a random STAB move present in its move list (if possible):
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen) but guarantees the first move slot to be occupied by a random damaging move present in its move list (if possible):
If you want to add TM and/or Egg moves to the move pool:
If you want movesets to be generated the same for all Pokemon, just replace everything in def resetMoves (in Pokebattle_Pokemon) with whichever version you want to use.
If you want movesets to be generated differently between wild and trainer Pokemon (I like to guarantee at least 1 damaging move for wild Pokemon and 1 STAB move for trainer Pokemon), you'll need to do a little more:
You might also consider using switches to turn these on and off, but it's not at all necessary.
I hope some of you find this useful, and please let me know if you find any problems or have any questions about it. Also, if you have suggestions for other variations of this (like guaranteeing the strongest STAB move as part of the moveset), let me know that as well and I'll consider making the code for it. Feel free to give me credit if you use this, but I don't require it.
It is important to note that normally, a Pokemon's moveset will be determined as the last 4 moves before and up to the Pokemon's current level as defined in pokemon.txt. There are 3 variations that I made:
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen):
Spoiler:
Code:
def resetMoves
moves=self.getMoveList
movelist=[]
for i in moves
if i[0]<=self.level
movelist[movelist.length]=i[1]
end
end
movelist|=[] # Remove duplicates
j=0
threshold=4
if movelist.length<4
threshold=movelist.length
end
leftover=4-threshold
while j<threshold
r=rand(movelist.length)
moveid=movelist[r]
@moves[j]=PBMove.new(moveid)
movelist.delete_at(r)
j+=1
end
while leftover > 0
@moves[4-leftover]=PBMove.new(0)
leftover-=1
end
end
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen) but guarantees the first move slot to be occupied by a random STAB move present in its move list (if possible):
Spoiler:
Code:
def resetMoves
moves=self.getMoveList
movelist=[]
for i in moves
if i[0]<=self.level
movelist[movelist.length]=i[1]
end
end
movelist|=[] # Remove duplicates
j=1
threshold=4
if movelist.length<4
threshold=movelist.length
end
leftover=4-threshold
stabmoves=[]
stabmoveindexes=[]
k=0
for i in movelist
temp=PBMove.new(i)
if self.hasType?(temp.type) && PBMoveData.new(temp.id).category!=2
stabmoves[stabmoves.length]=temp
stabmoveindexes[stabmoveindexes.length]=k
end
k+=1
end
if stabmoves.length!=0
r=rand(stabmoves.length)
@moves[0]=stabmoves[r] # Guarantees 1st move as STAB
movelist.delete_at(stabmoveindexes[r]) # Removes selected move from movelist
else
j=0
end
while j<threshold
r=rand(movelist.length)
moveid=movelist[r]
@moves[j]=PBMove.new(moveid)
movelist.delete_at(r)
j+=1
end
while leftover > 0
@moves[4-leftover]=PBMove.new(0)
leftover-=1
end
end
Generate moves as a random 4 out of all the moves the Pokemon learns up to its current level by leveling up (removes duplicate moves so that moves that appear twice in a Pokemon's levelup moves don't have a higher chance of being chosen) but guarantees the first move slot to be occupied by a random damaging move present in its move list (if possible):
Spoiler:
Code:
def wildResetMoves
moves=self.getMoveList
movelist=[]
for i in moves
if i[0]<=self.level
movelist[movelist.length]=i[1]
end
end
movelist|=[] # Remove duplicates
j=1
threshold=4
if movelist.length<4
threshold=movelist.length
end
leftover=4-threshold
damagemoves=[]
damagemoveindexes=[]
k=0
for i in movelist
temp=PBMove.new(i)
if PBMoveData.new(temp.id).category!=2
damagemoves[damagemoves.length]=temp
damagemoveindexes[damagemoveindexes.length]=k
end
k+=1
end
if damagemoves.length!=0
r=rand(damagemoves.length)
@moves[0]=damagemoves[r] # Guarantees 1st move as damaging
movelist.delete_at(damagemoveindexes[r]) # Removes selected move from movelist
else
j=0
end
while j<threshold
r=rand(movelist.length)
moveid=movelist[r]
@moves[j]=PBMove.new(moveid)
movelist.delete_at(r)
j+=1
end
while leftover > 0
@moves[4-leftover]=PBMove.new(0)
leftover-=1
end
end
If you want to add TM and/or Egg moves to the move pool:
Spoiler:
If you want to include Egg Moves (note that you'll have to define egg moves for evolved Pokemon in the PBS file for them to get these moves):
If you want to include TM Moves (doesn't work with tutor moves; note that including TMs makes it a bit slower):
Spoiler:
Find "movelist|=[] # Remove duplicates" and paste the following code directly above:
Code:
# Adds Egg Moves
pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
f.pos=(fSpecies-1)*8
offset=f.fgetdw
length=f.fgetdw
if length>0
f.pos=offset
i=0; loop do break unless i<length
atk=f.fgetw
movelist.push(atk)
i+=1
end
end
}
If you want to include TM Moves (doesn't work with tutor moves; note that including TMs makes it a bit slower):
Spoiler:
Find "movelist|=[] # Remove duplicates" and paste the following code directly above:
Code:
# Adds TM Moves
for i in 0...$ItemData.length
next if !$ItemData[i]
atk=$ItemData[i][ITEMMACHINE]
next if !atk || atk==0
if isCompatibleWithMove?(atk)
movelist.push(atk)
end
end
If you want movesets to be generated the same for all Pokemon, just replace everything in def resetMoves (in Pokebattle_Pokemon) with whichever version you want to use.
If you want movesets to be generated differently between wild and trainer Pokemon (I like to guarantee at least 1 damaging move for wild Pokemon and 1 STAB move for trainer Pokemon), you'll need to do a little more:
Spoiler:
The suggestion I give here is what I use, but you can obviously customize it to work how you want:
So first you'll want to copy the 2 out of the 3 code sections that you want to use. Find "def resetMoves" in Pokebattle_Pokemon and paste both of these sections between "def resetMoves" and "def pbLearnMove(move)". You'll notice how the 2 pasted sections also start with "def resetMoves". In order to distinguish them from the original, replace "def resetMoves" (just that line) in the ones that you pasted with "def trainerResetMoves" and "def wildResetMoves", respectively. Use trainerResetMoves for the one that you want to have activate for trainer battles and use wildResetMoves for the one that you want to have activate for wild battles.
Next, you'll need to go to PField_EncounterModifiers and add the following code at the bottom:
So first you'll want to copy the 2 out of the 3 code sections that you want to use. Find "def resetMoves" in Pokebattle_Pokemon and paste both of these sections between "def resetMoves" and "def pbLearnMove(move)". You'll notice how the 2 pasted sections also start with "def resetMoves". In order to distinguish them from the original, replace "def resetMoves" (just that line) in the ones that you pasted with "def trainerResetMoves" and "def wildResetMoves", respectively. Use trainerResetMoves for the one that you want to have activate for trainer battles and use wildResetMoves for the one that you want to have activate for wild battles.
Next, you'll need to go to PField_EncounterModifiers and add the following code at the bottom:
Code:
Events.onWildPokemonCreate+=proc {|sender,e|
pokemon=e[0]
pokemon.wildResetMoves
}
Events.onTrainerPartyLoad+=proc {|sender,e|
if e[0] # Trainer data should exist to be loaded, but may not exist somehow
party=e[0][2] # An array of the trainer's Pokémon
for pokemon in party
pokemon.trainerResetMoves
end
end
}
You might also consider using switches to turn these on and off, but it's not at all necessary.
I hope some of you find this useful, and please let me know if you find any problems or have any questions about it. Also, if you have suggestions for other variations of this (like guaranteeing the strongest STAB move as part of the moveset), let me know that as well and I'll consider making the code for it. Feel free to give me credit if you use this, but I don't require it.
Last edited: