PDA

View Full Version : [Essentials script] Pokemon Style Slot Machines


KitsuneKouta
November 19th, 2010, 09:31 PM
This slot machine script is modeled after the RSE version. You can alter it without too much trouble into whatever other version you want. All features found in the RSE slot machines are included in this script, except for the Reel Time feature. It has been started, but I'll get to that momentarily.

To put this script into your game, simply paste this into a new script section:
###################################################################
# The one-armed bandit for the Casino ©Nintendo (Made by Itachihro)
# Translated and improved by KitsuneKouta
###################################################################
class Scene_Slots
def initialize(usedcoins=0,slot1=nil,slot2=nil,slot3=nil,bolts=-1)

#Initialization of the game

@content1=slot1#Content of @Slot1
@content2=slot2#Content of @Slot2
@content3=slot3#Content of @Slot3
@usedcoins=usedcoins

#Initialization of variables

@FrameCount=0
@GameActive=false
@RedSevenWin=[1,1,1]
@BlueSevenWin=[2,2,2]
@LotadWin=[5,5,5]
@AzurillWin=[4,4,4]
@PikachuWin=[7,7,7]
@ReplayWin=[3,3,3]
@PokeballWin=[6,6]
@BigPokeballWin=[6,6,6]
@SmallRedBonus=[1,1,2]
@SmallBlueBonus=[2,2,1]
@Payout=0
@fastPayout=false
@WinAnimationOver=false
@bolts=bolts
@ReelTime=false
@ReelCount=0
@time=0
@Line1Flash=false
@Line2aFlash=false
@Line2bFlash=false
@Line3aFlash=false
@Line3bFlash=false

#Graphics are defined here

#Insert (thrown coins=0)

@Insert_01=RPG::Cache.picture("Insert 1")
@Insert_02=RPG::Cache.picture("Insert 2")

#Insert (thrown coins=1-3)

@Insert_03=RPG::Cache.picture("Insert 3")
@Insert_04=RPG::Cache.picture("Insert 4")
@Insert_05=RPG::Cache.picture("Insert 5")
@Insert_06=RPG::Cache.picture("Insert 6")

#Reel Time

@ReelTime_0=RPG::Cache.picture("Reel Time 0")
@ReelTime_1=RPG::Cache.picture("Reel Time 1")
@ReelTime_2=RPG::Cache.picture("Reel Time 2")
@ReelTime_3=RPG::Cache.picture("Reel Time 3")
@ReelTime_4=RPG::Cache.picture("Reel Time 4")
@ReelTime_5=RPG::Cache.picture("Reel Time 5")

#Stop

@Stop_01=RPG::Cache.picture("Stop 1")
@Stop_02=RPG::Cache.picture("Stop 2")
@Stop_03=RPG::Cache.picture("Stop 3")
@Stop_04=RPG::Cache.picture("Stop 4")
@Stop_05=RPG::Cache.picture("Stop 5")
@Stop_06=RPG::Cache.picture("Stop 6")

#Win

@Win_01=RPG::Cache.picture("Win 1")
@Win_02=RPG::Cache.picture("Win 2")
@Win_03=RPG::Cache.picture("Win 3")
@Win_04=RPG::Cache.picture("Win 4")

#Big Bonus

@Big_B_01=RPG::Cache.picture("Big Bonus 1")
@Big_B_02=RPG::Cache.picture("Big Bonus 2")
@Big_B_03=RPG::Cache.picture("Big Bonus 3")
@Big_B_04=RPG::Cache.picture("Big Bonus 4")

#Reg Bonus

@Reg_B_01=RPG::Cache.picture("Bonus 1")
@Reg_B_02=RPG::Cache.picture("Bonus 2")
@Reg_B_03=RPG::Cache.picture("Bonus 3")
@Reg_B_04=RPG::Cache.picture("Bonus 4")

#Flashing lights on win

@Win_Light1=RPG::Cache.picture("Win Out")
@Win_Light2=RPG::Cache.picture("Win Middle")
@Win_Light3=RPG::Cache.picture("Win In")

#Lose

@Lose_01=RPG::Cache.picture("Lose 1")
@Lose_02=RPG::Cache.picture("Lose 2")

#Lighting Bolt

@LBolt=RPG::Cache.picture("Bolt")

#Background

@BackgroundIMG=RPG::Cache.picture("Slots Layout")

#Highlighted lines

@Light_1=RPG::Cache.picture("Line 1")
@Light_2_1=RPG::Cache.picture("Line 2")
@Light_2_2=RPG::Cache.picture("Line 2")
@Light_3_1=RPG::Cache.picture("Line 3-1")
@Light_3_2=RPG::Cache.picture("Line 3-2")

#Buttons

@PushButton1=RPG::Cache.picture("Button Pressed")
@PushButton2=RPG::Cache.picture("Button Pressed")
@PushButton3=RPG::Cache.picture("Button Pressed")

#Numbers

@Credit0=RPG::Cache.picture("0")
@Credit1=RPG::Cache.picture("1")
@Credit2=RPG::Cache.picture("2")
@Credit3=RPG::Cache.picture("3")
@Credit4=RPG::Cache.picture("4")
@Credit5=RPG::Cache.picture("5")
@Credit6=RPG::Cache.picture("6")
@Credit7=RPG::Cache.picture("7")
@Credit8=RPG::Cache.picture("8")
@Credit9=RPG::Cache.picture("9")

#Array for the number images

@Credit_Numbers=[@Credit0,@Credit1,@Credit2,@Credit3,@Credit4,@Credit5,@Credit6,
@Credit7,@Credit8,@Credit9]

end

def main
#============================
#Creation of the sprites
#==========================

#Background

@Background=Sprite.new
@Background.bitmap=@BackgroundIMG

#Black window on the right

@SupportWindow=Sprite.new
@SupportWindow.bitmap=@Insert_01

#Used for flashing lights

@SupportWindow2=Sprite.new

#Credit field

