Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Random Variables (https://forums.graalonline.com/forums/showthread.php?t=12324)

nyghtGT 09-20-2001 03:24 AM

Random Variables
 
I am doing some mining type stuff for my server and i got the triggeraction stuff working to destroy rocks and stuff. But for the rocks i figure they could leave things behind sometimes like a little diamond or something. And I need help setting it to pick a random variable. So could some one help me. Like ... say it picks a random number between 1-1000 and if you get a 483 it lays a diamond. Could someone please help me.

Thak2 09-20-2001 03:33 AM

use

i = random(0,999);

then have stuff like
if (i >50&&i<101) {
stuffhere;

nyghtGT 09-20-2001 03:37 AM

kool
 
kool i'll try it thanx ...

Merlin 09-20-2001 03:49 AM

you can do it a lot of ways
this.random = random(1,90);

entravial 09-20-2001 04:14 AM

~AlphaFlame~

Quote:

if (i >50&&i<101) {
It would be much simpler to do...

Quote:

if (i in |50,101|){

nyghtGT 09-21-2001 07:28 AM

ended
 
what i just ended up doing was ....

this.destroy=random(1,1000);
if (this.destroyed=483) {
putnpc diamond.gif,diamond.txt,32,32;
}

I know the ending probably aint right but i am just explaining what i did and dont care if its wrong ...

BocoC 09-21-2001 08:15 PM

I think there is still a bug in random() in where it doesn't get re-randomized if you don't move...

CyanideSR71 09-21-2001 11:44 PM

Quote:

Originally posted by Kaimetsu
Um... The odds of getting 483 from a random(0,1000) are like 100000000000:1. You better have some patient players.
It's fun to tell him why, Kai!

PHP Code:

this.destroy=int(random(1,1000)); 
if (
this.destroyed=483) { 
putnpc diamond.gif,diamond.txt,32,32


By using random, it finds a random real number between the two numbers you've set. That means that muber could be 4.876658756 or any other number like that, making the odds of getting 483 somewhere around infinity to one. What you want is a random integer number, which only allows numbers without decimals. By putting int() in there, the odds around 1 in 1000 once again.


All times are GMT +2. The time now is 08:15 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.