Slot Machine Script

*Created by UUICEO.*

```
Using "RC_Core.rcm"

; Aftermath!

; Date/Time: 1:02:28 AM on 10/17/2009

; By RSQ on UUI

Dim SlotReel$(5,12)

Dim Items$(3)

Dim Line$(3)

Dim SlotCurrent(5)

Function Main()

    SlotNum = 2

Player = Actor()

    NPC = ContextActor()

    PlayerMoney% =
Money(Player)

    BetAmount% = 5

    NumSpots = 3

    If
PlayerMoney% < BetAmount% Then

        Output(Player, "Sorry " +
Name(Player) + " but you don't have " + BetAmount + " coins to play.")

  Return

    EndIf

    If FileSize("Slot" + SlotNum + ".SEM") > 0
Then

        Output(Player, "Sorry but this machine is already in use!")

        Return

    Else

        F = WriteFile("Slot" + SlotNum +
".SEM")

            WriteInt(F, Player)

        CloseFile(F)

DoEvents(500)

        F = ReadFile("Slot" + SlotNum + ".SEM")

  CheckPlayer = ReadInt(F)

        CloseFile(F)

        If CheckPlayer
<> Player Then

            Output(Player, "Sorry but someone beat you
to this machine!")

            Return

        EndIf

    EndIf

  If FileSize("Slot" + SlotNum + "Config.dat") < 6 Then

SlotCurrent(1) = Rand(0, 11) + 1

        SlotCurrent(2) = Rand(0, 11) + 1

        SlotCurrent(3) = Rand(0, 11) + 1

        SlotCurrent(4) =
Rand(0, 11) + 1

        SlotCurrent(5) = Rand(0, 11) + 1

        F =
WriteFile("Slot" + SlotNum + "Config.Dat")

            WriteInt(F,
SlotCurrent(1))

            WriteInt(F, SlotCurrent(2))

WriteInt(F, SlotCurrent(3))

            WriteInt(F, SlotCurrent(4))

        WriteInt(F, SlotCurrent(5))

        CloseFile(F)

    Else

      F = ReadFile("Slot" + SlotNum + "Config.Dat")

SlotCurrent(1) = ReadInt(F)

            SlotCurrent(2) = ReadInt(F)

        SlotCurrent(3) = ReadInt(F)

            SlotCurrent(4) = ReadInt(F)

            SlotCurrent(5) = ReadInt(F)

        CloseFile(F)

EndIf

    BuildReels(NumSpots)

    Repeat

        If PlayerMoney%
< BetAmount% Then

            Output(Player, "Sorry " + Name(Player) + "
but you don't have enough money to play again.")

DeleteFile("Slot" + SlotNum + ".SEM")

            Return

        EndIf

        DW = OpenDialog(Player, NPC, BetAmount% + " Coin Slots")

ShowReels(Player, DW)

        Result = DialogInput(Player, DW, "Play|View
Payouts|Exit", "|")

        If Result = 1 Then

ChangeMoney(Player, -BetAmount%)

            PlayerMoney% = Money(Player)

            SpinTimeReel1 = Rand(1, 5) * 1000

            SpinTimeReel2
= Rand(1, 5) * 1000

            SpinTimeReel3 = Rand(1, 5) * 1000

      SpinTimeReel4 = Rand(1, 5) * 1000

            SpinTimeReel5 = Rand(1,
5) * 1000

            Start = Millisecs()

            While Millisecs()
< Start + SpinTimeReel1

                SpinReelOne(Player, DW)

          CloseDialog(Player, DW)

                DW = OpenDialog(Player,
NPC, BetAmount% + " Coin Slots")

                ShowReels(Player, DW)

              DoEvents(300)

            Wend

            While
Millisecs() < Start + SpinTimeReel1 + SpinTimeReel2

SpinReelTwo(Player, DW)

                CloseDialog(Player, DW)

        DW = OpenDialog(Player, NPC, BetAmount% + " Coin Slots")

    ShowReels(Player, DW)

                DoEvents(300)

            Wend

            While Millisecs() < Start + SpinTimeReel1 + SpinTimeReel2 +
SpinTimeReel3

                SpinReelThree(Player, DW)

CloseDialog(Player, DW)

                DW = OpenDialog(Player, NPC,
BetAmount% + " Coin Slots")

                ShowReels(Player, DW)

          DoEvents(300)

            Wend

            While Millisecs()
< Start + SpinTimeReel1 + SpinTimeReel2 + SpinTimeReel3 + SpinTimeReel4

              SpinReelFour(Player, DW)

                CloseDialog(Player,
DW)

                DW = OpenDialog(Player, NPC, BetAmount% + " Coin Slots")

                ShowReels(Player, DW)

                DoEvents(300)

            Wend

            While Millisecs() < Start +
SpinTimeReel1 + SpinTimeReel2 + SpinTimeReel3 + SpinTimeReel4 + SpinTimeReel5

                SpinReelFive(Player, DW)

CloseDialog(Player, DW)

                DW = OpenDialog(Player, NPC,
BetAmount% + " Coin Slots")

                ShowReels(Player, DW)

          DoEvents(300)

            Wend

            Win% =
CheckWinner%(NumSpots)

            If Win% > 0 Then

DialogOutput(Player, DW, "")

                DialogOutput(Player, DW, "You
won " + (Win% * BetAmount%))

                ChangeMoney(Player, Win% *
BetAmount%)

                DialogInput(Player, DW, "Continue.", "|")

          Else

                DialogOutput(Player, DW, "")

    DialogOutput(Player, DW, "You lost. ")

DialogInput(Player, DW, "Continue.", "|")

            EndIf

ElseIf Result = 2

                CloseDialog(Player, DW)

      DW = OpenDialog(Player, NPC, BetAmount% + " Coin Slots")

  DialogOutput(Player, DW, "Payouts are the following")

DialogOutput(Player, DW, "=========================")

DialogOutput(Player, DW, Chr(198) + " " + Chr(198) + " " + Chr(198) + " = 50 x
Bet")

                DialogOutput(Player, DW, Chr(230) + " " + Chr(230) + "
" + Chr(230) + " = 50 x Bet")

                DialogOutput(Player, DW,
"=========================")

                DialogInput(Player, DW,
"Continue.", "|")

                CloseDialog(Player, DW)

        Else

            CloseDialog(Player, DW)

            F = WriteFile("Slot"
+ SlotNum + "Config.Dat")

                WriteInt(F, SlotCurrent(1))

              WriteInt(F, SlotCurrent(2))

                WriteInt(F,
SlotCurrent(3))

                WriteInt(F, SlotCurrent(4))

    WriteInt(F, SlotCurrent(5))

            CloseFile(F)

DeleteFile("Slot" + SlotNum + ".SEM")

            Return

        EndIf

        CloseDialog(Player, DW)

        F = WriteFile("Slot" + SlotNum +
"Config.Dat")

            WriteInt(F, SlotCurrent(1))

WriteInt(F, SlotCurrent(2))

            WriteInt(F, SlotCurrent(3))

        WriteInt(F, SlotCurrent(4))

            WriteInt(F, SlotCurrent(5))

        CloseFile(F)

    Forever

End Function

Function SpinReelFive(Player, DW)

    SlotCurrent(5) =
SlotCurrent(5) + 1

        If SlotCurrent(5) > 12 Then

SlotCurrent(5) = 1

        EndIf

End Function

Function
SpinReelFour(Player, DW)

    SlotCurrent(4) = SlotCurrent(4) + 1

SlotCurrent(5) = SlotCurrent(5) + 1

    For i = 4 to 5

        If
SlotCurrent(i) > 12 Then

            SlotCurrent(i) = 1

        EndIf

    Next

End Function

Function SpinReelThree(Player, DW)

    SlotCurrent(3) = SlotCurrent(3) + 1

    SlotCurrent(4) =
SlotCurrent(4) + 1

    SlotCurrent(5) = SlotCurrent(5) + 1

        For i
= 3 to 5

            If SlotCurrent(i) > 12 Then

SlotCurrent(i) = 1

            EndIf

        Next

End
Function

Function SpinReelTwo(Player, DW)

    SlotCurrent(2) =
SlotCurrent(2) + 1

    SlotCurrent(3) = SlotCurrent(3) + 1

SlotCurrent(4) = SlotCurrent(4) + 1

    SlotCurrent(5) = SlotCurrent(5) + 1

        For i = 2 to 5

            If SlotCurrent(i) > 12 Then

              SlotCurrent(i) = 1

            EndIf

        Next

End Function

Function SpinReelOne(Player, DW)

SlotCurrent(1) = SlotCurrent(1) + 1

    SlotCurrent(2) = SlotCurrent(2) + 1

    SlotCurrent(3) = SlotCurrent(3) + 1

    SlotCurrent(4) =
SlotCurrent(4) + 1

    SlotCurrent(5) = SlotCurrent(5) + 1

        For i
= 1 to 5

            If SlotCurrent(i) > 12 Then

SlotCurrent(i) = 1

            EndIf

        Next

End
Function

Function BuildReels(NumSpots)

    Items$(1) = Chr(32) ;
NADA

    Items$(2) = Chr(198)

    Items$(3) = Chr(230)

    fh =
ReadFile("BarBell_Setup.dat")

        While Not EoF(fh)

Counter = Counter + 1

            MyData$ = ReadLine(fh)

            For
h = 1 to 5

                SlotReel$(h, Counter) = Items$(Int(Split(MyData$,
h, ",")))

            Next

        Wend

    CloseFile(fh)

Return

End Function

Function ShowReels(Player, DW)

  Line$(1) = " " : Line$(2) = ">" : Line$(3) = " "

    For i = 1 To 5

        If SlotCurrent(i) = 1 Then

            Line$(1) = Line$(1) + " "
+ SlotReel$(i, 12)

        Else

            Line$(1) = Line$(1) + " " +
SlotReel$(i, SlotCurrent(i) - 1)

        EndIf

        Line$(2) =
Line$(2) + " " + SlotReel$(i, SlotCurrent(i))

        If SlotCurrent(i) = 12
Then

            Line$(3) = Line$(3) + " " + SlotReel$(i, 1)

Else

            Line$(3) = Line$(3) + " " + SlotReel$(i, SlotCurrent(i) +

        EndIf

    Next

    Line$(1) = Line$(1) + " "

Line$(2) = Line$(2) + " <"

    Line$(3) = Line$(3) + " "

    For i =
1 To 3

        DialogOutput(Player, DW, Line$(i))

    Next

Return

End Function

Function CheckWinner%(NumSpots)

    If SlotReel$(1, SlotCurrent(1)) <> Items$(1)

        If
SlotReel$(1, SlotCurrent(1)) = SlotReel$(2, SlotCurrent(2)) Then

If SlotReel$(2, SlotCurrent(2)) = SlotReel$(3, SlotCurrent(3)) Then

        Winner = 1

            EndIf

        EndIf

        If Winner
= 1 Then

            If SlotReel$(1,SlotCurrent(1)) = Items$(2) Then

            Multiply = 15

            ElseIf SlotReel$(1,SlotCurrent(1)) =
Items$(3) Then

                Multiply = 10

            EndIf

      Return(Multiply)

        EndIf

    EndIf

    Return(0)

End Function

```