@Creditfield1=Sprite.new
@Creditfield1.x=358
@Creditfield1.y=36
@Creditfield2=Sprite.new
@Creditfield2.x=372
@Creditfield2.y=36
@Creditfield3=Sprite.new
@Creditfield3.x=386
@Creditfield3.y=36
@Creditfield4=Sprite.new
@Creditfield4.x=400
@Creditfield4.y=36

#Payout field

@Payoutfield1=Sprite.new
@Payoutfield1.x=422
@Payoutfield1.y=36
@Payoutfield2=Sprite.new
@Payoutfield2.x=436
@Payoutfield2.y=36
@Payoutfield3=Sprite.new
@Payoutfield3.x=450
@Payoutfield3.y=36
@Payoutfield4=Sprite.new
@Payoutfield4.x=464
@Payoutfield4.y=36

#Buttons

@Button1=Sprite.new
@Button1.x=84
@Button1.y=246
@Button2=Sprite.new
@Button2.x=164
@Button2.y=246
@Button3=Sprite.new
@Button3.x=244
@Button3.y=246

#Slots

if @content1!=nil
@Slot1=Slot.new(62,@content1[0],@content1[1],@content1[2])
else
@Slot1=Slot.new(62)
end
if @content2!=nil
@Slot2=Slot.new(142,@content2[0],@content2[1],@content2[2])
else
@Slot2=Slot.new(142)
end
if @content3!=nil
@Slot3=Slot.new(222,@content3[0],@content3[1],@content3[2])
else
@Slot3=Slot.new(222)
end

#Highlighted lines created

@Light=Sprite.new
@Light2=Sprite.new
@Light3=Sprite.new
@Light4=Sprite.new
@Light5=Sprite.new
#Transition
Graphics.transition

#Updates lightning bolt graphics
boltGraphics

#Start Main Loop
loop do
Graphics.update
Input.update
update
#Loopbreak at scene change
if $scene!=self
break
end
end

#Graphics freeze, delete objects
Graphics.freeze
@SupportWindow.dispose
@SupportWindow2.dispose
@Background.dispose
@Creditfield1.dispose
@Creditfield2.dispose
@Creditfield3.dispose
@Creditfield4.dispose
@Payoutfield1.dispose
@Payoutfield2.dispose
@Payoutfield3.dispose
@Payoutfield4.dispose
@Slot1.dispose
@Slot2.dispose
@Slot3.dispose
@Button1.dispose
@Button2.dispose
@Button3.dispose
@Light.dispose
@Light2.dispose
@Light3.dispose
@Light4.dispose
@Light5.dispose
end

#============================================================
#More or less everything worked, processed, and analyzed
#============================================================
def update
@FrameCount=@FrameCount+1
if !(@GameActive)
@evaluated=false
end

def coinCheck
if $PokemonGlobal.coins<9999
$PokemonGlobal.coins=$PokemonGlobal.coins+1
elsif $PokemonGlobal.coins>=9999
$PokemonGlobal.coins=9999
@Payout=0
end
end

if (@Payout==0)&&!(@Replay)&&!(@GameActive)&&($PokemonGlobal.coins==0)#&&!(@ReelTime)
Kernel.pbMessage("You've run out of COINS.\nGame over!")
$scene=Scene_Map.new
end

#=====================================================================
#Handler for finished game (Win or Lose)
#Support Window and Coins
#=====================================================================
if (@GameActive) &&!(@Slot3.active)
if !(@evaluated)
self.evaluate
end
if @Win
case @FrameCount
when 4
lineErase
@SupportWindow2.bitmap=@Win_Light1
if @BigBonus
@SupportWindow.bitmap=@Big_B_01
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_01
else
@SupportWindow.bitmap=@Win_01
end
when 8
lineFlash
@SupportWindow2.bitmap=@Win_Light2
if @BigBonus
@SupportWindow.bitmap=@Big_B_02
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_02
else
@SupportWindow.bitmap=@Win_02
end
when 12
lineErase
@SupportWindow2.bitmap=@Win_Light3
if @BigBonus
@SupportWindow.bitmap=@Big_B_03
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_03
else
@SupportWindow.bitmap=@Win_03
end
when 16
lineFlash
@SupportWindow2.bitmap=@Win_Light2
if @BigBonus
@SupportWindow.bitmap=@Big_B_04
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_04
else
@SupportWindow.bitmap=@Win_04
end
when 20
lineErase
@SupportWindow2.bitmap=@Win_Light1
if @BigBonus
@SupportWindow.bitmap=@Big_B_01
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_01
else
@SupportWindow.bitmap=@Win_01
end
when 24
lineFlash
@SupportWindow2.bitmap=@Win_Light2
if @BigBonus
@SupportWindow.bitmap=@Big_B_02
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_02
else
@SupportWindow.bitmap=@Win_02
end
when 28
lineErase
@SupportWindow2.bitmap=@Win_Light3
if @BigBonus
@SupportWindow.bitmap=@Big_B_03
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_03
else
@SupportWindow.bitmap=@Win_03
end
when 32
lineFlash
@SupportWindow2.bitmap=@Win_Light2
if @BigBonus
@SupportWindow.bitmap=@Big_B_04
elsif @RegBonus
@SupportWindow.bitmap=@Reg_B_04
else
@SupportWindow.bitmap=@Win_04
end
@FrameCount=0
@WinAnimationOver=true
end

def lineFlash
if @Line1Flash
@Light.bitmap=@Light_1
end
if @Line2aFlash
@Light2.bitmap=@Light_2_1
end
if @Line2bFlash
@Light3.bitmap=@Light_2_2
end
if @Line3aFlash
@Light4.bitmap=@Light_3_1
end
if @Line3bFlash
@Light5.bitmap=@Light_3_2
end
end

def lineErase
@Light.bitmap=nil
@Light2.bitmap=nil
@Light3.bitmap=nil
@Light4.bitmap=nil
@Light5.bitmap=nil
end

if ((@FrameCount%1)==0)&&@fastPayout&&@WinAnimationOver&&(@Payout>0)
@Payout=@Payout-1
coinCheck
elsif ((@FrameCount%2)==0)&&@WinAnimationOver&&(@Payout>0)
@Payout=@Payout-1
coinCheck
end

