OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Messiah on 06 Sep 2002, 23:21:25
-
how, can i make a script generate a random number and then make that number the value of a variable, so then i can check what that number is and then exec different parts of the script.
and, could u make it so that in the array u exec, that u can specify how many different number there can be so if you type:
[8, man1] exec "somescript.sqs"
then the possible random numbers are from 1-8
cheers
:thumbsup:
-
Well if you used the example you gave then in the script you would put:
Randomnum = random (_this select 0)
Then the variable Randomnum would be a random number between 0 and 8.
To use it do:
? Randomnum <1:Code
? Randomnum <2:Code
? Randomnum <3:Code
? Randomnum <4:Code
? Randomnum <5:Code
? Randomnum <6:Code
? Randomnum <7:Code
? Randomnum <8:Code
Must be in that order!!!
I think thats what you want. :-\
8)PEACE
-
ummmm, not sure...
will that generate a random number? so from the numbers 1-8 will it select one a random? The idea of adding an 8 is because i want to select how many random events can happen.... although it doesnt matter.
sorry, seems like you are working on my mission more than i am ;)
-
Just one reminder: random does not create integer values, so you have to make an integer value of it first. To do that you could try something like this:
_Random = _Random - (_Random % 1)
The (_Random % 1) wil subtract 1 from _Random as long as it's possible (i.e. as long as _Random is bigger than 1). So if your random number would be 4.63, _Random % 1 would be 0.63. When you subtract this from _Random you'll get 4.63 - 0.63 = 4
Get it?
-
Lol, I've got 2 windows up for your 2 Q's.
By adding this to the "Somescript" then it takes the first argument (8) and produces a random number from 0-8. It could be 1.373 though so you have to check the number in a certain order, so it checks the for a number lower than 1 then 2 then 3 and so on...
if you were wanting more than 8 events then just add them and change the 8 to 10 for example when you are calling the script.
8)PEACE
-
Yes, Demoniac, but by counting 1 then 2 then 3 etc. Its easier than doing that and is just the same.
8)PEACE
-
lol - i didnt see the this select 0 bit
lol - ok... thats that sorted - now one last question in general editing and i think i have this sorted
:thumbsup: