Vendily

PokemonOWSprite

Jul 16th, 2019
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PokemonOWSprite
  2.   def initialize(event,index,viewport)
  3.     @event=event
  4.     @event.character_name=""
  5.     @index=index
  6.     pkmn=($PokemonGlobal.daycarePokemon[@index][0] rescue nil) # change this to point to the wild pokemon that you've created.
  7.     @form=(pkmn)? pkmn.form : 0
  8.     if !pkmn
  9.       @event.moveto(0,0)
  10.     end
  11.     setGraphic
  12.   end
  13.  
  14.   def dispose
  15.     @event=nil
  16.     @index=nil
  17.     @form=0
  18.     @disposed=true
  19.   end
  20.  
  21.   def disposed?
  22.     @disposed
  23.   end
  24.  
  25.   def update
  26.     pkmn=($PokemonGlobal.daycarePokemon[@index][0] rescue nil)
  27.     if pkmn && pkmn.form != @form
  28.       setGraphic
  29.       @form = pkmn.form
  30.     end
  31.   end
  32.  
  33.   def setGraphic
  34.     pkmn=($PokemonGlobal.daycarePokemon[@index][0] rescue nil)
  35.     if pkmn
  36.       @event.character_name=pbPokemonOverworldFile([pkmn.species,false,(pkmn.isFemale?),
  37.        pkmn.isShiny?,(pkmn.form rescue 0),(pkmn.isShadow? rescue false)])
  38.     end
  39.   end
  40. end
  41.  
  42. def pbPokemonOverworldFile(params)
  43.   species = params[0]
  44.   back    = params[1]
  45.   factors = []
  46.   factors.push([5,params[5],false]) if params[5] && params[5]!=false     # shadow
  47.   factors.push([2,params[2],false]) if params[2] && params[2]!=false     # gender
  48.   factors.push([3,params[3],false]) if params[3] && params[3]!=false     # shiny
  49.   factors.push([4,params[4].to_s,""]) if params[4] && params[4].to_s!="" &&
  50.                                                       params[4].to_s!="0" # form
  51.   tshadow = false
  52.   tgender = false
  53.   tshiny  = false
  54.   tform   = ""
  55.   for i in 0...2**factors.length
  56.     for j in 0...factors.length
  57.       case factors[j][0]
  58.       when 2   # gender
  59.         tgender = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
  60.       when 3   # shiny
  61.         tshiny = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
  62.       when 4   # form
  63.         tform = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
  64.       when 5   # shadow
  65.         tshadow = ((i/(2**j))%2==0) ? factors[j][1] : factors[j][2]
  66.       end
  67.     end
  68.     bitmapFileName = sprintf("pkmn/%s%s%s%s%s%s",
  69.        getConstantName(PBSpecies,species),
  70.        (tgender) ? "f" : "",
  71.        (tshiny) ? "s" : "",
  72.        (back) ? "b" : "",
  73.        (tform!="") ? "_"+tform : "",
  74.        (tshadow) ? "_shadow" : "") rescue nil
  75.     ret = pbResolveBitmap("Graphics/Characters/"+bitmapFileName)
  76.     return bitmapFileName if ret
  77.     bitmapFileName = sprintf("pkmn/%03d%s%s%s%s%s",
  78.        species,
  79.        (tgender) ? "f" : "",
  80.        (tshiny) ? "s" : "",
  81.        (back) ? "b" : "",
  82.        (tform!="") ? "_"+tform : "",
  83.        (tshadow) ? "_shadow" : "")
  84.     ret = pbResolveBitmap("Graphics/Characters/"+bitmapFileName)
  85.     return bitmapFileName if ret
  86.   end
  87.   return ""
  88. end
  89.  
  90. Events.onSpritesetCreate+=proc{|sender,e|
  91.    spriteset=e[0]
  92.    viewport=e[1]
  93.    map=spriteset.map
  94.    next if map.map_id!=5
  95.    for i in 2..6 # event ids that get the pokemon sprite
  96.      spriteset.addUserSprite(PokemonOWSprite.new(map.events[i],i-2,viewport))
  97.    end
  98. }
RAW Paste Data