if (Input.trigger?(Input::C))&&@Payout>0
@fastPayout=true
end

if (@Payout==0)&&!(@Replay)#&&!(@ReelTime)
if $PokemonGlobal.coins==9999
Kernel.pbMessage("You've got 9,999 COINS.")
elsif $PokemonGlobal.coins==0
Kernel.pbMessage("You've run out of COINS./nGame over!")
end
@GameActive=false
@FrameCount=0
@Line2_Active=false
@Line3_Active=false
@Light.bitmap=nil
@Light2.bitmap=nil
@Light3.bitmap=nil
@Light4.bitmap=nil
@Light5.bitmap=nil
@SupportWindow2.bitmap=nil
@BigBonus=false
@RegBonus=false
@fastPayout=false
@WinAnimationOver=false
@Line1Flash=false
@Line2aFlash=false
@Line2bFlash=false
@Line3aFlash=false
@Line3bFlash=false
end

if (@Payout==0)&&(@Replay)#&&!(@ReelTime)
@Slot1.active=true
@Slot2.active=true
@Slot3.active=true
@Replay=false
@SupportWindow2.bitmap=nil
@FrameCount=0
@BigBonus=false
@RegBonus=false
@fastPayout=false
@WinAnimationOver=false
@Line1Flash=false
@Line2aFlash=false
@Line2bFlash=false
@Line3aFlash=false
@Line3bFlash=false
end

if (@Payout==0)&&(@WinAnimationOver)#&&(@ReelCount>0)
@Slot1.active=true
@Slot2.active=true
@Slot3.active=true
#@ReelCount-=1
@SupportWindow2.bitmap=nil
@FrameCount=0
@BigBonus=false
@RegBonus=false
@fastPayout=false
@WinAnimationOver=false
@Line1Flash=false
@Line2aFlash=false
@Line2bFlash=false
@Line3aFlash=false
@Line3bFlash=false
#if @ReelCount==0
# @bolts=-1
#end
end

else
case @FrameCount
when 10
@SupportWindow.bitmap=@Lose_02
when 20
@SupportWindow.bitmap=@Lose_01
when 30
@SupportWindow.bitmap=@Lose_02
when 40
@SupportWindow.bitmap=@Lose_01
@FrameCount=0
@GameActive=false
@Line2_Active=false
@Line3_Active=false
@Light.bitmap=nil
@Light2.bitmap=nil
@Light3.bitmap=nil
@Light4.bitmap=nil
@Light5.bitmap=nil
end
end
end
#================================================
#Input Processes
#===============================================
@content1=[@Slot1.TopVal,@Slot1.MidVal,@Slot1.DownVal]
@content2=[@Slot2.TopVal,@Slot2.MidVal,@Slot2.DownVal]
@content3=[@Slot3.TopVal,@Slot3.MidVal,@Slot3.DownVal]
if (Input.trigger?(Input::C))&&(@GameActive)
if @Slot1.active
pbSEPlay("SlotsStop")
@Button1.bitmap=@PushButton1
@Slot1.active=false
elsif @Slot2.active
pbSEPlay("SlotsStop")
@Button2.bitmap=@PushButton2
@Slot2.active=false
elsif @Slot3.active
pbSEPlay("SlotsStop")
@Button3.bitmap=@PushButton3
@Slot3.active=false
end
end

if @GameActive
@time+=1
if !@Slot3.active
if @time>=10
@Button3.bitmap=nil
@Button2.bitmap=nil
@Button1.bitmap=nil
@time=0
end
elsif !@Slot2.active
if @time>=10
@Button3.bitmap=nil
@Button2.bitmap=nil
@Button1.bitmap=nil
@time=0
end
else
if @time>=10
@Button3.bitmap=nil
@Button2.bitmap=nil
@Button1.bitmap=nil
@time=0
end
end
end

if (Input.trigger?(Input::CTRL))&&(@usedcoins<1)&&!(@GameActive)&&(@Payout==0)
$scene=Scene_Slots_Help.new(@usedcoins,@content1,@content2,@content3,@bolts)
end

if (Input.trigger?(Input::DOWN))&&!(@GameActive)&&$PokemonGlobal.coins>0
pbSEPlay("SlotsSelect")
@usedcoins=@usedcoins+1
$PokemonGlobal.coins=$PokemonGlobal.coins-1
if @usedcoins==1
@Light.bitmap=@Light_1
@Light.y=138
@Light.x=2
end
if @usedcoins==2
@Line2_Active=true
@Light.bitmap=@Light_1
@Light.y=138
@Light.x=2
@Light2.bitmap=@Light_2_1
@Light2.y=90
@Light2.x=2
@Light3.bitmap=@Light_2_2
@Light3.y=186
@Light3.x=2
end
if @usedcoins==3
@Light.bitmap=@Light_1
@Light.y=138
@Light.x=2
@Light2.bitmap=@Light_2_1
@Light2.y=90
@Light2.x=2
@Light3.bitmap=@Light_2_2
@Light3.y=186
@Light3.x=2
@Light4.bitmap=@Light_3_1
@Light4.y=50
@Light4.x=2
@Light5.bitmap=@Light_3_2
@Light5.y=50
@Light5.x=2
@Line3_Active=true
@GameActive=true
@Slot1.active=true
@Slot2.active=true
@Slot3.active=true
@FrameCount=0
end
#rnd=rand(20)
#if rnd==1
# @ReelTime=true
# rnd2=rand(5)
#end
#@ReelCount=rnd2#left off
#if @ReelCount==0
# @ReelTime=false
#else
# @ReelTime=true
#end
end

if (Input.trigger?(Input::B))&&!(@GameActive)
if Kernel.pbConfirmMessage("Quit the game?")
$PokemonGlobal.coins=$PokemonGlobal.coins+@usedcoins
@bolts=-1
boltGraphics
$scene=Scene_Map.new
end
end

if (Input.trigger?(Input::C))&&!(@GameActive)&&(@usedcoins>0)
@GameActive=true
@Slot1.active=true
@Slot2.active=true
@Slot3.active=true
@FrameCount=0
end

