Hard Light Productions Forums
Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Boomer20 on February 24, 2016, 04:40:06 am
-
So I understand that you can use a random number generator with the sexp random-of. However I am curious if its possible to define a pool of numbers for the generator to pick from?
Context:
I want to add randomness to where certain ships warp in while still controlling there general location. To do this I will have them warp near a placeholder ship (the SJD Sathanas seems its invisible). BUT before they warp I want to manipulate the co-ordinates of the placeholder ship to one of 15 waypoints scattered around. I want the number generator to pick a number between 1-15 which corresponds to each warp location.
Is this possible?
-
Yes, absolutely. random-of takes a list of arguments (in this case, waypoint locations), and returns a random element from that list. Do note, however, that what you actually want is random-multiple-of, since random-of will fire once and then continue to return the same result.
-
That's some PHP-level function naming there.
-
Not by choice. The original rand SEXP had the same behaviour and it would be really confusing if random-of didn't.
You can also just use rand-multiple rather than rand-multiple-of. You can specify that you want a random number between 1 and 15 quite easily.
Random-multple-of requires you to use when-argument. It's probably easier but it depends on you've already FREDded.
-
Okay i am a little lost, so if I am going to have 4 instances of random events, should I use random-multiple-of or rand-multiple? Then what is the best way to implement it? I feel either I don't know/understand enough on how to use it or that I haven't created all the variables etc need to set it up.
-
If you use a when-argument sexp, use rand-multiple-of.
If you use a regular when sexp, use rand-multiple if it has a repeat count or trigger count, and use regular rand if it does not.
-
Success, I now have one groups warp point randomly changing every play through. Now to make the other 3 groups events. :D
Admiral Ralwood's thread "Example Event: Setting cargo at random" proved very helpful in working out how to set it out.
-
Glad it came in handy for someone. :yes: