ID:168655
 
I want to make a dice system were there dice apear in the text box when they are rolled; for example when a person is a certain level they will be able to roll up to 11 dice; I want them to show up like this-

d1,d2,d3,d4,d5

like that; how would I make them show up without a bunch of variables.
mob/verb/Dice_Roll()
var/obj/dice/num=new/obj/dice //Make a var equal to the object
num.icon_state="[rand(1,6)]" //Make the var's icon state equal which is a random number between 1 and 6
src<<"You rolled a \icon[num]" //Output the debug message

obj/dice
icon='dice.dmi'


That should give you a hint on how to do it.
In response to Mega fart cannon
thanks but, the question isnt how to make it roll; but how to make all 11 of them to apear...
In response to Lifehunter
I'm guessing what you do is repeat the process
mob/verb/Dice_Roll()
var/obj/dice/num1=new/obj/dice
var/obj/dice/num2=new/obj/dice
...
num1.icon_state="[rand(1,6)]"
num2.icon_state="[rand(1,6)]"
...
src<<"You rolled \icon[num1] \icon[num2] ..."
In response to Mega fart cannon
You need a for loop, I think.
But I am not familuar with that coding out of the loops I use, sorry.
In response to Developous
Im not sure, but I think that a while loop might be a little better here. Give me some time to figure it out, but I think I can help you. Unless someone else beats me to the punch.

Will edit soon.

[Edit]

obj/dice
icon='dice.dmi'

mob
verb
Dice_roll()
var/X = input(src,"How many dice would you like to roll?","Roll",) as null|num
var/Y = 0
if(!X || X <= 0)
src << "Thank you come again."
return 0
else
src << "You roll"
while(X > 0)
var/a = roll("1d6")
Y += a
var/obj/Z = new/obj/dice
Z.icon_state = "[a]"
src << "\icon[Z]"
X--
src << "For a total of [Y] points]"


This will output every dice that you roll, however it does not account for people rolling more than 11 dice. I'll leave that one for you figure out, its pretty simple though should be easy enough. Anywho. The only major drawback that I can see is that this method draws them all on their own line. Mega fart cannons method will display them all on the same line, yet is a little more variable intensive. Some combination of the two would probably be the most effective.

Hope that helps. Let me know if you have any questions.
In response to Madcrackfiend
mob/verb/DiceRoll()
var/list/Dice = new( lvl ) // Initialize it
var/Total
for( var/i = 0; i <= lvl; i++ )
Dice[ i ] = roll( 1, 6 ) // BYOND already has a dice system, so use it!
Total += Dice[ i ]
var/obj/dice/D = new /obj/dice
D.icon_state = "[Dice[ i ]]"
src << "\icon[ D ]"
src << "The total is: [Total]"


You just need to make sure that you have a mob/var named lvl, and that you have a dice object with it's icon pointing at a file with a set of icon_states numbered 1-x.