#=================================================
#@SupportWindow update
#=================================================
# Case: No coins thrown
if @usedcoins==0&&!(@GameActive)
if @FrameCount==16
@SupportWindow.bitmap=@Insert_01
end
if @FrameCount==32
@SupportWindow.bitmap=@Insert_02
@FrameCount=0
end
end

# One or more coins thrown (and the game is not yet active)
if (@usedcoins > 0) && !(@GameActive)
case @FrameCount
when 16
@SupportWindow.bitmap=@Insert_03
when 24
@SupportWindow.bitmap=@Insert_04
when 32
@SupportWindow.bitmap=@Insert_05
when 40
@SupportWindow.bitmap=@Insert_06
@FrameCount=0
end
end

# Game running and Reel Time active

if (@GameActive)&&(@ReelTime)
Graphics.update
case @FrameCount
when 40
@SupportWindow.bitmap=@ReelTime_0
when 80
@SupportWindow.bitmap=@ReelTime_5
when 120
@SupportWindow.bitmap=@ReelTime_4
when 160
@SupportWindow.bitmap=@ReelTime_3
when 200
@SupportWindow.bitmap=@ReelTime_2
when 240
@SupportWindow.bitmap=@ReelTime_1
@ReelTime=false
@bolts= -1
@FrameCount=0
boltGraphics
end
end


# Game running
if (@GameActive)&&(@Slot3.active)#&&!(@ReelTime)
case @FrameCount
when 8
@SupportWindow.bitmap=@Stop_01
when 16
@SupportWindow.bitmap=@Stop_02
when 24
@SupportWindow.bitmap=@Stop_03
when 32
@SupportWindow.bitmap=@Stop_02
when 40
@SupportWindow.bitmap=@Stop_04
when 48
@SupportWindow.bitmap=@Stop_05
when 56
@SupportWindow.bitmap=@Stop_06
when 64
@SupportWindow.bitmap=@Stop_05
@FrameCount=0
end
end

#==================================================
#Credit update
#==================================================
@Creditfield1.bitmap=@Credit_Numbers[$PokemonGlobal.coins/1000]
@Creditfield2.bitmap=@Credit_Numbers[($PokemonGlobal.coins%1000)/100]
@Creditfield3.bitmap=@Credit_Numbers[(($PokemonGlobal.coins%1000)%100)/10]
@Creditfield4.bitmap=@Credit_Numbers[(($PokemonGlobal.coins%1000)%100)%10]
#==========================================================
#Payout update
#==========================================================
@Payoutfield1.bitmap=@Credit_Numbers[@Payout/1000]
@Payoutfield2.bitmap=@Credit_Numbers[(@Payout%1000)/100]
@Payoutfield3.bitmap=@Credit_Numbers[((@Payout%1000)%100)/10]
@Payoutfield4.bitmap=@Credit_Numbers[((@Payout%1000)%100)%10]
#=================================================
#Slots run
#=================================================
if @GameActive&&(@FrameCount%2)==0
if @Slot1.active
@Slot1.run
end#of if
if @Slot2.active
@Slot2.run
end#of if
if @Slot3.active
@Slot3.run
end#of if
end#of if @GameActive
end#of Method

#=================================
#Payout Check and Pikachu Bonus
#=================================
def boost
if @bolts<15
@bolts+=1
end
boltGraphics
end

def boltGraphics
@sprites={}
@sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height)
x=48
overlay=@sprites["overlay"].bitmap
overlay.clear
boltPositions=[]
for i in 0...16
if @bolts>=i
boltPositions[boltPositions.length]=[
"Graphics/Pictures/bolts",x,34,i*16,0,16,16]
end
x+=16
end
pbDrawImagePositions(overlay,boltPositions)
Graphics.update
end

def evaluate
boltGraphics
@evaluated=true
@FrameCount=0
@Payout=0
@Line1=[@Slot1.MidVal,@Slot2.MidVal,@Slot3.MidVal]
@Line2a=[@Slot1.TopVal,@Slot2.TopVal,@Slot3.TopVal]
@Line2b=[@Slot1.DownVal,@Slot2.DownVal,@Slot3.DownVal]
@Line3a=[@Slot1.TopVal,@Slot2.MidVal,@Slot3.DownVal]
@Line3b=[@Slot1.DownVal,@Slot2.MidVal,@Slot3.TopVal]
@usedcoins=0
#Payout Check Line 1
@Replay=false
case @Line1
when @RedSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line1Flash=true
when @BlueSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line1Flash=true
when @SmallRedBonus
@Payout=@Payout+90
@RegBonus=true
@Line1Flash=true
when @SmallBlueBonus
@Payout=@Payout+90
@RegBonus=true
@Line1Flash=true
when @BigPokeballWin
@Payout=@Payout+4
@Line1Flash=true
when @AzurillWin
@Payout=@Payout+12
@Line1Flash=true
when @PikachuWin
@Payout=@Payout+3
boost
@Line1Flash=true
when @LotadWin
@Payout=@Payout+6
@Line1Flash=true
when @ReplayWin
@Replay=true
@Line1Flash=true
else
if @PokeballWin==[@Line1[0],@Line1[1]]
@Payout=@Payout+2
@Line1Flash=true
end
end
#Payout Check Line 2
if @Line2_Active
case @Line2a
when @RedSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line2aFlash=true
when @BlueSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line2aFlash=true
when @SmallRedBonus
@Payout=@Payout+90
@RegBonus=true
@Line2aFlash=true
when @SmallBlueBonus
@Payout=@Payout+90
@RegBonus=true
@Line2aFlash=true
when @BigPokeballWin
@Payout=@Payout+4
@Line2aFlash=true
when @AzurillWin
@Payout=@Payout+12
@Line2aFlash=true
when @PikachuWin
@Payout=@Payout+3
boost
@Line2aFlash=true
when @LotadWin
@Payout=@Payout+6
@Line2aFlash=true
when @ReplayWin
@Replay=true
@Line2aFlash=true
else
if @PokeballWin==[@Line2a[0],@Line2a[1]]
@Payout=@Payout+2
@Line2aFlash=true
end
end

