- 386
- Posts
- 18
- Years
- Seen Aug 10, 2015
Regional Pokedex numbers have been included for a long time, but I didn't write any support functions for them. Now I've done so. Put the code below in the script section PokemonUtilities, and read the comments to learn how to use these functions.
Code:
def pbGetRegionalNumber(region, nationalSpecies)
# Gets the regional Pokedex number of
# the national species for the specified region.
# The parameter "region" is zero-based. For
# example, if two regions are defined, they would
# each be specified as 0 and 1.
if nationalSpecies<=0 || nationalSpecies>PBSpecies.getCount
# Return 0 if national species is outside range
return 0
end
pbRgssOpen("Data/regionals.dat","rb"){|f|
numRegions=f.fgetw
numDexDatas=f.fgetw
if region>=0 && region<numRegions
f.pos=4+region*numDexDatas*2
f.pos+=nationalSpecies*2
return f.fgetw
end
}
return 0
end
def pbGetNationalNumber(region, regionalSpecies)
# Gets the national Pokedex number of
# the specified species and region.
# The parameter "region" is zero-based. For
# example, if two regions are defined, they would
# each be specified as 0 and 1.
pbRgssOpen("Data/regionals.dat","rb"){|f|
numRegions=f.fgetw
numDexDatas=f.fgetw
if region>=0 && region<numRegions
f.pos=4+region*numDexDatas*2
# "i" specifies the national species
for i in 0...numDexDatas
regionalNum=f.fgetw
if regionalNum==regionalSpecies
return i
end
end
end
}
return 0
end
def pbAllRegionalSpecies(region)
# Gets an array of all national species
# within a regional Pokedex, sorted by
# regional Pokedex number.
# The number of items in the array should be
# the number of species in the regional Pokedex plus
# 1, since index 0 is considered to be empty.
# The parameter "region" is zero-based. For
# example, if two regions are defined, they would
# each be specified as 0 and 1.
ret=[0]
pbRgssOpen("Data/regionals.dat","rb"){|f|
numRegions=f.fgetw
numDexDatas=f.fgetw
if region>=0 && region<numRegions
f.pos=4+region*numDexDatas*2
# "i" specifies the national species
for i in 0...numDexDatas
regionalNum=f.fgetw
ret[regionalNum]=i if regionalNum!=0
end
# Replace unspecified regional
# numbers with zeros
for i in 0...ret.length
ret[i]=0 if !ret[i]
end
end
}
return ret
end