ID:168332
 
Hello, I am Bamrulez. I would like to know how to code it a lottery game. For example you click on the lottery and it says
pull lever. Then It says like sometimes Wow! you won and sometimes like sorry try again. And if you win you get random amount of money. But also I want it that if you win like 10 times you cant play anymore so there wont be people on all night playing the lottery. If anyone would like to help me please contact me here, aim-nightmaresk8er13, or [email protected]. Thank you.
obj
Lottery_Machine

mob
var
Plays = 0
Money = 0
verb
Play(obj/Lottery_Machine/O in oview(1,src))
if(istype(O,/obj/Lottery_Machine))
if(src.Plays>=10)
src << "Sorry, you have played this to many times."
return
else
var/Rand = rand(1,10)
if(Rand>=9)
var/Rand_Money = rand(1,100)
src << "You win [Rand_Money] money!"
src.Money += Rand_Money
src.Plays ++
In response to Sniper Joe
thank you very much.
In response to Bamrulez
Wait...I forgot something, here.
obj
Lottery_Machine

mob
var
Plays = 0
Money = 0
verb
Play(obj/Lottery_Machine/O in oview(1,src))
if(istype(O,/obj/Lottery_Machine))
if(src.Plays>=10)
src << "Sorry, you have played this to many times."
return
else
var/Rand = rand(1,10)
if(Rand>=9)
var/Rand_Money = rand(1,100)
src << "You win [Rand_Money] money!"
src.Money += Rand_Money
src.Plays ++
else
src << "Sorry you loose."
src.Plays ++
In response to Sniper Joe
Why not do it like this?

mob/var
money=0
SlotMachineAttempts=10

obj/LotteryMachine/verb/Play() //It's a verb - usr is valid.
set src in view(1)
if(!(src in view(1)) return //Possible packet sending.
if(usr.SlotMachineAttempts<=0)
usr << "You have no more attempts left."
return
usr.SlotMachineAttempts--
if(prob(90))
usr << "You win!"
var/MoneyGained=rand(10,100)
usr << "Got [MoneyGained] francs" //Better then dollars!
usr.money+=MoneyGained
else
usr << "I'm afraid you lost. Better luck next time?"
In response to Bamrulez
Sorry, but I have one problem. In the commands theres play. But when i click it noting happens. Do you know wats wrong.
In response to Jp
Just modified Jp's code a little bit.

mob/var
money=0
SlotMachineAttempts=10

obj/LotteryMachine/
DblClick() //Click() is too easy and might be accessed on accident


if(!(src in view(1)) return //Possible packet sending.
if(usr.SlotMachineAttempts<=0)
usr << "You have no more attempts left."
return
usr.SlotMachineAttempts--
if(prob(90))
usr << "You win!"
var/MoneyGained=rand(10,100)
usr << "Got [MoneyGained] Rubles" //"1 Russian ruble = 0.0350609 U.S. dollars" - Google. Also, don't the French use the Euro now?
usr.money+=MoneyGained
else
usr << "I'm afraid you lost. Better luck next time?"
In response to Rockinawsome
I used a verb, not click(). :P.

Although, yes, you are correct. The french use euroes. So archaic french currency must be even better then french currency!
In response to Jp
I changed it to double click merely because I liked it better...Not because you made it a verb. Because, with this code in hand, nothing can stop Bamrulez!