case @Line2b
when @RedSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line2bFlash=true
when @BlueSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line2bFlash=true
when @SmallRedBonus
@Payout=@Payout+90
@RegBonus=true
@Line2bFlash=true
when @SmallBlueBonus
@Payout=@Payout+90
@RegBonus=true
@Line2bFlash=true
when @BigPokeballWin
@Payout=@Payout+4
@Line2bFlash=true
when @AzurillWin
@Payout=@Payout+12
@Line2bFlash=true
when @PikachuWin
@Payout=@Payout+3
boost
@Line2bFlash=true
when @LotadWin
@Payout=@Payout+6
@Line2bFlash=true
when @ReplayWin
@Replay=true
@Line2bFlash=true
else
if @PokeballWin==[@Line2b[0],@Line2b[1]]
@Payout=@Payout+2
@Line2bFlash=true
end
end
end
#Payout Check Line 3
if @Line3_Active
case @Line3a
when @RedSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line3aFlash=true
when @BlueSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line3aFlash=true
when @SmallRedBonus
@Payout=@Payout+90
@RegBonus=true
@Line3aFlash=true
when @SmallBlueBonus
@Payout=@Payout+90
@RegBonus=true
@Line3aFlash=true
when @BigPokeballWin
@Payout=@Payout+4
@Line3aFlash=true
when @AzurillWin
@Payout=@Payout+12
@Line3aFlash=true
when @PikachuWin
@Payout=@Payout+3
boost
@Line3aFlash=true
when @LotadWin
@Payout=@Payout+6
@Line3aFlash=true
when @ReplayWin
@Replay=true
@Line3aFlash=true
else
if @PokeballWin==[@Line3a[0],@Line3a[1]]
@Payout=@Payout+2
@Line3aFlash=true
end
end

case @Line3b
when @RedSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line3bFlash=true
when @BlueSevenWin
@Payout=@Payout+300
@BigBonus=true
@Line3bFlash=true
when @SmallRedBonus
@Payout=@Payout+90
@RegBonus=true
@Line3bFlash=true
when @SmallBlueBonus
@Payout=@Payout+90
@RegBonus=true
@Line3bFlash=true
when @BigPokeballWin
@Payout=@Payout+4
@Line3bFlash=true
when @AzurillWin
@Payout=@Payout+12
@Line3bFlash=true
when @PikachuWin
@Payout=@Payout+3
boost
@Line3bFlash=true
when @LotadWin
@Payout=@Payout+6
@Line3bFlash=true
when @ReplayWin
@Replay=true
@Line3bFlash=true
else
if @PokeballWin==[@Line3b[0],@Line3b[1]]
@Payout=@Payout+2
@Line3bFlash=true
end
end
end
@Win= (@Payout>0)||(@Replay)
if @BigBonus||@RegBonus
pbMEPlay("SlotsBigWin")
elsif @Win
pbMEPlay("SlotsWin")
end
end
end

class Scene_Slots_Help
def initialize(usedcoins,content1,content2,content3,bolts)
#Parameters to pass variables (when returning to Scene_Slots)
@usedcoins=usedcoins
@content1=content1
@content2=content2
@content3=content3
@bolts=bolts
#Numbers
@Credit0=RPG::Cache.picture("0")
@Credit1=RPG::Cache.picture("1")
@Credit2=RPG::Cache.picture("2")
@Credit3=RPG::Cache.picture("3")
@Credit4=RPG::Cache.picture("4")
@Credit5=RPG::Cache.picture("5")
@Credit6=RPG::Cache.picture("6")
@Credit7=RPG::Cache.picture("7")
@Credit8=RPG::Cache.picture("8")
@Credit9=RPG::Cache.picture("9")
@Credit_Numbers=[@Credit0,@Credit1,@Credit2,@Credit3,@Credit4,@Credit5,@Credit6,
@Credit7,@Credit8,@Credit9]
end

def main
#Background
@Background=Sprite.new
@Background.bitmap=RPG::Cache.picture("Slots Info.png")
#Credits field
@Creditfield1=Sprite.new
@Creditfield1.x=358
@Creditfield1.y=36
@Creditfield2=Sprite.new
@Creditfield2.x=372
@Creditfield2.y=36
@Creditfield3=Sprite.new
@Creditfield3.x=386
@Creditfield3.y=36
@Creditfield4=Sprite.new
@Creditfield4.x=400
@Creditfield4.y=36

Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene!=self
break
end
end
Graphics.freeze
@Background.dispose
@Creditfield1.dispose
@Creditfield2.dispose
@Creditfield3.dispose
@Creditfield4.dispose
end

def update
if Input.trigger?(Input::CTRL)
$scene=Scene_Slots.new(@usedcoins,@content1,@content2,@content3,@bolts)
end
if Input.trigger?(Input::B)
#Exit the game; returns coins that were input but not used
$PokemonGlobal.coins=$PokemonGlobal.coins+@usedcoins
$scene=Scene_Map.new
end
#Credit field update
@Creditfield1.bitmap=@Credit_Numbers[$PokemonGlobal.coins/1000]
@Creditfield2.bitmap=@Credit_Numbers[($PokemonGlobal.coins%1000)/100]
@Creditfield3.bitmap=@Credit_Numbers[(($PokemonGlobal.coins%1000)%100)/10]
@Creditfield4.bitmap=@Credit_Numbers[(($PokemonGlobal.coins%1000)%100)%10]
end
end

