The Dink Network

Random function: Helpo-pleaso

June 15th 2008, 10:55 AM
wizardg.gif
schnapper
Peasant He/Him Heard Island And Mcdonald Islands
Let us save our effort and just lie down and die. 
Hullo again, well im a bit of a noob when it comes 2 scripting; i was jus wonderin though, can any of youse tell me what to write for a random function ie when dink kills slayer there is a 1 in 15 chance of it leaving a str potion OR when dink walks into screen 37, there is a 3 in 22 chance of their being 1,2 or 3 boncas.
June 15th 2008, 12:17 PM
maidenb.gif
Sharp
Peasant She/Her Finland
 
From the old dinkc reference:

"int random(max, plus_this);
Random(10,1) would return a number between 1 and 10. Random(5,0) would return a number from 0 to 4. Simular to how C does it."

Check out some of the original Dink source files (e.g. s2-wand.c has a lot of randomization going on) for real examples of how to do it.
June 15th 2008, 05:00 PM
dinkdead.gif
In slayer's die procedure:
int &rand = random(15, 1);
if (&rand == 1)
//^doesn't have to be 1, anything up to 15.
{
//make potion
}

Following attached to screen (or a sprite):
void main (void)
{
int &rand = random(22, 1);
if (&rand <= 3)
{
&rand = random(3, 1);
if (&rand >= 2)
{
if (&rand == 3)
{
//create 1 bonca here
}
//create 1 bonca here
}
//create 1 bonca here
}
kill_this_task();
}

I think this is what you meant? So there is a 19 in 22 chance of there being no boncas.

Edit: The line &rand = random(3, 1); is unecessary, take it out if you like.
June 17th 2008, 09:24 AM
wizardg.gif
schnapper
Peasant He/Him Heard Island And Mcdonald Islands
Let us save our effort and just lie down and die. 
alriiight! now we're cookin with slimes. yeah, thanks Sparrowhawk - that was what i was after.