Jump to content
Sign in to follow this  
L.Trale

Help with select Random Array?

Recommended Posts

I'm a bit rusty at scripting as I took a few months off. Can someone help me with this?

_Select1 = ["A", "B", "C", "D", "E"];
_Select2 = floor random count _Select1;
hint ["1%", _Select1];

The Letters are the names of AIs.

Thanks.

Share this post


Link to post
Share on other sites

Thank you so much. I also made a few embarrassing errors. Forgot the "format" after hint and the "%1". Thanks!

---------- Post added at 21:49 ---------- Previous post was at 21:42 ----------

Quick question; how do I add an action the the person selected? Thanks

---------- Post added at 21:58 ---------- Previous post was at 21:49 ----------

Scratch that, found it. Another quick question; how do you add an action to just the player? For example, I want A to have an action "Wave", but other players can use the action on him.

Share this post


Link to post
Share on other sites
Thank you so much. I also made a few embarrassing errors. Forgot the "format" after hint and the "%1". Thanks!

---------- Post added at 21:49 ---------- Previous post was at 21:42 ----------

Quick question; how do I add an action the the person selected? Thanks

---------- Post added at 21:58 ---------- Previous post was at 21:49 ----------

Scratch that, found it. Another quick question; how do you add an action to just the player? For example, I want A to have an action "Wave", but other players can use the action on him.

_action = a addAction ["Wave", "Script.sqf"];

But your soldiers names need to match so the if the name of the soldier..

so what you should have is

_selector = [soldier1, soldier2, soldier3]call bis_fnc_selectRandom;
_action = _selector addAction ["wave", "script.sqf"];

Share this post


Link to post
Share on other sites

You don't need the "_action" part. The rest I have and it still allows other players to use that action.

Share this post


Link to post
Share on other sites
You don't need the "_action" part. The rest I have and it still allows other players to use that action.

The _action part in that case is the return value, which in the case of addAction, is the action ID. So in the event that you want to removeActive (its hidden by default, yes, but for reuseability it'd need to be removed), you would call on the return. IE, using the above as reference, _selector removeAction _action.

Share this post


Link to post
Share on other sites
;2614957']The _action part in that case is the return value' date=' which in the case of addAction, is the action ID. So in the event that you want to removeActive (its hidden by default, yes, but for reuseability it'd need to be removed), you would call on the return. IE, using the above as reference, _selector removeAction _action.[/quote']

Thanks for explaining it :D

Share this post


Link to post
Share on other sites

Yeah, I know. Thanks for being helpful though. (I'm not trying to remove the action, I'm trying to hide it from other players)

Share this post


Link to post
Share on other sites

You'd probably have to use the condition field of the addAction

Share this post


Link to post
Share on other sites
Yeah, I know. Thanks for being helpful though. (I'm not trying to remove the action, I'm trying to hide it from other players)

Which Fusion already explained. I was just pointing out the importance of the return value.

As Fusion said, and the biki indicates, addAction is used on objects (be it soldiers, vehicles, boxes ,etc). If you are using "player" or "this", then yes, it will be on every client. However, if you call it for, say, p1, which is the name of 1 character, it will only be on that character.

Share this post


Link to post
Share on other sites

Do you mean _Selector = [Alpha,Bravo,Charlie,Delta,Echo] call BIS_fnc_selectRandom;

_action = _Selector addAction ["Wave", "Wave.sqf"];

Share this post


Link to post
Share on other sites

That is what I posted, justbwith different soldier names. Just make sure the random array is the same as the names of the soldiers you placed down..

Share this post


Link to post
Share on other sites

I've done this, still doesn't work. I've tried messing around with the parameters for addaction but no luck. Thanks for the help though :bounce3:

Share this post


Link to post
Share on other sites

Yes, they are the same names.

Share this post


Link to post
Share on other sites

But you are trying to limit the action to one unit right? So one randomly selected unit gets the addaction option and all other don't? Is that right?

Share this post


Link to post
Share on other sites

Yes. The problem is that any unit can walk up to the "_Selector" and use the addaction. I've tried _Stab = _Selector addAction ["STAB", "Stab.sqf", nil, 1.5, True, True, "", "this == _Selector"]; but It doesn't work.

Share this post


Link to post
Share on other sites

See u have a speific item causeimg the addaction so you have to do a if statement for it

Share this post


Link to post
Share on other sites

So I should add something similar to if (_Selector == this) then {_Selector addaction ["STAB", "Stab.sqf"]} else {};

Think I've gotten the answer: _Stab = if (player == _Selector) then {player addaction ["STAB", "Stab.sqf"]} else {};

It seems to work, but I'll have to do more testing.

Edited by L.Trale

Share this post


Link to post
Share on other sites

Try this:

_Selector = [A,B,C,D,E] call BIS_fnc_selectRandom;
_Selected = _Selector; // Narrow it down to one random I can use twice
_action = _Selected addAction ["STAB", "Stab.sqf", Nil, 1.5, true, true, "", "player == _Selected"]; 

I added "_selected" because I'm not sure if calling "_selector" twice will give me two different randoms or not.

Edited by Fight9

Share this post


Link to post
Share on other sites

_Stab = if (player == _Selector) then {player addaction ["STAB", "Stab.sqf"]} else {}; is working fine, but I might need this for something else. Thanks for the help! :D

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  

×