class Slot
attr_accessor :TopVal
attr_accessor :MidVal
attr_accessor :DownVal
attr_accessor :active
def initialize(x, topValue=nil,midValue=nil, downValue=nil)
#Slot images
@Pokeball_Down=RPG::Cache.picture("Pokeballs Bottom")
@Pokeball_Middle=RPG::Cache.picture("Pokeballs Middle")
@Pokeball_Top=RPG::Cache.picture("Pokeballs Top")
@AzurillDown=RPG::Cache.picture("Azurill Bottom")
@AzurillMiddle=RPG::Cache.picture("Azurill Middle")
@AzurillTop=RPG::Cache.picture("Azurill Top")
@PikachuDown=RPG::Cache.picture("Pikachu Bottom")
@PikachuMiddle=RPG::Cache.picture("Pikachu Middle")
@PikachuTop=RPG::Cache.picture("Pikachu Top")
@BlueSeven_Top=RPG::Cache.picture("Blue Seven Top")
@BlueSeven_Middle=RPG::Cache.picture("Blue Seven Middle")
@BlueSeven_Down=RPG::Cache.picture("Blue Seven Bottom")
@Lotad_Down=RPG::Cache.picture("Lotad Bottom")
@Lotad_Middle=RPG::Cache.picture("Lotad Middle")
@Lotad_Top=RPG::Cache.picture("Lotad Top")
@RedSeven_Down=RPG::Cache.picture("Red Seven Bottom")
@RedSeven_Middle=RPG::Cache.picture("Red Seven Middle")
@RedSeven_Top=RPG::Cache.picture("Red Seven Top")
@Replay_Down=RPG::Cache.picture("Replay Bottom")
@Replay_Middle=RPG::Cache.picture("Replay Middle")
@Replay_Top=RPG::Cache.picture("Replay Top")
#Y Coordinates of the images
@y1=78
@y2=127
@y3=176
#Image Position
@Top=Sprite.new
@Top.x=x
@Top.y=@y1
@Middle=Sprite.new
@Middle.x=x
@Middle.y=@y2
@Down=Sprite.new
@Down.x=x
@Down.y=@y3
#Rarity of slot elements is determined here. The more the number appears, the
#more common that element will be. Note that 1 (the Red 7) only occurs once
#and is rare, but 6 (the Pokeballs) occurs 4 times, being very common.
#Newly added elements must be placed here to appear.
#SlotInhalt set (1= Red 7, 2= Blue 7, 3= Replay, 4= Azurill, 5= Lotad,
#6= Pokeballs, 7= Pikachu)
@SlotInhalt=[1,6,6,4,3,7,4,5,2,5,6,4,5,7]
#@SlotInhalt=[1,1,1,1,1,1]# this is for testing the Big Bonus
#@SlotInhalt=[7,7,7,7,7,7]# this is for testing reel time, and the lighting bolts
#If the values are passed to the slots via parameters, use this
#Otherwise, choose randomly
if topValue!=nil
self.TopVal=topValue
self.MidVal=midValue
self.DownVal=downValue
else
self.setValues
end
#Active to false
self.active=false
#Graphs represent
@i=0
@j=1
@k=2
update
end

def setValues
@RndNr=rand(@SlotInhalt.size)
self.TopVal=@SlotInhalt[@RndNr]
if @RndNr==(@SlotInhalt.size-1)
@RndNr=0
else
@RndNr=@RndNr+1
end
self.MidVal=@SlotInhalt[@RndNr]
if @RndNr==(@SlotInhalt.size-1)
@RndNr=0
else
@RndNr=@RndNr+1
end
self.DownVal=@SlotInhalt[@RndNr]
end

def update
case self.TopVal
when 1
@Top.bitmap=@RedSeven_Top
when 2
@Top.bitmap=@BlueSeven_Top
when 3
@Top.bitmap=@Replay_Top
when 4
@Top.bitmap=@AzurillTop
when 5
@Top.bitmap=@Lotad_Top
when 6
@Top.bitmap=@Pokeball_Top
when 7
@Top.bitmap=@PikachuTop
end
case self.MidVal
when 1
@Middle.bitmap=@RedSeven_Middle
when 2
@Middle.bitmap=@BlueSeven_Middle
when 3
@Middle.bitmap=@Replay_Middle
when 4
@Middle.bitmap=@AzurillMiddle
when 5
@Middle.bitmap=@Lotad_Middle
when 6
@Middle.bitmap=@Pokeball_Middle
when 7
@Middle.bitmap=@PikachuMiddle
end
case self.DownVal
when 1
@Down.bitmap=@RedSeven_Down
when 2
@Down.bitmap=@BlueSeven_Down
when 3
@Down.bitmap=@Replay_Down
when 4
@Down.bitmap=@AzurillDown
when 5
@Down.bitmap=@Lotad_Down
when 6
@Down.bitmap=@Pokeball_Down
when 7
@Down.bitmap=@PikachuDown
end
end

def run
self.TopVal=@SlotInhalt[@i]
self.MidVal=@SlotInhalt[@j]
self.DownVal=@SlotInhalt[@k]
@i=@i+1
@j=@j+1
@k=@k+1
if @i==@SlotInhalt.size-1
@i=0
end
if @j==@SlotInhalt.size-1
@j=0
end
if @k==@SlotInhalt.size-1
@k=0
end
update
end

def dispose
@Top.dispose
@Middle.dispose
@Down.dispose
end

endTo call the script, use $scene=Scene_Slots.new.
The global variable for coins is already implemented in Essentials, so I simply adapted the script to work with it. To add coins to the players coin bag, use $PokemonGlobal.coins+=XXXX.

