PDA

View Full Version : Random Scripts


sam_is_me
05-21-2007, 06:46 PM
So, since I have to do this offline, its in gs1. I need to figure out how to put a random script, instead of numbers, into names. heres what I have so far:

if(playerchats && strequals(#c,:choose)){
setcharprop #c,var(int(random(1,5)));
sleep1;
message ;
}


If that's wrong, sorry, I'm trying to remember what I have, and GraalEditor isnt working at the moment, but yeah, i have a working random number script tiggered by the player saying :choose..

But how do I assign numbers to NAMES, do I use flags, or what...
:]
thanks

DustyPorViva
05-21-2007, 08:49 PM
if (playerchats && strequals(#c,:choose)) {
tokenize "Hello World!" "Boo ya!" "Whoop whoop." ":D";
setplayerprop #c,#t(int(random(0,tokenscount)));
}

Deadly_Killer
05-21-2007, 09:08 PM
You should not overload your event-statements

if (playerchats)
{
if (strequals(#c,:choose))
{
// etc
}
}

DustyPorViva
05-21-2007, 09:12 PM
You say it with such enthusiasm as though he's going to break something. It's preference really, and as they're highly related, I don't see the problem.

Deadly_Killer
05-21-2007, 09:21 PM
http://forums.graal2001.com/forums/showthread.php?t=46557

DustyPorViva
05-21-2007, 09:42 PM
Funny you should post that:
"Similarly to rule three, do not combine unrelated conditional statements. Instead of writing shambling messes like this:"

sam_is_me
05-22-2007, 05:36 AM
What does the 0,Tokenscount
do?
I dont know what they stand for..
Everything else I get.

DustyPorViva
05-22-2007, 05:55 AM
That would be the random statement, getting a random chunk of text. 0 would be the minimum, and tokenscount would be the max(tokenscount is the number of tokens when using tokenize).

Rapidwolve
05-22-2007, 07:03 AM
What does the 0,Tokenscount
do?
I dont know what they stand for..
Everything else I get.

0, tokenscount.

Heres a tip, you must ALWAYS pay attention to comma's (unless they are wrapped in quotes)

Deadly_Killer
05-22-2007, 07:08 AM
Aren't you supposed to do tokenscount + 1? ( random shouldn't pick the highest number)

Or does tokenscount not start with 0?

sam_is_me
05-22-2007, 06:35 PM
Oh, I get it.
Couldn't you use
tokenscount,tokenscount
though?

DustyPorViva
05-22-2007, 06:57 PM
tokenscount doesn't start with 0, because it's giving you the actual number of tokens, so if you have four words, it will return 4.
And tokenscount,tokenscount wouldn't work because it'd always pick the last option for text. You used the same method in your script as well. I want to pick between the first text, and the last, randomly. 0-tokenscount means it will randomly pick between the first token and the last.

zokemon
05-22-2007, 07:00 PM
Oh, I get it.
Couldn't you use
tokenscount,tokenscount
though?

Thats like saying random(1, 1)
As stated, the 0 is the minimum meaning it is the lowest possible number to be rolled.
tokenscount is the maximum meaning it is the highest number (actually, random never "reaches" the highest number, it just comes close).

DustyPorViva
05-22-2007, 07:07 PM
(actually, random never "reaches" the highest number, it just comes close).
I know, sucks :/

zokemon
05-22-2007, 07:10 PM
I know, sucks :/

I find that to be a good thing when you are dealing with intergers. There used to be a glitch where it could possibly reach the maximum value which screwed up alot of random intergers.

DustyPorViva
05-22-2007, 07:18 PM
Well I suppose it's good as of now because so many scripts use random accustom to that, but I find it dumb that I have to do int(random(0,max+1)) just to have it possible to actually reach the highest value.