Prize Wheels

Prize Wheels N/A

Pokémon Essentials Version
v19.1 ✅
prize wheel.gif
pokemon wheel.gif
ball wheel.gif















This script lets you create Prize Wheels that players can spin to win one of ten prizes! Your prize pool can be Pokemon, items, money, or a mix of the three!

(Yes I got this idea from Webkinz/Neopets what are you a cop)

Code
Paste in a new section above Main!
Ruby:
Prizes = [
[:POKEBALL,:REPEATBALL,:FASTBALL,:LEVELBALL,:NESTBALL,:DUSKBALL,:DIVEBALL,:HEAVYBALL,:GREATBALL,:MASTERBALL],
[:CHARMANDER,:CYNDAQUIL,:EEVEE,:PIKACHU,:CHIKORITA,:BULBASAUR,:SQUIRTLE,:TOTODILE,:MARILL,:RATTATA],
["100","200","300","400","500","600","700","800","900","1000"],
[:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,],
["100","2500","100","7500","100","10000","100","5000","100","15000"],
]


WheelStyles = [
#bg graphic, wheel graphic, radius, minimum spins,
#spin SFX, volume, pitch
#winning sfx, volume, pitch
["hatchbg","prizewheel",110,3,"battle ball shake",80,150,"mining reveal full",100,100],
["hatchbg","prizewheel2",110,3,"battle ball shake",80,150,"mining reveal full",100,100]
]

def Wheel(prizelist,cost,style=0,costcoins=false,prizecoins=false)
  PrizeWheel.new(prizelist,cost,style,costcoins,prizecoins)
end


class PrizeWheel


  def pbUpdate
    pbUpdateSpriteHash(@sprites)
  end


  def initialize(prizelist,cost,style=0,costcoins=false,prizecoins=false)
    @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
    @prizes=Prizes[prizelist]
    @costcoins = costcoins
    @prizecoins = prizecoins
    @sprites = {}
    @cost=cost
    @style=WheelStyles[style]
    @bg=@style[0]
    @wheel=@style[1]
    @minspins=@style[3]
    @prizespin=0
    @angle=[72,36,0,313,287,251,216,180,144,108]
    @xyangle=[198,234,270,306,340,16,52,90,126,162]
    @sprites["bg"] = Sprite.new(@viewport)
    @sprites["bg"].bitmap = Bitmap.new("Graphics/Pictures/#{@bg}")
    @sprites["downarrow"] = AnimatedSprite.new("Graphics/Pictures/downarrow",8,28,40,2,@viewport)
    @sprites["downarrow"].x = (Graphics.width/2)-15
    @sprites["downarrow"].y = 10
    @sprites["downarrow"].z = 5
    @sprites["downarrow"].play
    @sprites["wheel"] = Sprite.new(@viewport)
    @sprites["wheel"].bitmap = Bitmap.new("Graphics/Pictures/#{@wheel}")
    @sprites["wheel"].center_origins
    @sprites["wheel"].x=Graphics.width/2
    @sprites["wheel"].y=Graphics.height/2
    for i in 0...10
      if GameData::Item.try_get(@prizes[i])
        @sprites["prize#{i}"]=ItemIconSprite.new(0,0,0,@viewport)
        @sprites["prize#{i}"].item = @prizes[i]
        @sprites["prize#{i}"].ox=24
        @sprites["prize#{i}"].oy=24
      elsif GameData::Species.try_get(@prizes[i])
        @sprites["prize#{i}"]=PokemonSpeciesIconSprite.new(@prizes[i],@viewport)
        @sprites["prize#{i}"].shiny = false
        @sprites["prize#{i}"].ox=32
        @sprites["prize#{i}"].oy=32
      else
        @sprites["prize#{i}"] = Sprite.new(@viewport)
        if @prizecoins == true
          @sprites["prize#{i}"].bitmap = Bitmap.new("Graphics/Items/COINCASE")
        else
          @sprites["prize#{i}"].bitmap = Bitmap.new("Graphics/Pictures/Money")
        end
        @sprites["prize#{i}"].center_origins
      end
      @sprites["prize#{i}"].angle = @angle[i]
      @sprites["prize#{i}"].x=(Graphics.width/2) + Math.cos(@xyangle[i].degrees)*@style[2]
      @sprites["prize#{i}"].y=(Graphics.height/2) + Math.sin(@xyangle[i].degrees)*@style[2]
    end
    main
  end

  def main
    loop do
      Graphics.update
      Input.update
      pbUpdate
      if Input.trigger?(Input::C)
        if @cost>0
          if @costcoins == true
            confirmtext="Spin the wheel for #{@cost} coins?"
          else
            confirmtext="Spin the wheel for $#{@cost}?"
          end
        else
          confirmtext="Spin the wheel?"
        end
          if pbConfirmMessage("#{confirmtext}")
            if @costcoins == true
              if $Trainer.coins>=@cost
                $Trainer.coins-=@cost
              else
               pbMessage(_INTL("You don't have enough coins..."))
                break
              end
            else
              if $Trainer.money>=@cost
                $Trainer.money-=@cost
              else
                pbMessage(_INTL("You don't have enough money..."))
                break
              end
            end
          spins=rand(360)
          spins+=360*(@minspins)
          spun=0
          click=true
          loop do
          pbUpdate
            @sprites["wheel"].angle -= 5
            @prizespin+=5
             for i in 0...10
              @sprites["prize#{i}"].angle -= 5
                @sprites["prize#{i}"].x= (Graphics.width/2) + Math.cos((@xyangle[i]+@prizespin).degrees)*@style[2]
                @sprites["prize#{i}"].y= (Graphics.height/2) + Math.sin((@xyangle[i]+@prizespin).degrees)*@style[2]
            end
            spun+=5
            Graphics.update
            if click=true
                pbSEPlay(@style[4],@style[5],@style[6])
                click=false
              else
                click=true
            end
            if spun>=spins
            prize=0
            prizey=[]
            for i in 0...10
              prizey[i]=@sprites["prize#{i}"].y
            end
             winner=prizey.min
              for i in 0...10
                if @sprites["prize#{i}"].y==winner
                   prize=i
                 end
              end
              prize=@prizes[prize]
              pbSEPlay(@style[7],@style[8],@style[9])
              if GameData::Item.try_get(prize)
                pbUpdate
                pbReceiveItem(prize)
              elsif GameData::Species.try_get(prize)
                pbUpdate
                  pbAddPokemon(prize,20)
              else
                if @prizecoins == true
                  pbMessage("You won #{prize} coins!")
                  prize = prize.to_i
                  $Trainer.coins+=prize
                else
                  pbMessage("You won $#{prize}!")
                  prize = prize.to_i
                  $Trainer.money+=prize
                end
              end
            break
            end
          end
        end
      end
      if Input.trigger?(Input::B)
        break
      end
    end
    pbFadeOutAndHide(@sprites) {pbUpdate}
    dispose
  end

  def dispose
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end
end


