The Daily Click ::. Forums ::. Klik Coding Help ::. Dice rolling code
 

Post Reply  Post Oekaki 
 

Posted By Message

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
8th June, 2007 at 00:08:53 -

Simple thing... anyone ever played dungeons & dragons? The game uses dice, some 20-sided, 4-sided, 6-sided, whatever.

Now let's say I want to make my game produce a random amount of monsters.


First, I want something to be able to generate a dice roll for me. For example, I want it to roll five 4-sided dice. It's not as easy as (Random(4)+1)*5, that'll flaw the probability. It has to be (Random(4)+1)+(Random(4)+1)+(Random(4)+1)+(Random(4)+1)+(Random(4)+1)

The problem with that is I sometimes need to do three 4-sided dice or sometimes twenty dice. So I can't use a fix code and I can't multiply it. I could loop some "add Random()" events together N times but for some reason that part's buggy.

Let's say the answer is 13. That means 13 monsters.

Now I want the computer to calculate 13 percentile rolls, for example, there's a 5% of that creature being a goblin, 6% of it being an orc, 21% being a slime, etc. The trick there is that it can't overlap (e.g. it being possible to be a goblin and an orc).

Finally... the thing is I'll be using dozens of these events, so they should be easy enough to edit and refer to and stuff, not big ugly code I have to copy and paste for every attack.



Yeah, most of you would probably say "do a Random+1 then fatloop u n00b", but there seems to be some problem during the fatlooping. There are easy ways, but most of those would either spiral out of control on a bug, are unable to handle more than one dice-rolling request at once, or are just big and ugly.

So anyone who has the skills and devotion to give me clean, functional, non-buggy code can have 5 dc points or a custom rating . BTW, might take me a while for me to notice, my last day of unlimited internet access, lol.

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
8th June, 2007 at 01:44:48 -

Looping would be the only way to accomplish it. And as you pointed out, the MMF/TGF random number seeding gives very UNRandom results when combined with fast loop. In my random dungeon generator, I actually use this to the advantage to create patterns. However, your problem requires a custom random number seeder. Basically, in order to accomplish this, you need to use a random number generating extension. You can find some in the archives. This means you'll have to use other things to seed the #'s besides the date/time, since thats the same for an entire loop.

I mostly stick to TGF, but I think this is what you want: http://www.clickteam.info/extensions/extview.php?id=216
Also, the Cellosoft ones a bit more popular: http://www.clickteam.info/extensions/extview.php?id=51

So yeah, if you use that you can use the fast looping to accomplish your dice rolls, like normal. I think the problems with the way MMF seeds its randoms- it probably uses the date/time in combination with the event #, which are both the same for loops. Which is of course silly.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
8th June, 2007 at 01:46:07 -

Flexible engine, just pass in numbers and the engine puts out numbers and even monsters, I think I answered your questions right. Tell me otherwise.

http://www.ectoprods.com/uploads/dicerollmuz.zip

Edit: Er, and if you want to use that extension you can, they'll go well together.

Image Edited by the Author.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
8th June, 2007 at 02:27:17 -

Yeah, I used a RNG extension that came with one of the MMF2 bonus packs, MMF's randomness was way off.

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

BROO



Registered
  31/10/2002
Points
  595
8th June, 2007 at 16:04:50 -

I've made dice roll with Fast Function object. I've just made recurrential function and made a trick with one number value to store both summed dice rolls and amount of rolls more to do. I'm to lazy to find out mathematical formula. :---(.

http://www.republika.pl/tgf_rozsz/ffunct.gam


This needs Fast Function Object
http://www.clickteam.info/extensions/extview.php?id=42

I've done two methods in two events groups. One of the events group's deactived - you can turn on one of them and turn off another and compare the differences. This example makes 15*4*100 = 6000 4-sided dice rolls and gives FPS like this:
- 38 with using Multiply
- 33 with using MOD

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
9th June, 2007 at 14:20:35 -

Crap, using VB6 it's easy to simulate D&D dice for damage as I've done it in the past:

Weapon Examples & Variable Values:

Long Sword 1D8 ( D1 = 1, D2 = 8 )
Broad Sword 2D4 ( D1 = 2, D2 = 4 )
Hammer 1D4+1 ( D1 = 1, D2 = 4, D3 = 1 )

D1 = How Many Dice
D2 = The type of Dice ( 4,6,10,12,20-sided )
D3 = Any bonus modifier ( which could also be for a magic weapon, i.e. Dagger+2 )

* * *

TotDamage = 0
For X = 1 to D1
TotDamage = TotDamage + Int(D2*rnd(1)+1)
Next X
TotDamage = TotDamage + D3

* * *

That's the problem with me and Click though- things that are easy to do normally are not as easy for me to figure out how to do them using MMF or whatever, but I hope this helps you with your random dice roll generator somehow.



Image Edited by the Author.

Image Edited by the Author.

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!
   

Post Reply



 



Advertisement

Worth A Click