This is my own version of a roulette mini game. The gems you can see on the screenshot below will rotate as expected after you hit the OK button. Later on it will show you your prize. After you collect it, it will show up on the window on the right hand side of the screen as an icon. You may collect more prizes the more attempts you get.
Just remember I didn't provide the gems you see below. Use your own icons if possible, you just need 10 of them.
SCREENSHOT
Instructions
There is a TXT file you need to edit so you can configure the prizes the player might earn after spinning the wheel. Later on you may check the instructions included in my script. You also need to place all required (gem) graphics in Graphics/Icons directory, you may need to create it first.
[/align]
# * Gem Roulette XP
# Scripter : Kyonides-Arkanthos
# v 1.0.7 - 2017-11-14
# Llamados a Script
# Para abrir la Ruleta de Gemas : $scene = Gem_Roulette.new
# Para aumentar intentos de girarla : $game_party.roulette_attempts += Número
# Este script les permitirá hacer girar unas gemas y al detenerse, les
# permitirá recolectar su premio. Los premios recolectados podrán verlos a la
# derecha de las gemas en una ventana desplegada especialmente para eso.
# Los premios son seleccionados aleatoriamente por el script. Uds. pueden
# configurar qué premios podrían obtener según la ranura seleccionada.
# La Constante PRIZE_FILENAME guarda el nombre del archivo TXT donde colocarán
# los premios que prefieran.
# Si así lo desean, una o más ranuras pueden ser iguales a No Hay Premio.
# Recuerden que van a necesitar los gráficos de las Gemas-Ranuras.
module GemRouletteSetup
# Prefijo de los Iconos de Gemas (Sirven como Ranuras)
ICON_NAME_PREFIX = 'gema'
# Sonido para Inicio y Final del Giro de la Ruleta
SE_STARTUP = "056-Right02"
# Archivo con Configuración de Premios
PRIZE_FILENAME = 'premios.txt'
# Etiqueta del Indicador de Posición en el Archivo
POSITION_LABEL = 'Posición'
# Etiqueta de Ningún Premio en el Archivo
NO_PRIZE = 'Nada'
# Etiqueta de Objeto como Premio en el Archivo
ITEM_PRIZE = 'Objeto'
# Etiqueta de Arma como Premio en el Archivo
WEAPON_PRIZE = 'Arma'
# Etiqueta de Armadura como Premio en el Archivo
ARMOR_PRIZE = 'Armadura'
# Etiqueta de Habilidad o Skill como Premio en el Archivo
SKILL_PRIZE = 'Habilidad'
# Etiqueta de Puntos de Vida Perdidos
HP_LOSS = 'PV'
# Etiqueta de Puntos de Mana Perdidos
SP_LOSS = 'PM'
# Nombre de Icono para Pérdida de Puntos de PV o PM
STATS_LOSS_ICON = ''
# Etiqueta de Puntos Obtenidos
STATS_LOSS_LABEL = ' Obtenidos: '
# Etiqueta de Girar la Rueda o Ruleta
SPIN_WHEEL = 'Girar Rueda'
# Etiqueta de Intentos Restantes
ATTEMPTS_LEFT = 'Intentos Restantes: '
# Etiqueta de Recolectar Premio
COLLECT = 'Recolectar'
# Etiqueta de Se Quedó Sin Intentos
RUNOUT = 'No Más Giros'
# Etiqueta de Lo Sentimos, No Hay Premio Esta Vez
NEXT_TIME = '¡Suerte para la próxima!'
# Etiqueta de Puntos
POINTS = 'Puntos'
# NO EDITAR LO SIGUIENTE
PRIZE_RXDATA = 'Data/GemRoulette.rxdata'
PRIZES = {}
@prizes = []
@prize_points = []
def self.prizes() @prizes end
def self.prize_points() @prize_points end
def self.get_prize_data
if $DEBUG and File.exist?(PRIZE_FILENAME)
lines = File.readlines(PRIZE_FILENAME)
10.times{|n| pts = lines[0].scan(/\d+ #{POINTS}/)[0].sub!(/ #{POINTS}/,'')
@prize_points << pts.to_i
lines.shift
PRIZES[n] = []
regex = /[a-zA-Z]+/
kinds = lines[0].scan(regex).map {|ln| self.prize_kind(ln) }
indexes = lines[0].scan(/[0-9\-]+/).map {|ln| self.prize_kind(ln) }
kinds.size.times {|m| PRIZES[n] << [kinds[m], indexes[m]] }
lines.shift }
File.open(PRIZE_RXDATA, 'wb') {|file|
Marshal.dump(@prize_points, file)
Marshal.dump(PRIZES, file) }
return
end
File.open(PRIZE_RXDATA, 'rb') {|file|
@prize_points = Marshal.load(file)
PRIZES.merge!(Marshal.load(file)) }
end
def self.prize_kind(kind)
regexp = /\d+/
prize = case kind
when ITEM_PRIZE then :item
when WEAPON_PRIZE then :weapon
when ARMOR_PRIZE then :armor
when SKILL_PRIZE then :skill
when HP_LOSS then :hp
when SP_LOSS then :sp
when regexp then kind.to_i
end
return prize
end
self.get_prize_data
end
class StatsItem
attr_reader :name, :points, :icon_name
def initialize(new_name, new_points)
@name = new_name.to_s.upcase + ' ' + GemRouletteSetup::STATS_LOSS_LABEL
@name += new_points.to_s
@points = new_points
@icon_name = GemRouletteSetup::STATS_LOSS_ICON
end
end
class Game_Party
attr_accessor :roulette_attempts, :roulette_points
alias kyon_gem_roulette_gm_party_init initialize
def initialize
@roulette_attempts = 0
@roulette_points = 0
@skills = {}
kyon_gem_roulette_gm_party_init
end
def gain_skill(sid, n)
return unless sid > 0
@skills[sid] = [[skill_number(sid) + n, 0].max, 99].min
end
def lose_skill(sid, n) gain_skill(sid, -n) end
def skill_number(sid) @skills.include?(sid)? @skills[sid] : 0 end
end
class Sprite_Blink < Sprite
def update
super
if @_blink
@_blink_count = (@_blink_count + 1) % 32
alpha = 6 * (@_blink_count < 16 ? 16 - @_blink_count : @_blink_count - 16)
self.color.set(255, 255, 255, alpha)
end
@@_animations.clear rescue nil
end
def blink_on
return if @_blink
@_blink = true
@_blink_count = 0
end
def blink_off
return unless @_blink
@_blink = false
self.color.set(0, 0, 0, 0)
end
end
class Window_Roulette_Prizes < Window_Base
def initialize
super(552, 80, 88, 340)
@column_max = 2
refresh
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = GemRouletteSetup.prizes
@item_max = @data.size
return if @item_max == 0
self.contents = Bitmap.new(width - 32, @item_max * 32)
@item_max.times {|n| draw_item(n) }
end
def draw_item(index)
x = index % 2 * 32
y = index / 2 * 32
bitmap = RPG::Cache.icon(@data[index])
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
end
end
class Window_Command
def replace_command(index, command)
@commands[index] = command
refresh
end
end
class Window_GRPLabel < Window_Base
def initialize(w)
super(0, 0, w, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def update
@option_window.update
@prizes_window.update
@item_sprites.each {|sprite| sprite.update }
if @move
refresh_sprites
return
end
if Input.trigger?(Input::B)
exit_scene
return
elsif Input.trigger?(Input::C)
if $game_party.roulette_attempts == 0
if @result
retrieve_new_prize
exit_scene
else
$game_system.se_play($data_system.buzzer_se)
end
return
end
$game_system.se_play($data_system.decision_se)
retrieve_new_prize
end
end
def exit_scene
$game_system.se_play($data_system.buzzer_se)
GemRouletteSetup.prizes.clear
$scene = Scene_Map.new
end
def retrieve_new_prize
if !@move and !@result
@item_sprites[@blink_index].blink_off
@option_window.index = -1
$game_party.roulette_attempts -= 1
make_attempts_left_label
@index = rand(@item_max)
@move = true
return
end
return unless @result
GemRouletteSetup.prizes << @new_prize.icon_name if @new_prize
@prizes_window.refresh
@option_window.index = 0
case @kind
when :item then $game_party.gain_item(@new_prize.id, 1)
when :weapon then $game_party.gain_weapon(@new_prize.id, 1)
when :armor then $game_party.gain_armor(@new_prize.id, 1)
when :skill then $game_party.gain_skill(@new_prize.id, 1)
when :hp then $game_party.actors[0].hp += @new_prize.points
when :sp then $game_party.actors[0].sp += @new_prize.points
end
@prize_sprites[0].bitmap.clear rescue nil
@prize_sprites[1].bitmap.clear rescue nil
@result = nil
spin = $game_party.roulette_attempts > 0
comm = spin ? GemRouletteSetup::SPIN_WHEEL : GemRouletteSetup::RUNOUT
@option_window.replace_command(0,comm)
end
def check_prize
$game_party.roulette_points += GemRouletteSetup.prize_points[@blink_index]
@points_window.refresh
prizes = GemRouletteSetup::PRIZES[@result]
unless prizes[0]
no_prize
return
end
@new_prize = case prizes.size
when 1 then prizes[0][0] ? prize_kind(prizes[0][0], prizes[0][1]) : nil
else
index = prizes.size > 2 ? rand(prizes.size) : rand(4) % 2
prize_kind(prizes[index][0], prizes[index][1])
end
unless @new_prize
no_prize
return
end
@prize_sprites[0].bitmap = RPG::Cache.icon(@new_prize.icon_name).dup
@prize_sprites[1].bitmap = bitmap = Bitmap.new(180, 24)
bitmap.font.bold = true
bitmap.font.size = 19
bitmap.draw_text(0, 0, 180, 24, @new_prize.name, 1)
@option_window.replace_command(0, GemRouletteSetup::COLLECT)
end
def prize_kind(kind, index)
@kind = kind
case kind
when :item then $data_items[index]
when :weapon then $data_weapons[index]
when :armor then $data_armors[index]
when :skill then $data_skills[index]
when :hp, :sp then StatsItem.new(kind, index)
end
end
Done! Honestly I had uploaded them long time ago, but I just forgot to update the main post for some weird reason and the fact that the demos are in Spanish and there's none in English. The main reason was that "my customers" didn't speak English (fluently at least) so I had no good reason to work on a translation except for the TXT files where I pasted my scripts. Now you should be able to run a demo and check out how well it works on your favorite platform.
(11-16-2016, 11:43 PM)kyonides Wrote: Done! Honestly I had uploaded them long time ago, but I just forgot to update the main post for some weird reason and the fact that the demos are in Spanish and there's none in English. The main reason was that "my customers" didn't speak English (fluently at least) so I had no good reason to work on a translation except for the TXT files where I pasted my scripts. Now you should be able to run a demo and check out how well it works on your favorite platform.
Thanks but when I try to run the game I get the following error message:
I noticed I never uploaded version 1.0.3 of Gem Roulette XP, but I did just a couple of minutes ago. Now you all should be able to test it, don't hesitate to contact me if you find any other bug. Just keep in mind that you should have configured the TXT file first!
(11-17-2016, 08:36 PM)kyonides Wrote: I noticed I never uploaded version 1.0.3 of Gem Roulette XP, but I did just a couple of minutes ago. Now you all should be able to test it, don't hesitate to contact me if you find any other bug. Just keep in mind that you should have configured the TXT file first!
Thanks, seems like Im going to be your bugtester^^
Whenever I try to use the item Cofre Regular I get the following error message:
RandomPrize? That's weird, I looked for anything called random and the only place I found it was in the script comments. I don't know why it's looking for that stuff then.
I updated this stand alone version of Gem Roulette for XP, now it's available in both languages, namely English and Spanish. It also includes the newest feature where your team leader may lose his or her HP or SP if the wheel stops at the "wrong" gem!
You only need to leave a comment like HP 50 or SP 25 as a possible prize if you want the lead character earn those points or use negative values to make him or her lose the specified amount of points instead! If he or she earns the points, it will cure that character unless he or she has reached its maximum amount of points.