ID:1797373
 
(See the best response by Avidanimefan.)
Code:
obj
Casino_Items
var
Casinocombo = list()
spinning = 0
inputing = 0
icon = 'ObjsCasino.dmi'
density = TRUE
Spinning
icon_state = "spinning"
Jackpot
icon_state = "Jackpot"
Combinations
a1
icon_state="a1"
a2
icon_state="a2"
a3
icon_state="a3"
b1
icon_state="b1"
b2
icon_state="b2"
b3
icon_state="b3"
c1
icon_state="c1"
c2
icon_state="c2"
c3
icon_state="c3"
Slot_Machine
icon_state = "Machine"
verb
Play(/*Phat T*/)
set src in oview(1)
if(spinning)
usr<<"<font color=gray>This machine is already in use"
return
if(!usr.coins)
usr<<"<font color=gray>You don't have any coins to play with"
return
if(usr.frozen)
usr<<"<font color=gray>You can`t use this while frozen"
return
var/luckynumber = pick(rand(50,300))
var/coin_amount = input("How many coins would you like to enter?\n- Your Coins: [cn(usr.coins)]\n- Max Input: 300\n Lucky Number: [luckynumber] ","Input Coins")as num|null
if(!coin_amount) return
if(inputing) return
if(coin_amount > usr.coins)
usr<<"<font color=gray>You don't have that many coins!"
return
if(coin_amount > 300) return
if(coin_amount <= 0) return
if(spinning)
usr<<"<font color=gray>This machine is already in use"
return 0
usr<<"You bet [coin_amount]"
spinning = 1
usr.frozen = 1
usr.dir = NORTH
usr.coins -= coin_amount
flick("Pull",src)
overlays += new/obj/Casino_Items/Spinning
spawn(30)
switch(rand(1,3))
if(1)
src.overlays += new/obj/Casino_Items/Combinations/a1
Casinocombo += "1"
if(2)
src.overlays += new/obj/Casino_Items/Combinations/a2
Casinocombo += "2"
if(3)
src.overlays += new/obj/Casino_Items/Combinations/a3
Casinocombo += "3"
sleep(6)
switch(rand(1,3))
if(1)
src.overlays += new/obj/Casino_Items/Combinations/b1
Casinocombo += "1"
if(2)
src.overlays += new/obj/Casino_Items/Combinations/b2
Casinocombo += "2"
if(3)
src.overlays += new/obj/Casino_Items/Combinations/b3
Casinocombo += "3"
sleep(6)
switch(rand(1,3))
if(1)
src.overlays += new/obj/Casino_Items/Combinations/c1
Casinocombo += "1"
if(2)
src.overlays += new/obj/Casino_Items/Combinations/c2
Casinocombo += "2"
if(3)
src.overlays += new/obj/Casino_Items/Combinations/c3
Casinocombo += "3"
var/combination
for(var/i in Casinocombo)
combination += "[i]"
if(usr)
if((combination == "111") || (combination == "222") || (combination == "333"))
var/amount
if(coin_amount == luckynumber)
amount = round(coin_amount +(rand(4000,5000)))
if(coin_amount != luckynumber)
amount = round(coin_amount +(rand(1,5)))
usr<<"<font color=yellow>~Jackpot! [amount] coins come tumbling out of the machine!"
usr.coins += amount
else if((combination == "121") || (combination == "131"))
var/amount
if(coin_amount == luckynumber)
amount = round(coin_amount +(rand(4000,2000)))
if(coin_amount != luckynumber)
amount = round(coin_amount +(rand(1,5)))
usr<<"<font color=yellow>~Jackpot! [amount] coins come tumbling out of the machine!"
usr.coins += amount
else if((combination == "212") || (combination == "232"))
var/amount
if(coin_amount == luckynumber)
amount = round(coin_amount +(rand(2000,1000)))
if(coin_amount != luckynumber)
amount = round(coin_amount +(rand(1,5)))
usr<<"<font color=yellow>~Jackpot! [amount] coins come tumbling out of the machine!"
usr.coins += amount
else if((combination == "313") || (combination == "323"))
var/amount
if(coin_amount == luckynumber)
amount = round(coin_amount +(rand(1000,300)))
if(coin_amount != luckynumber)
amount = round(coin_amount +(rand(1,5)))
usr<<"<font color=yellow>~Jackpot! [amount] coins come tumbling out of the machine!"
usr.coins += amount
else
usr<<"<font color=gray>You did not win, better luck next time"





src.overlays += new/obj/Casino_Items/Jackpot
sleep(15)
src.overlays = null
if(usr)
usr.frozen = 0
spinning = 0
combination = null
Casinocombo = list(null)


Problem description:

Is there a way to achive the same goal. I wanted to make so player needs to input a lucky number that is randomly picked. If the player insert lucky number and got jackpot he will get alot more than if he would just insert a random number in.

The code is working but I would really want to avoid switch() proc to search for combination.
Sorry for the bad grammar. Phat T
Best response
This is really huge and unnecessary in my opinion. Try this :

Pick 3 random numbers (or however many random numbers)
Concatenate them together using num2text()
var/list/winning=list()
var/rolls=3//number of rolls
while(rolls>0)
winning+=num2text(rand(0,9))
rolls--
sleep(world.tick_lag)


Then remake the list into a "solid" number.

for(var/i in winning)
.+i

var/winning_seq=text2num(.)//for displaying the number.

To check if the player wins is simple.

To add the lucky number into the mix just randomly get a number from 1-100 (or lower if you wish)
if(.==player_roll)
var/lucky=rand(1,100)
var/amt=1000/player won.
if(lucky==lucky_need)
amt*=1.75//player wins more than they normally would.


Note : This is just to give you an idea of how to do the same thing just a bit more simply.
Thank you. This really helps alot. I will be able to do it hopefully