# Prize Wheels N/A

Pokémon Essentials Version

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,],

]

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]
]

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

class PrizeWheel

def pbUpdate
end

def initialize(prizelist,cost,style=0)
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@prizes=Prizes[prizelist]
@sprites = {}
@cost=cost
@style=WheelStyles[0]
@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 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
else
@sprites["prize#{i}"] = Sprite.new(@viewport)
@sprites["prize#{i}"].bitmap = Bitmap.new("Graphics/Pictures/Money")
@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
confirmtext="Spin the wheel for $#{@cost}?" else confirmtext="Spin the wheel?" end if pbConfirmMessage("#{confirmtext}") if$Trainer.money>=@cost
$Trainer.money-=@cost else pbMessage(_INTL("You don't have enough money...")) break 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 getID(PBItems,prize)>0 pbUpdate pbReceiveItem(prize) elsif getID(PBSpecies,prize)>0 pbUpdate pbAddPokemon(prize,20) else pbMessage("You won$#{prize}!")
prize = prize.to_i
$Trainer.money+=prize 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:  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] 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 else @sprites["prize#{i}"] = Sprite.new(@viewport) @sprites["prize#{i}"].bitmap = Bitmap.new("Graphics/Pictures/Money") @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 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 else @sprites["prize#{i}"] = Sprite.new(@viewport) @sprites["prize#{i}"].bitmap = Bitmap.new("Graphics/Pictures/Money") @sprites["prize#{i}"].center_origins end 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) else pbMessage("You won$#{prize}!")
prize = prize.to_i
$Trainer.money+=prize end Replace it with: Ruby:  if getID(PBItems,prize)>0 pbUpdate pbReceiveItem(prize) elsif getID(PBSpecies,prize)>0 pbUpdate pbAddPokemon(prize,20) else pbMessage("You won$#{prize}!")
prize = prize.to_i
\$Trainer.money+=prize
end

Make sure to grab the money.png and prizewheel.png files from the download link and put them in Graphics/Pictures! (Although, if you have spriting abilities, I do recommend you use the wheel as a base and make a new one- I'm not a spriter, and I realized too late that some lines were off + I'm pretty sure I used the wrong resolution + I realized too late that the center circle was lopsided)

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.

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 players to spend and win coins instead of money
• 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
• Ganz/Webkinz for the Wheel of Wow graphic I based this wheel on
• And me, TechSkylander1518!
Author
TechSkylander1518
70
Views
579
First release
Last update
Rating
3 ratings

1. ### v19 Update

Now compatible with v19!

### Latest reviews

Oh yes, this looks so much fun. I can't wait to play with it.
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
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
Thank you! Looking forward to seeing what you do with it!