UPC Forums - View topic - Problem with PokemonUtilities Script
Discussion boards for The Ultimate Pokemon Center
Problem with PokemonUtilities Script
- Brandon (Posted: Sun, Oct 25, 2009 8:18 am) [Quote Post]
I've modified some scripts to set in the game alternate forms for smeargle (yes, smeargle). I could fix some errors, but I can't fix the last error, the error is in PokemonUtilities Script. This is my script:
module PBDayNight # Screen tints for each hour of the day. HourlyTones=[ Tone.new(-142.5,-142.5,-22.5,68), Tone.new(-135.5,-135.5,-24,68), Tone.new(-127.5,-127.5,-25.5,68), Tone.new(-127.5,-127.5,-25.5,68), Tone.new(-119,-96.3,-45.3,45.3), Tone.new(-51,-73.7,-73.7,22.7), Tone.new(17,-51,-102,0), Tone.new(14.2,-42.5,-85,0), Tone.new(11.3,-34,-68,0), Tone.new(8.5,-25.5,-51,0), Tone.new(5.7,-17,-34,0), Tone.new(2.8,-8.5,-17,0), Tone.new(0,0,0,0), Tone.new(0,0,0,0), Tone.new(0,0,0,0), Tone.new(0,0,0,0), Tone.new(-3,-7,-2,0), Tone.new(-10,-18,-5,0), Tone.new(-36,-75,-13,0), Tone.new(-72,-136,-34,3), Tone.new(-88.5,-133,-31,34), Tone.new(-108.5,-129,-28,68), Tone.new(-127.5,-127.5,-25.5,68), Tone.new(-142.5,-142.5,-22.5,68) ] SummerAdjustment=[ 0, 0.5, 1, 1.5, 2, 3.5, 5, 6.5, 7.5, 9, 10, 11, 12, 13, 15, 17, 17.75, 19.25, 21, 21, 22, 22, 23, 23] WinterAdjustment=[ 0, 0.5, 1, 1.5, 2, 3.5, 5, 6.5, 7.5, 9, 10, 11, 12, 14, 16, 18.5, 19.5, 20.75, 21.5, 22, 22.25, 22.75, 23.25, 23.75] SummerMultiplier=[0.0, 0.1, 0.2, 0.5, 0.7, 0.8, 1.0, 0.95, 0.8, 0.5, 0.2, 0.05] WinterMultiplier= [1.0, 0.9, 0.8, 0.5, 0.3, 0.2, 0.0, 0.05, 0.2, 0.5, 0.8, 0.95] end # Similar to pbFadeOutIn, but pauses the music # as it fades out. def pbFadeOutInWithMusic(zViewport) playingBGS=$game_system.getPlayingBGS playingBGM=$game_system.getPlayingBGM $game_system.bgm_pause(1.0) $game_system.bgs_pause(1.0) pos=$game_system.bgm_position pbFadeOutIn(zViewport) { yield $game_system.bgm_position=pos $game_system.bgm_resume(playingBGM) $game_system.bgs_resume(playingBGS) } end def pbSetDayNightTone(toneToSet) now=Time.now # Get the current system time hour=now.hour minute=now.min month=now.mon-1 nextMonth=(month+1)%12 nextHour=hour==0 ? 23 : hour-1 dayPosition=month==1 ? ([28,now.mday].min-1)/28.0 : ([30,now.mday].min-1)/30.0 summerMult=PBDayNight::SummerMultiplier[month]*1.0; summerMult+=(PBDayNight::SummerMultiplier[nextMonth]-PBDayNight::SummerMultiplier[month])*dayPosition winterMult=PBDayNight::WinterMultiplier[month]*1.0; winterMult+=(PBDayNight::WinterMultiplier[nextMonth]-PBDayNight::WinterMultiplier[month])*dayPosition realHour=PBDayNight::SummerAdjustment[hour]*summerMult+ PBDayNight::WinterAdjustment[hour]*winterMult realNextHour=PBDayNight::SummerAdjustment[nextHour]*summerMult+ PBDayNight::WinterAdjustment[nextHour]*winterMult realMinutes=realHour+((realNextHour-realHour)*(minute/60.0)) realMinutes=((realMinutes*60).to_i)%(60*24) hour=realMinutes/60 minute=realMinutes%60 tone=PBDayNight::HourlyTones[hour] nexthourtone=PBDayNight::HourlyTones[(hour+1)%24] # Calculate current tint according to current and next hour's tint and # depending on current minute toneToSet.red = ((nexthourtone.red-tone.red)*minute/60.0)+tone.red toneToSet.green = ((nexthourtone.green-tone.green)*minute/60.0)+tone.green toneToSet.blue = ((nexthourtone.blue-tone.blue)*minute/60.0)+tone.blue toneToSet.gray = ((nexthourtone.gray-tone.gray)*minute/60.0)+tone.gray end def pbIsWeekday(wdayVariable,*arg) wday=Time.now.wday ret=false for wd in arg ret=true if wd==wday end if wdayVariable>=0 $game_variables[wdayVariable]=[ _INTL("Domingo"), _INTL("Lunes"), _INTL("Martes"), _INTL("Miércoles"), _INTL("Jueves"), _INTL("Viernes"), _INTL("Sábado") ][wday] end return ret end def printException(e) s="" e.backtrace.each do |i| s=s+"#{i}\r\n" end s.gsub!(/Section(\d+)/){$RGSS_SCRIPTS[$1.to_i][1]} print(s) if "#{e.class}"=="Reset" || e.is_a?(SystemExit) raise e end if !printRetry("#{e.message}\r\n#{s}") return end end def isConst?(val,mod,constant) begin isdef=mod.const_defined?(constant.to_sym) return false if !isdef rescue return false end return (val==mod.const_get(constant.to_sym)) end def hasConst?(mod,constant) begin return mod.const_defined?(constant.to_sym) rescue return false end end def pbShowMap pbFadeOutIn(99999) { scene=PokemonRegionMapScene.new screen=PokemonRegionMap.new(scene) screen.pbStartScreen } end #For demonstration purposes only, not to be used in a real game. def pbCreatePokemon party=[] party.push(PBSpecies::PIKACHU) if hasConst?(PBSpecies,:PIKACHU) party.push(PBSpecies::SQUIRTLE) if hasConst?(PBSpecies,:SQUIRTLE) party.push(PBSpecies::CHARMANDER) if hasConst?(PBSpecies,:CHARMANDER) party.push(PBSpecies::TURTWIG) if hasConst?(PBSpecies,:TURTWIG) party.push(PBSpecies::CHIMCHAR) if hasConst?(PBSpecies,:CHIMCHAR) party.push(PBSpecies::PIPLUP) if hasConst?(PBSpecies,:PIPLUP) # Species IDs of the Pokémon to be created for i in 0...party.length species=party[i] # Generate Pokémon with species and level 20 $Trainer.party[i]=PokeBattle_Pokemon.new(species,20,$Trainer) $Trainer.seen[species]=true # Set this species to seen and owned $Trainer.owned[species]=true end end def pbBoxesFull? return $Trainer.party.length==6 && $PokemonStorage.full? end def pbPlayCry(pokemon,volume=90,pitch=nil) return if !pokemon if pokemon.is_a?(Numeric) pkmnwav=sprintf("Audio/SE/%03dCry",pokemon) Audio.se_play(pkmnwav,volume,pitch ? pitch : 100) rescue nil elsif !pokemon.egg? if pokemon.respond_to?("chatter") && pokemon.chatter pokemon.chatter.play else pkmnwav=sprintf("Audio/SE/%03dCry.wav",pokemon.species) Audio.se_play(pkmnwav,volume,pitch ? pitch : (pokemon.hp*25/pokemon.totalhp)+75) rescue nil end end end def pbStorePokemon(pokemon) if pbBoxesFull? Kernel.pbMessage(_INTL("ˇAquí no hay más sitio para los Pokémon!\1")) Kernel.pbMessage(_INTL("ˇLas cajas Pokémon están llenas y no cabe nada más!")) return end if $Trainer.party.length<6 $Trainer.party[$Trainer.party.length]=pokemon else oldcurbox=$PokemonStorage.currentBox storedbox=$PokemonStorage.pbStoreCaught(pokemon) curboxname=$PokemonStorage[oldcurbox].name boxname=$PokemonStorage[storedbox].name creator=nil if $PokemonGlobal.seenStorageCreator creator=pbGetStorageCreator end if storedbox!=oldcurbox if creator Kernel.pbMessage(_INTL("La caja \"{1}\" del PC de {2}está llena.\1",curboxname,creator)) else Kernel.pbMessage(_INTL("La caja \"{1}\" del PC de alguien está llena.\1",curboxname)) end Kernel.pbMessage(_INTL("{1} fue transferido a la caja \"{2}.\"",pokemon.name,boxname)) else if creator Kernel.pbMessage(_INTL("{1} fue transferido al PC de {2}.\1",pokemon.name,creator)) else Kernel.pbMessage(_INTL("{1} fue transferido al PC de alguien.\1",pokemon.name)) end Kernel.pbMessage(_INTL("Fue guardado en la caja \"{1}.\"",boxname)) end end end def pbNicknameAndStore(pokemon) if pbBoxesFull? Kernel.pbMessage(_INTL("ˇNo hay sitio para más Pokémon!\1")) Kernel.pbMessage(_INTL("ˇLas cajas Pokémon están llenas y no cabe nada más!")) return end speciesname=PBSpecies.getName(pokemon.species) $Trainer.seen[pokemon.species]=true $Trainer.owned[pokemon.species]=true if Kernel.pbConfirmMessage(_INTL("żQuieres darle un mote a {1}?",speciesname)) helptext=_INTL("żMote de {1}?",speciesname) newname=pbEnterText(helptext,0,10) pokemon.name=newname if newname!="" end pbStorePokemon(pokemon) end def pbAddForeignPokemon(species,level,ownerName,nickname=nil) if $Trainer.party.length==6 return false end speciesname=PBSpecies.getName(species) Kernel.pbMessage(_INTL("{1} recibió un Pokémon de {2}.\1",$Trainer.name,ownername)) pokemon=PokeBattle_Pokemon.new(species,level,$Trainer) # Set ID and OT name to a foreign one pokemon.id=$Trainer.getForeignID pokemon.ot=ownerName # Set nickname if nickname pokemon.name=nickname[0,10] end # Recalculate stats pokemon.calcStats pbStorePokemon(pokemon) return true end def pbAddPokemonToParty(species,level) if $Trainer.party.length==6 return false end speciesname=PBSpecies.getName(species) Kernel.pbMessage(_INTL("ˇ{1} obtuvó a {2}!\1",$Trainer.name,speciesname)) pokemon=PokeBattle_Pokemon.new(species,level,$Trainer) pbNicknameAndStore(pokemon) return true end def pbAddPokemon(species,level) if pbBoxesFull? Kernel.pbMessage(_INTL("ˇNo hay más sitio para los Pokémon!\1")) Kernel.pbMessage(_INTL("ˇLas cajas Pokémon están llenas y no cabe nada más!")) return false end speciesname=PBSpecies.getName(species) Kernel.pbMessage(_INTL("ˇ{1} obtuvo a {2}!\1",$Trainer.name,speciesname)) pokemon=PokeBattle_Pokemon.new(species,level,$Trainer) pbNicknameAndStore(pokemon) return true end def pbCheckAble(pokemonIndex) for i in 0...$Trainer.party.length p=$Trainer.party[i] next if i==pokemonIndex return true if p && !p.egg? && p.hp>0 end return false end def pbFirstAblePokemon(variableNumber) for i in 0...$Trainer.party.length p=$Trainer.party[i] if p && !p.egg? && p.hp>0 $game_variables[variableNumber]=i return end end $game_variables[variableNumber]=-1 end def pbLoadPokemonIcon(pokemon) return BitmapCache.load_bitmap(pbPokemonIconFile(pokemon)) end def pbPokemonIconFile(pokemon) if pokemon.egg? # Special case for eggs return sprintf("Graphics/Pictures/iconEgg.png") end if isConst?(pokemon.species,PBSpecies,:UNOWN) # Special case for Unown d=pokemon.personalID&3 d|=((pokemon.personalID>>8)&3)<<2 d|=((pokemon.personalID>>16)&3)<<4 d|=((pokemon.personalID>>24)&3)<<6 d%=32 # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!? filename=sprintf("Graphics/Icons/icon%03d_%02d.png",pokemon.species,d) begin load_data(filename) return filename rescue Errno::ENOENT, Errno::EACCES, RGSSError # File not found, just fall back end end if isConst?(pokemon.species,PBSpecies,:SMEARGLE) # Special case for Smeargle d=pokemon.personalID&3 d|=((pokemon.personalID>>8)&3)<<2 d|=((pokemon.personalID>>16)&3)<<4 d|=((pokemon.personalID>>24)&3)<<6 d%=9 # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!? filename=sprintf("Graphics/Icons/icon%03d_%02d.png",pokemon.species,d) begin load_data(filename) return filename rescue Errno::ENOENT, Errno::EACCES, RGSSError # File not found, just fall back end end return sprintf("Graphics/Icons/icon%03d.png",pokemon.species) end def pbPositionPokemonSprite(sprite,left,top) if sprite.bitmap && !sprite.bitmap.disposed? sprite.x=left+(sprite.bitmap.width-128)/2 sprite.y=top+(sprite.bitmap.height-128)/2 else sprite.x=left sprite.y=top end end def drawSpot(bitmap,spotpattern,x,y,red,green,blue) height=spotpattern.length width=spotpattern[0].length for yy in 0...height spot=spotpattern[yy] for xx in 0...width if spot[xx]==1 xOrg=(x+xx)<<1 yOrg=(y+yy)<<1 color=bitmap.get_pixel(xOrg,yOrg) r=color.red+red g=color.green+green b=color.blue+blue color.red=[[r,0].max,255].min color.green=[[g,0].max,255].min color.blue=[[b,0].max,255].min bitmap.set_pixel(xOrg,yOrg,color) bitmap.set_pixel(xOrg+1,yOrg,color) bitmap.set_pixel(xOrg,yOrg+1,color) bitmap.set_pixel(xOrg+1,yOrg+1,color) end end end end def pbSpindaSpots(pokemon,bitmap) spot1=[ [0,0,1,1,1,1,0,0], [0,1,1,1,1,1,1,0], [1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1], [0,1,1,1,1,1,1,0], [0,0,1,1,1,1,0,0] ] spot2=[ [0,0,1,1,1,0,0], [0,1,1,1,1,1,0], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [0,1,1,1,1,1,0], [0,0,1,1,1,0,0] ] spot3=[ [0,0,0,0,0,1,1,1,1,0,0,0,0], [0,0,0,1,1,1,1,1,1,1,0,0,0], [0,0,1,1,1,1,1,1,1,1,1,0,0], [0,1,1,1,1,1,1,1,1,1,1,1,0], [0,1,1,1,1,1,1,1,1,1,1,1,0], [1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1], [0,1,1,1,1,1,1,1,1,1,1,1,0], [0,1,1,1,1,1,1,1,1,1,1,1,0], [0,0,1,1,1,1,1,1,1,1,1,0,0], [0,0,0,1,1,1,1,1,1,1,1,0,0], [0,0,0,0,0,1,1,1,0,0,0,0,0] ] spot4=[ [0,0,0,0,1,1,1,0,0,0,0,0], [0,0,1,1,1,1,1,1,1,0,0,0], [0,1,1,1,1,1,1,1,1,1,0,0], [0,1,1,1,1,1,1,1,1,1,1,0], [1,1,1,1,1,1,1,1,1,1,1,0], [1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,0], [1,1,1,1,1,1,1,1,1,1,1,0], [0,0,1,1,1,1,1,1,1,1,0,0], [0,0,0,0,0,1,1,1,1,0,0,0] ] id=pokemon.personalID h=(id>>28)&15 g=(id>>24)&15 f=(id>>20)&15 e=(id>>16)&15 d=(id>>12)&15 c=(id>>8)&15 b=(id>>4)&15 a=(id)&15 if pokemon.isShiny? drawSpot(bitmap,spot1,b+33,a+25,-100,30,-100) drawSpot(bitmap,spot2,d+21,c+24,-100,30,-100) drawSpot(bitmap,spot3,f+39,e+7,-100,30,-100) drawSpot(bitmap,spot4,h+15,g+6,-100,30,-100) else drawSpot(bitmap,spot1,b+33,a+25,30,-100,-100) drawSpot(bitmap,spot2,d+21,c+24,30,-100,-100) drawSpot(bitmap,spot3,f+39,e+7,30,-100,-100) drawSpot(bitmap,spot4,h+15,g+6,30,-100,-100) end end def pbLoadPokemonBitmap(pokemon, back=false) return pbLoadPokemonBitmapSpecies(pokemon,pokemon.species,back) end def pbLoadPokemonBitmapSpecies(pokemon, species, back=false) if pokemon.egg? return BitmapCache.load_bitmap( sprintf("Graphics/Pictures/egg.png")) end bitmapFileName=sprintf("Graphics/Battlers/%03d%s%s.png",species, pokemon.isShiny? ? "s" : "", back ? "b" : "") if isConst?(species,PBSpecies,:SPINDA) && !back bitmap=Bitmap.new(bitmapFileName) pbSpindaSpots(pokemon,bitmap) return bitmap elsif isConst?(species,PBSpecies,:UNOWN) d=pokemon.personalID&3 d|=((pokemon.personalID>>8)&3)<<2 d|=((pokemon.personalID>>16)&3)<<4 d|=((pokemon.personalID>>24)&3)<<6 d%=32 # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!? begin # Load special bitmap if found # Example: 201b_02 for the letter C return BitmapCache.load_bitmap( sprintf("Graphics/Battlers/%03d%s%s_%02d.png",species, pokemon.isShiny? ? "s" : "", back ? "b" : "", d) ) rescue # Load plain bitmap as usual (see below) if isConst?(species,PBSpecies,:SMEARGLE) d=pokemon.personalID&3 d|=((pokemon.personalID>>8)&3)<<2 d|=((pokemon.personalID>>16)&3)<<4 d|=((pokemon.personalID>>24)&3)<<6 d%=9 # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!? begin # Load special bitmap if found # Example: 201b_02 for the letter C return BitmapCache.load_bitmap( sprintf("Graphics/Battlers/%03d%s%s_%02d.png",species, pokemon.isShiny? ? "s" : "", back ? "b" : "", d) ) rescue # Load plain bitmap as usual (see below) end end return BitmapCache.load_bitmap(bitmapFileName) end def pbStringToAudioFile(str) if str[/^(.*)\:\s*(\d+)\s*\:\s*(\d+)\s*$/] file=$1 volume=$2.to_i pitch=$3.to_i return RPG::AudioFile.new(file,volume,pitch) elsif str[/^(.*)\:\s*(\d+)\s*$/] file=$1 volume=$2.to_i return RPG::AudioFile.new(file,volume,100) else return RPG::AudioFile.new(str,100,100) end end def pbGetWildBattleBGM(species) if $PokemonGlobal.nextBattleBGM return $PokemonGlobal.nextBattleBGM.clone end wildbgm=pbGetMetadata(0,MetadataWildBattleBGM) if wildbgm wildbgm="#{wildbgm}" else wildbgm="002-Battle02.mid" end return pbStringToAudioFile(wildbgm) end def pbPlayTrainerIntroME(trainertype) pbRgssOpen("Data/trainernames.dat","rb"){|f| trainernames=Marshal.load(f) if trainernames[trainertype] bgm=trainernames[trainertype][6] if bgm && bgm!="" bgm=pbStringToAudioFile(bgm) $game_system.bgm_play_ex("../../Audio/ME/#{bgm.name}",bgm.volume,bgm.pitch,false) end end } end def pbGetTrainerBattleBGM(trainer) if $PokemonGlobal.nextBattleBGM return $PokemonGlobal.nextBattleBGM.clone end trainerbgm=pbGetMetadata(0,MetadataTrainerBattleBGM) pbRgssOpen("Data/trainernames.dat","rb"){|f| trainernames=Marshal.load(f) if !trainer.is_a?(Array) trainerarray=[trainer] else trainerarray=trainer end for i in 0...trainerarray.length trainertype=trainerarray[i].trainertype if trainernames[trainertype] bgm=trainernames[trainertype][4] trainerbgm=bgm if bgm end end } if trainerbgm trainerbgm="#{trainerbgm}" else trainerbgm="005-Boss01.mid" end return pbStringToAudioFile(trainerbgm) end def pbGetTrainerBattleBGMFromType(trainertype) if $PokemonGlobal.nextBattleBGM return $PokemonGlobal.nextBattleBGM.clone end trainerbgm=pbGetMetadata(0,MetadataTrainerBattleBGM) pbRgssOpen("Data/trainernames.dat","rb"){|f| trainernames=Marshal.load(f) trainertype=trainertype if trainernames[trainertype] bgm=trainernames[trainertype][4] trainerbgm=bgm if bgm end } if trainerbgm trainerbgm="#{trainerbgm}" else trainerbgm="005-Boss01.mid" end return pbStringToAudioFile(trainerbgm) end def pbGetTrainerVictoryME(trainer) if $PokemonGlobal.nextBattleME return $PokemonGlobal.nextBattleME.clone end music=nil pbRgssOpen("Data/trainernames.dat","rb"){|f| trainernames=Marshal.load(f) if trainernames[trainer.trainertype] music=trainernames[trainer.trainertype][5] end } ret=nil if music && music!="" ret=pbStringToAudioFile("#{music}") else music=pbGetMetadata(0,MetadataTrainerVictoryME) if music && music!="" ret=pbStringToAudioFile("#{music}") else ret=pbStringToAudioFile("001-Victory01.mid") end end ret.name="../../Audio/ME/"+ret.name return ret end def pbGetWildVictoryME if $PokemonGlobal.nextBattleME return $PokemonGlobal.nextBattleME.clone end music=pbGetMetadata(0,MetadataWildVictoryME) ret=nil if music && music!="" ret=pbStringToAudioFile("#{music}") else ret=pbStringToAudioFile("001-Victory01.mid") end ret.name="../../Audio/ME/"+ret.name return ret end def pbChangePlayer(id) return false if id<0||id>=4 meta=pbGetMetadata(0,MetadataPlayerA+id) return false if !meta $game_player.character_name=meta[1] $game_player.character_hue=0 $PokemonGlobal.playerID=id end def pbGetPlayerGraphic id=$PokemonGlobal.playerID return "" if id<0||id>=4 meta=pbGetMetadata(0,MetadataPlayerA+id) return "" if !meta return sprintf("../Characters/trainer%03d",meta[0]) end def pbGetPlayerTrainerType id=$PokemonGlobal.playerID return 0 if id<0||id>=4 meta=pbGetMetadata(0,MetadataPlayerA+id) return 0 if !meta return meta[0] end #Modified by Wichu, adapted by Peter O. def getRandomNameEx(type,variable,upper,*formats) if formats.length==0 case type when 0 formats=%w( 1423 2341 23441 14235 1415 14141 142314 41423 4141 42341 ) when 1 formats=%w( 1416 14416 141416 23416 41416 423416 414236 14236 1414236 14146 ) when 2 formats=%w( cvcvvc cvvcvc cvcvcv vcvvc cvcv cvvc cvcv cvve bvc bve cve bvvc bvcv bvcvc) end end format=formats[rand(formats.length)] name="" format.scan(/./) {|c| case c when "c" set=%w( b c d f g h j k l l m n n p r r s s t t v w x z ) name+=set[rand(set.length)] when "v" set=%w( a a a e e e i i i o o o u u u y ) name+=set[rand(set.length)] when "b" # two-letter "blends" set=%w( br bl ch cl cr dr fr fl gh gl gr ph pl pr sc sh sk sl sm sn sp st sw th tr tw wh wr ) name+=set[rand(set.length)] when "e" # two-letter "blends" at end set=%w( ck ch dd ff bb gg gh ld ll mm nd nt ng ph pt ps sk sh sp ss st rd rn rp rm rk ns bs ft ) name+=set[rand(set.length)] when "1" set=%w( b c d f g h j k l m n p q r s t v w x z ) name+=set[rand(set.length)] when "2" set=%w( c f g k l p r s t ) name+=set[rand(set.length)] when "3" set=%w( h k l s t ) name+=set[rand(set.length)] when "4" set=%w( a e i o u ) name+=set[rand(set.length)] when "5" set=%w( e e o o o u u ) name+=set[rand(set.length)] when "6" set=%w( a a a i i i e ) name+=set[rand(set.length)] end } case upper when 0 name=name.upcase when 1 name[0,1]=name[0,1].upcase end $game_variables[variable]=name if variable return name end def getRandomName(*formats) return getRandomNameEx(2,nil,nil,formats) end def pbGetTrainerTypeGender(trainertype) ret=2 pbRgssOpen("Data/trainernames.dat","rb"){|f| trainernames=Marshal.load(f) if !trainernames[trainertype] ret=2 else ret=trainernames[trainertype][7] ret=2 if !ret end } return ret end def pbTrainerName trname=pbEnterText("żTu nombre?",0,7) trainertype=pbGetPlayerTrainerType gender=pbGetTrainerTypeGender(trainertype) if trname=="" trname=getRandomNameEx(gender,nil,1) end $Trainer=PokeBattle_Trainer.new(trname,trainertype) $PokemonBag=PokemonBag.new $PokemonTemp.begunNewGame=true end def pbPokemonBitmapFile(species, shiny, back=false) if shiny # Load shiny bitmap return sprintf("Graphics/Battlers/%03ds%s.png",species,back ? "b" : "") else # Load normal bitmap return sprintf("Graphics/Battlers/%03d%s.png",species,back ? "b" : "") end end # Stores result in variable _variableNumber_ and #name in variable _nameVarNumber_; result is -1 if no Pokémon was chosen def pbChoosePokemon(variableNumber,nameVarNumber,ableProc=nil) chosen=0 pbFadeOutIn(99999){ scene=PokemonScreen_Scene.new screen=PokemonScreen.new(scene,$Trainer.party) if ableProc chosen=screen.pbChooseAblePokemon(ableProc) else screen.pbStartScene(_INTL("Elige un Pokémon."),false) chosen=screen.pbChoosePokemon screen.pbEndScene end } $game_variables[variableNumber]=chosen if chosen>=0 $game_variables[nameVarNumber]=$Trainer.party[chosen].name else $game_variables[nameVarNumber]="" end end def pbChooseAblePokemon(variableNumber,nameVarNumber) pbChoosePokemon(variableNumber,nameVarNumber,proc {|poke| !poke.egg? && poke.hp>0 }) end def pbDeleteMove(pokemon,index) newmoves=[] for i in 0...4 newmoves.push(pokemon.moves[i]) if i!=index end newmoves.push(PBMove.new(0)) for i in 0...4 pokemon.moves[i]=newmoves[i] end end def pbNumMoves(pokemon) ret=0 for i in 0...4 ret+=1 if pokemon.moves[i].id!=0 end return ret end def pbGetRegionalNumber(region, nationalSpecies) # Gets the regional Pokédex 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 Pokédex 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 Pokédex, sorted by # regional Pokédex number. # The number of items in the array should be # the number of species in the regional Pokédex 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 def pbGenerateEgg(species,level) if $Trainer.party.length>=6 raise _INTL("No se puede guardar el huevo.") end # Get egg steps dexdata=pbOpenDexData pbDexDataOffset(dexdata,species,21) eggsteps=dexdata.fgetw dexdata.close # Generate egg egg=PokeBattle_Pokemon.new(species,level,$Trainer) egg.calcStats egg.name=_INTL("HUEVO") egg.eggsteps=eggsteps # Add egg to party $Trainer.party[$Trainer.party.length]=egg end def pbHasSpecies?(species) for pokemon in $Trainer.party next if pokemon.egg? return true if pokemon.species==species end return false end def pbTextEntry(helptext,minlength,maxlength,variableNumber) $game_variables[variableNumber]=pbEnterText(helptext,minlength,maxlength) end def pbMoveTutorAnnotations(move,movelist) ret=[] for i in 0...6 ret[i]=nil next if i>=$Trainer.party.length found=false for j in 0...4 if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move ret[i]=_INTL("APRENDIDO") found=true end end next if found species=$Trainer.party[i].species if !$Trainer.party[i].egg? && movelist.any?{|j| j==species } ret[i]=_INTL("COMPATIBLE") else ret[i]=_INTL("INCOMPATIBLE") end end return ret end def pbMoveTutorChoose(move,movelist) ret=false pbFadeOutIn(99999){ scene=PokemonScreen_Scene.new movename=PBMoves.getName(move) screen=PokemonScreen.new(scene,$Trainer.party) annot=pbMoveTutorAnnotations(move,movelist) screen.pbStartScene(_INTL("żEnseńar a qué Pokémon?"),false,annot) chosen=screen.pbChoosePokemon if chosen>=0 pokemon=$Trainer.party[chosen] if pokemon.egg? Kernel.pbMessage(_INTL("{1} no puede ser enseńado a un huevo.",movename)) elsif !movelist.any?{|j| j==pokemon.species } Kernel.pbMessage(_INTL("{1} no es compatible con {2}.",pokemon.name,movename)) Kernel.pbMessage(_INTL("{1} no puede ser aprendido.",movename)) else if pbLearnMove(pokemon,move) ret=true end end end screen.pbEndScene } return ret end def pbChooseMove(pokemon,variableNumber,nameVarNumber) ret=-1 pbFadeOutIn(99999){ scene=PokemonSummaryScene.new screen=PokemonSummary.new(scene) ret=screen.pbStartForgetScreen([pokemon],0,0) } $game_variables[variableNumber]=ret if ret>=0 $game_variables[nameVarNumber]=PBMoves.getName(pokemon.moves[ret].id) else $game_variables[nameVarNumber]="" end end # Opens the Pokémon screen def pbPokemonScreen PBDebug.logonerr{ sscene=PokemonScreen_Scene.new sscreen=PokemonScreen.new(sscene,$Trainer.party) pbFadeOutIn(99999) { sscreen.pbPokemonScreen } } end def pbSaveScreen ret=false PBDebug.logonerr { scene=PokemonSaveScene.new screen=PokemonSave.new(scene) ret=screen.pbSaveScreen } return ret end def pbHideVisibleObjects visibleObjects=[] # Windows excluded because they # are implemented as sprites ObjectSpace.each_object(Sprite){|o| if !o.disposed? && o.visible visibleObjects.push(o) o.visible=false end } ObjectSpace.each_object(Viewport){|o| if !pbDisposed?(o) && o.visible visibleObjects.push(o) o.visible=false end } ObjectSpace.each_object(Plane){|o| if !o.disposed? && o.visible visibleObjects.push(o) o.visible=false end } ObjectSpace.each_object(Tilemap){|o| if !o.disposed? && o.visible visibleObjects.push(o) o.visible=false end } return visibleObjects end def pbShowObjects(visibleObjects) for o in visibleObjects if !pbDisposed?(o) o.visible=true end end end def pbLoadRpgxpScene(scene) return if !$scene.is_a?(Scene_Map) oldscene=$scene $scene=scene Graphics.freeze oldscene.disposeSpritesets visibleObjects=pbHideVisibleObjects Graphics.transition(15) Graphics.freeze while $scene && !$scene.is_a?(Scene_Map) $scene.main end Graphics.transition(15) Graphics.freeze oldscene.createSpritesets pbShowObjects(visibleObjects) Graphics.transition(20) $scene=oldscene end def getOggPage(file) pos=file.pos dw=file.fgetdw return nil if dw!=0x5367674F header=file.read(22) bodysize=0 hdrbodysize=file.fgetb hdrbodysize.times do bodysize+=file.fgetb end ret=[header,file.pos,bodysize,file.pos+bodysize] return ret end def oggfiletime(file) pages=[] page=nil begin page=getOggPage(file) if page pages.push(page) file.pos=page[3] end end while page if pages.length==0 return -1 end curserial=nil i=-1 pcmlengths=[] rates=[] for page in pages header=page[0] serial=header[10,4].unpack("V") frame=header[2,8].unpack("C*") frameno=frame[7] frameno=(frameno<<8)|frame[6] frameno=(frameno<<8)|frame[5] frameno=(frameno<<8)|frame[4] frameno=(frameno<<8)|frame[3] frameno=(frameno<<8)|frame[2] frameno=(frameno<<8)|frame[1] frameno=(frameno<<8)|frame[0] if serial!=curserial curserial=serial file.pos=page[1] packtype=file.fgetb string=file.read(6) if string!="vorbis" return -1 end if packtype!=1 return -1 end i+=1 version=file.fgetdw if version!=0 return -1 end channels=file.fgetb rates[i]=file.fgetdw end pcmlengths[i]=frameno end ret=0.0 for i in 0...pcmlengths.length ret+=pcmlengths[i]*1.0/rates[i] end return ret end def getPlayTime(filename) time=-1 File.open(filename,"rb"){|file| file.pos=0 fdw=file.fgetdw if fdw==0x46464952 # "RIFF" filesize=file.fgetdw wave=file.fgetdw if wave!=0x45564157 # "WAVE" return -1 end fmt=file.fgetdw if fmt!=0x20746d66 # "fmt " return -1 end fmtsize=file.fgetdw format=file.fgetw channels=file.fgetw rate=file.fgetdw bytessec=file.fgetdw if bytessec==0 return -1 end bytessample=file.fgetw bitssample=file.fgetw data=file.fgetdw if data!=0x61746164 # "data" return -1 end datasize=file.fgetdw time=(datasize*1.0)/bytessec elsif fdw==0x5367674F # "OggS" file.pos=0 time=oggfiletime(file) end } return time end def pbCommonEvent(id) return false if id<0 ce=$data_common_events[id] return false if !ce celist=ce.list interp=Interpreter.new interp.setup(celist,0) begin Graphics.update Input.update interp.update pbUpdateSceneMap end while interp.running? return true end def pbDelayedDelete(filename) thr=Thread.new { Thread.stop loop do break if !FileTest.exist?(Thread.current[:path]) begin File.delete(Thread.current[:path]) rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT end sleep 1.0 end } thr[:path]=filename thr.run end class WaveData def initialize(samplesPerSec,samples) @freq=samplesPerSec @samples=samples.pack("C*") end def setSamples(samples) @samples=samples end def openTemp(prefix,mode) for i in 0...1000 begin filename=sprintf("%s%d.tmp",prefix,i) return File.open(filename,mode) rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT end end return nil end def self._load(string) data=Marshal.load(string) ret=self.new(data[0],[]) ret.setSamples(Zlib::Inflate.inflate(data[1])) return ret end def _dump(depth=100) return Marshal.dump([@freq,Zlib::Deflate.deflate(@samples)]) end def intensity distance=@samples.length/2000 i=distance/2 count=0 volume=0 while i<@samples.length vol=(@samples[i]-128).abs vol=127 if vol>127 if vol>=16 volume+=vol count+=1 end i+=distance end return 0 if count==0 return volume/count # from 0 through 127 end def time return @freq==0 ? 0.0 : (@samples.length)*1.0/@freq end def play return if @samples.length==0 data=[ 0x46464952,@samples.length+0x2C, 0x45564157,0x20746d66,0x10, 0x01,0x01, # PCM,mono @freq,@freq, 1,8, # 8-bit 0x61746164,@samples.length ].pack("VVVVVvvVVvvVV") f=openTemp("wav","wb") if f path=f.path f.write(data) f.write(@samples) f.close Audio.se_play(path) pbDelayedDelete(path) end end end # Creates wave data from the given WAV file path def getWaveData(filename) time=-1 if !FileTest.exist?(filename) return 1 # Not found end File.open(filename,"rb"){|file| file.pos=0 fdw=file.fgetdw if fdw==0x46464952 # "RIFF" filesize=file.fgetdw wave=file.fgetdw if wave!=0x45564157 # "WAVE" return 2 end fmt=file.fgetdw if fmt!=0x20746d66 # "fmt " return 2 end fmtsize=file.fgetdw format=file.fgetw if format!=1 return 3 # unsupported end channels=file.fgetw # channels (1 or 2) if channels!=1 return 3 # unsupported end rate=file.fgetdw # samples per second bytessec=file.fgetdw # avg bytes per second if bytessec==0 return 2 end bytessample=file.fgetw # bytes per sample bitssample=file.fgetw # bits per sample (8, 16, etc.) if bitssample!=8 && bitssample!=16 return 3 # unsupported end data=file.fgetdw if data!=0x61746164 # "data" return 2 end datasize=file.fgetdw data=file.read(datasize) samples=nil if bitssample==8 samples=data.unpack("C*") start=0 for i in 0...samples.length s=samples[i] if s<0x70 || s>=0x90 start=i break end end finish=start i=samples.length-1 while i>=start s=samples[i] if s<0x70 || s>=0x90 finish=i+1 break end i-=1 end if finish==start return 4 # Nothing was recorded end start=0 finish=samples.length wave=WaveData.new(rate,samples[start,finish-start]) return wave elsif bitssample==16 samples=data.unpack("v*") start=0 for i in 0...samples.length s=samples[i] if s>0x1000 && s<0xF000 start=i break end end finish=start i=samples.length-1 while i>=start s=samples[i] if s<0x1000 && s<0xF000 finish=i+1 break end i-=1 end if finish==start return 4 # Nothing was recorded end start=0 # Convert to 8-bit samples for i in start...finish samples[i]=((samples[i]-0x8000)>>8)&0xFF end finish=samples.length return WaveData.new(rate,samples[start,finish-start]) end end } return 2 end def getWaveDataUI(filename,deleteFile=false) error=getWaveData(filename) if deleteFile begin File.delete(filename) rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT end end if error==1 Kernel.pbMessage(_INTL("Los datos guardados no pudieron ser salvados o encontrados..")) elsif error==2 Kernel.pbMessage(_INTL("Los datos guardados estaban en un formato incorrecto.")) elsif error==3 Kernel.pbMessage(_INTL("El formato de los datos guardados no es soportado.")) elsif error==4 Kernel.pbMessage(_INTL("No hay sonido en la grabación. Asegúrate de que hay un micrófono bien conectado al ordenador.")) else return error end return nil end MciSendString = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','l') MciErrorString = Win32API.new('winmm','mciGetErrorString','%w(l,p,l)','l') # Starts recording. Returns 0 if successful. def beginRecord MciSendString.call("open new type waveaudio alias RECORDER buffer 4",0,0,0) MciSendString.call("set RECORDER channels 1",0,0,0) retval=MciSendString.call("record RECORDER",0,0,0) if retval!=0 MciSendString.call("close RECORDER",0,0,0) end return retval end # Starts recording, and displays a message if the # recording failed to start. Returns true if # successful, false otherwise def beginRecordUI code=beginRecord case code when 0; return true when 256+66 Kernel.pbMessage(_INTL("All recording devices are in use. Recording is not possible now.")) return false when 256+72 Kernel.pbMessage(_INTL("No supported recording device was found. Recording is not possible.")) return false else buffer="\0"*256 MciErrorString.call(code,buffer,256) Kernel.pbMessage(_INTL("Recording failed: {1}",buffer.gsub(/\x00/,""))) return false end end # Gets a single sample from the microphone. # The beginRecord or beginRecordUI function # must have been called beforehand. def getRecorderSample buffer="\0"*256 ret=0 MciSendString.call("stop RECORDER",0,0,0) MciSendString.call("status RECORDER bitspersample",buffer,256,0) bitspersample=buffer.to_i MciSendString.call("status RECORDER level",buffer,256,0) MciSendString.call("record RECORDER",0,0,0) if bitspersample==8 ret=buffer.to_i<<8 # max 128 else ret=buffer.to_i # max 0x8000 end return ret end def stopRecord() MciSendString.call("stop RECORDER",0,0,0) MciSendString.call("close RECORDER",0,0,0) end def endRecord(file) MciSendString.call("stop RECORDER",0,0,0) if file && file!="" MciSendString.call("save RECORDER #{file}",0,0,0) end MciSendString.call("close RECORDER",0,0,0) end class PokemonGlobalMetadata attr_accessor :trainerRecording end def pbRecordTrainer wave=pbRecord(nil,10) if wave $PokemonGlobal.trainerRecording=wave return true end return false end =begin Gets the ID number for the current region based on the player's current position. Returns -1 if no region was defined in the game's metadata. The ID numbers returned by this function depend on the town map configuration. =end def pbGetCurrentRegion mappos=!$game_map ? nil : pbGetMetadata($game_map.map_id,MetadataMapPosition) if !mappos return -1 # No region defined else return mappos[0] end end class RegionalStorage def initialize @storages=[] @lastmap=-1 @rgnmap=-1 end def getCurrentStorage if !$game_map raise _INTL("The player is not on a map, so the region could not be determined.") end if @lastmap!=$game_map.map_id @rgnmap=pbGetCurrentRegion # may access file IO, so caching result @lastmap=$game_map.map_id end if @rgnmap<0 raise _INTL("The current map has no region set. Please set the MapPosition metadata setting for this map.") end if !@storages[@rgnmap] @storages[@rgnmap]=PokemonStorage.new end return @storages[@rgnmap] end def boxes return getCurrentStorage.boxes end def party return getCurrentStorage.party end def currentBox return getCurrentStorage.currentBox end def currentBox=(value) getCurrentStorage.currentBox=value end def [](x,y=nil) getCurrentStorage[x,y] end def []=(x,y,value) getCurrentStorage[x,y]=value end def full? getCurrentStorage.full? end def pbFirstFreePos(box) getCurrentStorage.pbFirstFreePos(box) end def pbCopy(boxDst,indexDst,boxSrc,indexSrc) getCurrentStorage.pbCopy(boxDst,indexDst,boxSrc,indexSrc) end def pbMove(boxDst,indexDst,boxSrc,indexSrc) getCurrentStorage.pbCopy(boxDst,indexDst,boxSrc,indexSrc) end def pbMoveCaughtToParty(pkmn) getCurrentStorage.pbMoveCaughtToParty(pkmn) end def pbStoreCaught(pkmn) getCurrentStorage.pbStoreCaught(pkmn) end def pbDelete(box,index) getCurrentStorage.pbDelete(pkmn) end end
When I play the game, a screen say that there is an error in PokemonUtilities, so I opened the script editors, and the error is at line 1213. Forward, there is the line 1213 and more:
class WaveData def initialize(samplesPerSec,samples) @freq=samplesPerSec @samples=samples.pack("C*") end def setSamples(samples) @samples=samples end def openTemp(prefix,mode) for i in 0...1000 begin filename=sprintf("%s%d.tmp",prefix,i) return File.open(filename,mode) rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT end end return nil end def self._load(string) data=Marshal.load(string) ret=self.new(data[0],[]) ret.setSamples(Zlib::Inflate.inflate(data[1])) return ret end def _dump(depth=100) return Marshal.dump([@freq,Zlib::Deflate.deflate(@samples)]) end def intensity distance=@samples.length/2000 i=distance/2 count=0 volume=0 while i<@samples.length vol=(@samples[i]-128).abs vol=127 if vol>127 if vol>=16 volume+=vol count+=1 end i+=distance end return 0 if count==0 return volume/count # from 0 through 127 end def time return @freq==0 ? 0.0 : (@samples.length)*1.0/@freq end def play return if @samples.length==0 data=[ 0x46464952,@samples.length+0x2C, 0x45564157,0x20746d66,0x10, 0x01,0x01, # PCM,mono @freq,@freq, 1,8, # 8-bit 0x61746164,@samples.length ].pack("VVVVVvvVVvvVV") f=openTemp("wav","wb") if f path=f.path f.write(data) f.write(@samples) f.close Audio.se_play(path) pbDelayedDelete(path) end end endCould anyone help me, please?
Page 1 of 1
All times are GMT - 5 Hours