#center_origins command from Marin's Scripting Utilities.
#If you have that script, you can delete this section
class Sprite
    def center_origins
      return if !self.bitmap
      self.ox = self.bitmap.width / 2
      self.oy = self.bitmap.height / 2
  end
end



#.degrees command, to convert degrees to radians
class Numeric
     def degrees
     self * Math::PI / 180
     end
end

If you're using this in a version before v19, there's a couple last steps you need to do.
Find this section:
Ruby:
      if GameData::Item.try_get(@prizes[i])
        @sprites["prize#{i}"]=ItemIconSprite.new(0,0,0,@viewport)
        @sprites["prize#{i}"].item = @prizes[i]
      elsif GameData::Species.try_get(@prizes[i])
        @sprites["prize#{i}"]=PokemonSpeciesIconSprite.new(@prizes[i],@viewport)
         @sprites["prize#{i}"].ox=32
        @sprites["prize#{i}"].oy=32

Replace it with:
Ruby:
      if getID(PBItems,@prizes[i])>0
        @sprites["prize#{i}"]=ItemIconSprite.new(0,0,0,@viewport)
        @sprites["prize#{i}"].item=getID(PBItems,@prizes[i])
        @sprites["prize#{i}"].center_origins
      elsif getID(PBSpecies,@prizes[i])>0
        @sprites["prize#{i}"]=PokemonSpeciesIconSprite.new(getID(PBSpecies,@prizes[i]),@viewport)
        @sprites["prize#{i}"].ox=32
        @sprites["prize#{i}"].oy=32


Near the bottom, find this section:
Ruby:
              if GameData::Item.try_get(prize)
                pbUpdate
                pbReceiveItem(prize)
              elsif GameData::Species.try_get(prize)
                pbUpdate
                  pbAddPokemon(prize,20)
Replace it with:
Ruby:
              if getID(PBItems,prize)>0
                pbUpdate
                pbReceiveItem(prize)
              elsif
                getID(PBSpecies,prize)>0
                pbUpdate
                  pbAddPokemon(prize,20)

Graphics
4591

AiurJordan graciously made some beautiful graphics for this! Download the pack here!

  • Put "money.png" and "prizewheel.png" in Graphics/Pictures
    • prizewheel2.png is an edit of the original wheel (also made by AiurJordan) to display some coin values on it! These correspond with the fourth prize array!
  • If you're using the vanilla Game Corner tileset, put Game Corner interior.png in Graphics/Tilesets, overwriting the file already there. Otherwise, use an image editing program to put the wheeltile image into whatever tileset you're using.
  • Old wheel is just there if anyone has any reason to need it. I really recommend you use AiurJordan's, though!
Using the script
There's a few things to do before putting your wheels in place!

We've got two arrays-of-arrays defined at the top of our script: Prizes and Wheel Styles.

