Jump to content
Sign in to follow this  
Valeriy

Needed help, command "random".

Recommended Posts

as by means of commands "Random", force soldier to pronounce accidentally chosen phrases "RUS1", "RUS2",

"RUS3", ......, "RUS19" ?

Share this post


Link to post
Share on other sites

I think there is no simply way like unit say ("rus"+random19)

try this :

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_speech=["RUS1","RUS2","RUS3", ... ,"RUS19"]

_number=(count _speech)-0.001

_pick=-0.499+random _number

_picked=_speech select _pick

soldier say _picked

<span id='postcolor'>

Share this post


Link to post
Share on other sites

Right, that seems odd. Random will produce random numbers, with fractions.

I suggest something like this:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_speech = ["RUS1,"RUS2","RUS3",..."RUS19"]

_number  = (count _speech)

_randomNumber = random _number

_randomNumber = _randomNumber - (_randomNumber mod 1)

_picked = _speech select _randomNumber

soldier say _picked

<span id='postcolor'>

Wait a minute, I just came up with an idea, add a parameter to it.

*rewrites*

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_soldier = _this select 0

_speech = ["RUS1,"RUS2","RUS3",..."RUS19"]

_number  = (count _speech)

_randomNumber = random _number

_randomNumber = _randomNumber - (_randomNumber mod 1)

_picked = _speech select _randomNumber

_soldier say _picked

<span id='postcolor'>

Now, this is better, as it lets you define the soldier dynamically.

So you just do a trigger, init, or whatever call to the script with this.

[speakingSoldiersName] exec {speechScript.sqs}

That way, you can add the script to several triggers, and several soldiers, without rewriting the script.

Now, you could do it so that you could enter what to say manually, but I think that's over doing it.

Share this post


Link to post
Share on other sites

What Bart said will work fine, could rewrite it:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_speech=["RUS1","RUS2","RUS3", ... ,"RUS19"]

_number=count _speech;

_picked=_speech select _pick

soldier say (_speech select ((random _number)-0.5))<span id='postcolor'>

Or

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_rNum = random 19;

_rNum = _rNum - (_rNum mod 1);

soldier say (format ["RUS%1",_rNum]);<span id='postcolor'>

should work... not tested as usual

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (KTottE @ Jan. 09 2003,18:33)</td></tr><tr><td id="QUOTE">Random will produce random numbers, with fractions.<span id='postcolor'>

Yes, but if you use number with fractions for SELECT, engine automaticaly rounds that number.

It's standard math rounding : -0.4999 to 0.4999 is rounded to 0, 0.5 to 1.499 is rounded to 1 and so on.

I posted script with several variables for better apprehending. You can also use :

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_speech=["RUS1","RUS2","RUS3", ... ,"RUS19"]

soldier say (_speech select (-0.499+ random (-0.001+count _speech)))

<span id='postcolor'>

The format thing sounds promising. I must try it.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×