You must download the images and audio (http://www.megaupload.com/?d=B6DBHATK) and copy/paste the contents into the Graphics/Pictures and Audio/ME or Audio/SE directories (indicated by the folder names for audio).

If you don't like the speed of any of the animations (such as the flashing lines or the win animation), look for the portion of code that corresponds to the animation and change the frame numbers. It'll be under a "case @FrameCount" line with several checks for the frame number (such as "when 2" "when 4" etc.). It's best to keep them in a pattern though so that the animation is smooth (i.e. count by 2s, 5s, 10s, etc.).

If you want to implement the Reel Time feature, you have to script in a function that performs a replay several times, and sums the payouts at the end. I was working on it, but lost interest after a few failed attempts. All of the variables necessary to implement it should still be present, and in the appropriate areas. The related code has been commented out, so you can pick up where I left off or try something else. The necessary graphics have also been included for the Pikachu animation, just not formatted and arranged.

The script was initially created by Itachihro, and the original can be found on YouTube by searching for "RPGXP Casino Slots Script." I built the script using his as the core, and added/edited tons of things. Also, I translated the comments and variable names into English to make it easier to understand and modify. Although some of the stuff I named may be odd sounding, since it was off the top of my head.
The graphics were ripped by Guille-kun (the large image, which I broke into the smaller pieces).
The sound effects were ripped by me.

If there are any problems, or if there is anything you don't understand about the script, let me know. And if anyone has the patience to implement the Reel Time feature and the accompanying animation, I'll add it to this and give you appropriate credit for your contribution.

thepsynergist
November 26th, 2010, 11:10 PM
This is amazing, its just what I've been looking for. Only one problem is the extreme lag after a game... Is there a way to fix it? It plays at like 4-6 fps when you lose.

Cilerba
November 26th, 2010, 11:40 PM
This is amazing, its just what I've been looking for. Only one problem is the extreme lag after a game... Is there a way to fix it? It plays at like 4-6 fps when you lose.

The script actually lagged during the game for me. It seemed pretty great, so excellent job, Kitsune. It just lags a bit too much. ):

KitsuneKouta
November 27th, 2010, 05:58 AM
The script actually lagged during the game for me. It seemed pretty great, so excellent job, Kitsune. It just lags a bit too much. ):I had issues with lag off and on too. The problem is with the various things being checked in the main processing area, especially the endgame handler, which checks which endgame animation to display (3 different win animations, the flashing lines and 1 lose animation). It also checks if you have too many coins, or not enough, the payout, replays, etc. I had the lag reduced at one point, but I think it was after adding something that I started having the lag issue. I'll see if I can speed it up a bit.

EDIT: I also forgot a couple of the sound effects that are supposed to be there. I changed the link to the complete version. Also, there wasn't supposed to be an ME after losing, so I updated the code.

thepsynergist
November 27th, 2010, 10:05 AM
I noticed that if you left the map that you were on when you did the scripts, the lag goes away. Maybe if you teleport the player to a blank map when you enter the slot event the lag would be less. Then teleport back when you're done. That still doesn't fix the lag during the slots though...

KitsuneKouta
November 27th, 2010, 11:28 AM
I noticed that if you left the map that you were on when you did the scripts, the lag goes away. Maybe if you teleport the player to a blank map when you enter the slot event the lag would be less. Then teleport back when you're done. That still doesn't fix the lag during the slots though...Do you mean it fixes lag that lingers after you finish playing? I've noticed that most of the problem with lag is because it's doing so much in a row, and hitting the stop button fast makes it a little worse. It's especially bad after winning as it plays a little tune right after the SE for the stop buttons are finishing, while also trying to update the graphics every few frames. Waiting a second or two generally reduces the lag a bit as it has time to finish processing before doing it all over again. Using some well-placed pbWait commands might help, so I'll try it out and see what happens.

thepsynergist
November 27th, 2010, 11:32 AM
That'd be great. You did a really good job importing this to Pokemon Essentials.

KitsuneKouta
November 28th, 2010, 01:57 PM
I haven't quite pinned down the problem yet, but I think I'm on the right track. It doesn't seem to be any action in particular that causes the lag, but rather a time based thing. Every several seconds it suddenly lags, and then corrects itself. So I need to find whatever's being processed at that moment to see if I can fix it.

Another issue is that my computer is a bit above average, so I can't really tell how badly it may lag for others even if it works just fine on mine. Would any of you be able to try it out? Just let the reels run without inputting anything (the reels should be spinning), and see if the lag is on a cycle like I mentioned above. If it lags all the way through, and not on a cycle, then I may have to write a less resource intensive version for computers that aren't as powerful.

zingzags
November 28th, 2010, 03:58 PM
Speechless lol
Looks like you are not one of those people who back down from there word
Good one.

thepsynergist
November 28th, 2010, 04:02 PM
I've tested it and it only begins to lag for me after at least one game is played. If I let the slots do their thing and leave them alone it doesn't lag.

Dragonite Ernston
November 28th, 2010, 04:19 PM
Do you think you can actually analyze the algorithm and create a pseudocode version? Because that would be awesome in determining the algorithms used to play the game.

thepsynergist
November 28th, 2010, 04:23 PM
I can't code at all. :P But I trust KitsuneKouta to come up with something.

KitsuneKouta
November 28th, 2010, 04:51 PM
Speechless lol
Looks like you are not one of those people who back down from there word
Good one.Are you referring to how I mentioned it in my sig a long time ago? I had actually had this sitting around for a while, but I wanted to make it a little better first. Then I ended up putting it off for a couple months and figured I'd post it. I also have the secret base system done, but it is the most user (un)friendly thing I have ever worked with, so I'm not sure if it's worth posting.

@thepsynergist: ok, thanks for letting me know.

@Dragonite Ernston: I suppose I could put one together. I'll try to work on the lag problem first though before my mind wanders and I forget about it.

thepsynergist
November 28th, 2010, 04:55 PM
I can't wait, KitsuneKouta. If you checked out my Pokemon Pyrite thread, you'd notice that I have a slot machine Pokemon. I plan on having him pose as a slot machine in the game corner. With this script, he'll finally make sense.

KitsuneKouta
November 28th, 2010, 05:44 PM
I solved the lag issue. I overlooked a nifty little comment I left for myself when I left off working on it a couple months ago. There's a line that reads "boltGraphics" (a method name), which updates the little lightning bolts that appear if you get 3 pikachus in a row. Since Reel Time is not implemented, it's purely for looks. For whatever reason, I felt it was a good idea to put it in the main loop at the time. I updated the script in the first post. It runs like lightning now.

thepsynergist
November 28th, 2010, 05:48 PM
I told you I had faith in you. :D I'll put this in once I'm done with my final. Thanks a bunch dude. You are so in my credits.

KitsuneKouta
November 28th, 2010, 07:07 PM
I told you I had faith in you. :D I'll put this in once I'm done with my final. Thanks a bunch dude. You are so in my credits.You're welcome. I don't generally like to commit to anything in the event that I forget/lose interest/fail to accomplish it, but I still try to help out wherever I can. That's why I didn't release this sooner: I wasn't sure if I'd have the motivation to follow through.