Ruby:
Prizes = [
[:POKEBALL,:REPEATBALL,:FASTBALL,:LEVELBALL,:NESTBALL,:DUSKBALL,:DIVEBALL,:HEAVYBALL,:GREATBALL,:MASTERBALL],
[:CHARMANDER,:CYNDAQUIL,:EEVEE,:PIKACHU,:CHIKORITA,:BULBASAUR,:SQUIRTLE,:TOTODILE,:MARILL,:RATTATA],
["100","200","300","400","500","600","700","800","900","1000"],
[:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,:POKEBALL,"100",:CHARMANDER,],
]

The arrays in Prizes are your prize pool! Items and Pokemon should be put in as :NAME, while money amounts should just be "X" (quotes included). It has to be exactly ten prizes- any less and it'll crash, any above ten won't display.

You probably won't use the WheelStyles array as much, but it's there to allow to easily save multiple graphic/audio changes!

Ruby:
WheelStyles = [
#bg graphic, wheel graphic, radius, minimum spins,
#spin SFX, volume, pitch
#winning sfx, volume, pitch
["hatchbg","prizewheel",110,3,"battle ball shake",80,150,"mining reveal full",100,100]
]
  • bg graphic- filename of the background image in Graphics/Images, in quotes
  • wheel graphic- filename of the background image in Graphics/Images, in quotes
  • radius- the radius of the icons on the wheel. (Not necessarily the radius of the wheel itself, unless you want the icons to be on the edges)
  • Minimum spins- the minimum number of times the wheel will make a full loop before landing. (It can make up to one final loop after that)
  • Spin SFX, volume, pitch- The file in Audio/SFX that plays repeatedly as the wheel spins, to create the feel of the wheel clacking. Volume is 0 to 100, pitch is 0 to 150, just like if you called it via event.
  • Winning SFX- same thing, except it's what plays when the wheel lands on a prize.

Now that that's all set up, all you have to is call it in an event, with Wheel(prizepool,cost,style=#)
  • prizepool- The array in Prizes that are on the wheel (remember that it starts at 0!)
  • cost- The cost to spin the wheel. (Set to 0 for a free wheel)
  • style=# - The settings set up in WheelStyles (with # being the array it pulls from), if you want something different from the default.
  • If you want to make the player spend coins instead of money, add costcoins=true into the command. (It'd look like Wheel(prizepoolcost,style=#,costcoins=true)
  • If you want to make the player win coins instead of money, do the same thing, but with prizecoins=true. (I believe you still need to define costcoins in this, so be sure to do that as well, even if you want it to cost money- Wheel(prizepoolcost,style=#,costcoins=false,prizecoins=true) )


Future Goals
  • Display the name of the prize on its slot. (Right now, the size of the text and getting rotation to work has been causing issues for me)
  • Slots that let you win an item from an array- for example, landing a "Random Poké Ball" slot would pick a Poke Ball out of an array
  • Allow for more customization of prizes- Shiny Pokémon, Pokémon with special moves, unique effects for your Pokémon, etc.
  • Allow money and coins on the same wheel
  • Allow for customization of how many prizes are in a wheel
  • Allow devs to set specific probabilities for different slots
  • Maybe make a pretty animation for the prize
  • I might try to make this a plugin file rather than making it a new script section.
Credits
  • Marin, for his scripting utilities
  • Krom Stern from stackexchange for the circular movement
  • Flylib.com for the conversion from radians into degrees
  • AiurJordan for the tile and high-quality prize wheels, as well as the code relating to coin usage
  • Ganz/Webkinz for the Wheel of Wow graphic this wheel was based on
  • And me, TechSkylander1518!
Author
TechSkylander1518
Downloads
315
Views
2,285
First release
Last update
Rating
5.00 star(s) 7 ratings

More resources from TechSkylander1518

Latest updates

  1. Fixing shiny bug

    Not sure why this is working this way, but it was defaulting to shiny menu sprites for Pokemon...
  2. Graphic update and coins

    Some beautiful new graphics made by AiurJordan! Also, coin functionality!
  3. v19 Update

    Now compatible with v19!

Latest reviews

Really fun and unique, but a few pokemon I've tried (Treeko, Rowlett, Grookey) Appear as money symbols in the wheel and upon landing them, the game crashes.
TechSkylander1518
TechSkylander1518
Hm, can you share what your prize array looks like?
One of my favorite plugins to use! It's a nice way to add random rewards, and fun all at the same time. 11/10!
TechSkylander1518
TechSkylander1518
That's really kind of you to say! I'm glad you're having so much fun with it!
Oh yes, this looks so much fun. I can't wait to play with it.
TechSkylander1518
TechSkylander1518
Thank you! I'm looking forward to seeing what you do with it!
Excellent Script. One of the best thing I can imagine to have in fangame. Too Creative.
TechSkylander1518
TechSkylander1518
Thank you, that's really nice of you to say!
That's a great addition for the fangame development community and I'll be definitely using this in my future game projects, this'll look beautiful in the casino!
TechSkylander1518
TechSkylander1518
Thank you! Looking forward to seeing what you do with it!
Top