dice rolling?
Anonymous
13 Aug 2003, 19:36Is there a way that you could code somethign to roll a dice? I;m looking for a random way to determine if something wins or loses a battle. Do any of you know if there's a way to do this? It doesn't have to be dice.
I think Im Dead
13 Aug 2003, 20:48For say a standard six-sided the code would be
$rand(1;6)$
$rand(1;10)$ - ten sided
$rand(whatever;whatever)$ - you get the picture
to do something traditional D&D style you'd have to get a little elaborate but it's still simplistic.
$rand(1;6)$
$rand(1;10)$ - ten sided
$rand(whatever;whatever)$ - you get the picture
to do something traditional D&D style you'd have to get a little elaborate but it's still simplistic.
Anonymous
13 Aug 2003, 21:02Okay. Is there a way that I could set something to happen on different rolls?
I think Im Dead
13 Aug 2003, 21:45ok I'll try and explain this using qdk since I'm assuming you are using it.
Hope that clears things up and provides you with enough of an idea to use random "dice rolls" and such in your games. If you need more help or need a coding example, respond asking and I can provide them.
when you're creating your command or whatever that will trigger the dice roll first you'll want to ...
Click the add command button.
Go down to variables, then set a numeric variable.
Call the variable something like diceroll1, in the contents box place something along the lines of $rand(1;6)$ or however high you want the dice to be. click ok.
now click add conditional. in the "if" section click add then select compare to strings or values.
in the string 1 box put %diceroll1% or whatever you previously named the numeric variable.
in the comparison drop down pick how you would like to compare the resulting random number now placed in the %diceroll1% variable. Example: if %diceroll1% is greater than (whatever the enemies armor variable is) or if %diceroll1% is less than (whatever persons luck at dodging) or whatever you want.
in the string 2 box put whatever variable or value you'd like to compare %diceroll1% to however you decided. You can compare strings with the value of an objects property, another string or numeric variable, most anything defined somewhere in the game.
after that click ok.
next on the conditions window go to the "then" area and click edit.
This is where you decide what happens if the prerequisites you set earlier( in the "if" section) are met.
If you want to create an exit out of a room, change an object's property, set another variable, give the player an object, move them somewhere or anything else. Decide what you want to happen if the needs are met then click ok.
If the prerequisites are not met and you would like something to happen indicating they failed or whatnot, check the "else" tick box and then click edit which will no longer be grayed out.
Here you can choose what happens if the needs weren't met using the same conditions and commands prompt as usual.
Hope that clears things up and provides you with enough of an idea to use random "dice rolls" and such in your games. If you need more help or need a coding example, respond asking and I can provide them.
Anonymous
13 Aug 2003, 22:04Okay, thanks.
Anonymous
13 Aug 2003, 23:19Do you know how I could script a command that rolled the dice and then, on a conditional, printed a certain message based on the roll?
I think Im Dead
14 Aug 2003, 01:41Basically the same as above only you'd first select add a command, set a numeric variable "dice" (or whatever) of $rand(1;whatever)$ then select print a message and have the message say, "You rolled a %dice%." and the %dice% part would be replaced with the number.