@Dragonite Ernston: I put together the pseudocode. I don't do it very often, so I'm not sure if it's quite what you're looking for. I tried to indent to make it more readable.initialize variables
define graphics
create sprites
position contents of the 3 reels (contents are read from corresponding variables, which determines the images to use)
transition
update lighting bolt graphics (otherwise the disappear after viewing the info screen)
main Loop
update graphics
update input
update game
add 1 to frame count
check if game is active (reels spinning)
-determines if game has been evaluated
check if player has any coins to keep playing
-return to map if they don't
check if game is active but the slots have been stopped
evaluates game results (if game hasn't been evaluated yet)
update lighting bolt graphics
restore variables to default values (such as payout, frame count, coins input)
determine payout by line, and which lines should flash
Line1
Line2a
Line2b
Line3a
Line3b
determine if the round was a win
play ME depending on type of win
check if round was a win
-if true, display appropriate win animation w/ lines being erased and created (alternating)
-reset frame count
check frame count and payout speed
reduce payout by 1
check if player has max coins
-reduce payout to 0 if true
check if player presses "C"
-if true, increase payout speed
check if payout is 0 (the round is over) and ensure there's not a replay round
check players coins to see if they can continue playing
restore variables do default values
check if payout is 0 and if there IS a replay round
restore variables do default values, except the slots remain active
***an extra check is added that is supposed to work with Reel Time. at present, it's useless code***
if round was not a win:
display lose animation
restore variables to default values
determine contents of slots (3 values per reel)
check if "C" was pressed
-if true, set the first active slot to inactive (false), play an SE, and display an image (for the button)
check if game is active (reels moving)
-if true, increase time variable by 1
-check if a slot is inactive
-check if time variable is greater than or equal to 10
-erase button images and set time variable to 0
check if "CTRL" button was pressed (no coins can be inserted, payout must be 0, and game must be inactive)
-if true, change to slots help scene
check if "DOWN" was pressed (game must be inactive, and coins must be > 0)
Play SE
increase value of inserted coins by 1
decrease players coins by 1
check value of inserted coins
display appropriate line graphics (for the "light up" effect)
set game and slots to active status
set frame count to 0
check if "B" was pressed
-if true, prompt player to end game (return to map and restore any coins that were inserted but not used)
check if "C" was pressed (game must be inactive and inserted coins > 0)
-if true, set game and slots to active status, and set frame count to 0
check the number of inserted coins, and display the corresponding "Insert" animation
check if Reel Time is active and display the corresponding animation
check if game is active, and display the "Stop" animation
update credit field
update payout field
run active slots
####End of game update####
check if scene has changed
-if true, break loop
freeze graphics and delete objects

Dragonite Ernston
November 28th, 2010, 07:18 PM
Alright, now come the questions. What does "the game has been evaluated" mean? I don't understand that terminology.

Also, this is RGSS? (If it is, I am dumb. I thought it was translated ASM.)

KitsuneKouta
November 28th, 2010, 07:43 PM
Alright, now come the questions. What does "the game has been evaluated" mean? I don't understand that terminology.

Also, this is RGSS? (If it is, I am dumb. I thought it was translated ASM.)Maybe you could substitute it with "checked" or "processed," but it basically means that the results of the game (which I interchanged with the term "round" occasionally) have been looked at and the appropriate action taken in response to the results. And it is in fact RGSS; the only thing I translated it from was German.

thepsynergist
November 30th, 2010, 12:34 AM
One minor error in the code I just found out from having fun with the slots, is that when you get a pikachu in the reel, you get a lightning bolt icon. That's fine, but when you exit the slot game, it doesn't remove the picture. It stays there even when you change maps. I'm sure I could remove it with one line of code, but I suck with coding.

KitsuneKouta
November 30th, 2010, 08:47 AM
One minor error in the code I just found out from having fun with the slots, is that when you get a pikachu in the reel, you get a lightning bolt icon. That's fine, but when you exit the slot game, it doesn't remove the picture. It stays there even when you change maps. I'm sure I could remove it with one line of code, but I suck with coding.That's strange. I just tested it out again and I didn't have that problem. Find this portion of code (line 629):
if (Input.trigger?(Input::B))&&!(@GameActive)
if Kernel.pbConfirmMessage("Quit the game?")
$PokemonGlobal.coins=$PokemonGlobal.coins+@usedcoins
$scene=Scene_Map.new
end
endand modify it to look like this:
if (Input.trigger?(Input::B))&&!(@GameActive)
if Kernel.pbConfirmMessage("Quit the game?")
$PokemonGlobal.coins=$PokemonGlobal.coins+@usedcoins
@bolts=0
boltGraphics
$scene=Scene_Map.new
end
endThat should add a redundant measure to erase the bolts before changing the scene.

zingzags
November 30th, 2010, 09:02 AM
Tested it the yellow bolts stay with you. even with the mini change

thepsynergist
November 30th, 2010, 11:53 AM
And you only see it when the screen is black on the left side. The game covers it up. Kinda like its on Layer 0.

KitsuneKouta
November 30th, 2010, 02:51 PM
Sorry, I forgot that since I set it up the same way as the badge display on the trainer card you have to use -1 instead of 0. So @bolts=-1 should fix it. I'll update the script in the first post too.

Dragonite Ernston
December 5th, 2010, 09:42 PM
Also, does this script follow the Japanese slot machine style of the games, or is it entirely a script from scratch?

Because the reels slip in the actual games, and I can't find any code in your pseudocode that accounts for these slipping reels.

KitsuneKouta
December 6th, 2010, 10:23 AM
Also, does this script follow the Japanese slot machine style of the games, or is it entirely a script from scratch?

Because the reels slip in the actual games, and I can't find any code in your pseudocode that accounts for these slipping reels.The original script was from scratch, and I heavily modified it. There was no reel slipping in the original, so I didn't even think to put it in. I'm not to keen on how to implement it, but if I get some time I'll see if I can do something like that.