Joe98 92 Posted August 14, 2022 I have 5 scripts: location0.sqf location1.sqf location2.sqf location3.sqf location4.sqf I walk into a trigger and this runs another script named head1.sqf How do I write a script that selects one of the 5 scripts at random. . Share this post Link to post Share on other sites
Harzach 2518 Posted August 14, 2022 https://community.bistudio.com/wiki/selectRandom But whatever you are doing can probably be done from one script. 1 Share this post Link to post Share on other sites
Joe98 92 Posted August 14, 2022 Thank you but I do not understand that. . Share this post Link to post Share on other sites
Joe98 92 Posted August 14, 2022 I did find another way and I don't understand this either. I don't understand the underscore at the beginning. I have copied this from an old thread by somebody else. _rNum = selectRandom [1,2,3,4,5]; if ( _rNum == 1 ) then { execVM "script1.sqf"; }; if ( _rNum == 2 ) then { execVM "script2.sqf"; }; if ( _rNum == 3 ) then { execVM "script3.sqf"; }; if ( _rNum == 4 ) then { execVM "script4.sqf"; }; if ( _rNum == 5 ) then { execVM "script5.sqf"; }; Would I place all of that in a script? . Share this post Link to post Share on other sites
Schatten 290 Posted August 14, 2022 @Joe98, you can simplify code: private _scriptName = selectRandom ["script1", "script2", "script3", "script4", "script5"]; execVM (format ["%1.sqf", _scriptName]); 20 minutes ago, Joe98 said: Would I place all of that in a script? It depends what you want. 1 Share this post Link to post Share on other sites
Soapbox0331 17 Posted August 14, 2022 26 minutes ago, Joe98 said: I did find another way and I don't understand this either. I don't understand the underscore at the beginning. I have copied this from an old thread by somebody else. _rNum = selectRandom [1,2,3,4,5]; if ( _rNum == 1 ) then { execVM "script1.sqf"; }; if ( _rNum == 2 ) then { execVM "script2.sqf"; }; if ( _rNum == 3 ) then { execVM "script3.sqf"; }; if ( _rNum == 4 ) then { execVM "script4.sqf"; }; if ( _rNum == 5 ) then { execVM "script5.sqf"; }; Would I place all of that in a script? . @Joe98 I have used same method...this is all in one script. In my case, called from a trigger. AmbientFlyby.sqf: _rNum = selectRandom [1,2,3,4]; if ( _rNum == 1 ) then { execVM "AmbientFlyby_1.sqf"; }; if ( _rNum == 2 ) then { execVM "AmbientFlyby_2.sqf"; }; if ( _rNum == 3 ) then { execVM "AmbientFlyby_3.sqf"; }; if ( _rNum == 4 ) then { execVM "AmbientFlyby_4.sqf"; }; Then subsequent AmbientFlyby scripts 1-4 are in the mission file. Share this post Link to post Share on other sites
Harzach 2518 Posted August 14, 2022 My point is that having all of those scripts is likely unnecessary. Share your code. 1 Share this post Link to post Share on other sites
Soapbox0331 17 Posted August 14, 2022 22 minutes ago, Harzach said: My point is that having all of those scripts is likely unnecessary. Share your code. @Harzach I am sure you are right. Ok, intent is to create some variety to environment when players get to/spawn in their base/FOB. These are the "varieties" of flybys: AmbientFlyby_1.sqf: sleep 1; ambientFly = [getmarkerpos "FlyByStart", getMarkerPos "FlyByEnd", 120, "FULL", "uns_ov10_usaf_FAC", WEST] call BIS_fnc_ambientFlyBy; AmbientFlyby_2.sqf: sleep 1; ambientFly = [getmarkerpos "FlyByEnd_2", getMarkerPos "FlyByStart_2", 100, "FULL", "vn_b_air_uh1d_02_07", WEST] call BIS_fnc_ambientFlyBy; AmbientFlyby_3.sqf: sleep 1; ambientFly = [getmarkerpos "FlyByStart", getMarkerPos "FlyByEnd", 120, "FULL", "vn_i_air_ch34_02_02", WEST] call BIS_fnc_ambientFlyBy; sleep 2; ambientFly = [getmarkerpos "FlyByStart", getMarkerPos "FlyByEnd", 130, "FULL", "vn_i_air_ch34_02_02", WEST] call BIS_fnc_ambientFlyBy; AmbientFlyby_4.sqf: sleep 1; ambientFly = [getmarkerpos "FlyByStart_2", getMarkerPos "FlyByEnd_2", 200, "FULL", "uns_A1J_HCAS", WEST] call BIS_fnc_ambientFlyBy; sleep 3; ambientFly = [getmarkerpos "FlyByStart_2", getMarkerPos "FlyByEnd_2", 220, "FULL", "uns_A1J_HCAS", WEST] call BIS_fnc_ambientFlyBy; Share this post Link to post Share on other sites
Larrow 2823 Posted August 14, 2022 2 hours ago, Soapbox0331 said: These are the "varieties" of flybys: Spoiler _airCraft = [ "uns_ov10_usaf_FAC", "vn_b_air_uh1d_02_07", "vn_i_air_ch34_02_02", "uns_A1J_HCAS" ]; _flybys = [ [ "FlyByStart", "FlyByEnd" ], [ "FlyByEnd", "FlyByStart" ], [ "FlyByStart_2", "FlyByEnd_2" ], [ "FlyByEnd_2", "FlyByStart_2" ] ]; _plane = selectRandom _aircraft; selectRandom _flybys params[ "_start", "_end" ]; _numFlyBys = ( floor random 3 ) max 1; // 1-2 _flyByHeight = ( random 100 ) + 100; // 100-199.99 for "_flyby" from 1 to _numFlyBys do { [ getMarkerPos _start, getMarkerPos _end, _flyByHeight, "FULL", _plane, west ] call BIS_fnc_ambientFlyby; sleep (( floor random 5 ) max 2 ); // 2-4 }; A Random plane, flight path and height with random delay between multi-plane flybys. It could be easily changed up to provide certain planes per flight path if needed (as per your original). 2 1 Share this post Link to post Share on other sites
Soapbox0331 17 Posted August 15, 2022 @Larrow Hey thanks for doing this, works great! Seeing what it went from, to your script, really helps my understanding. Share this post Link to post Share on other sites
Harzach 2518 Posted August 15, 2022 14 hours ago, Soapbox0331 said: I am sure you are right. That doesn't sound like me. Anyway, I was replying to @Joe98, as this is his topic. Share this post Link to post Share on other sites
Soapbox0331 17 Posted August 15, 2022 16 minutes ago, Harzach said: That doesn't sound like me. Anyway, I was replying to @Joe98, as this is his topic. Ah, my apologies, didn't mean to commandeer the thread. Hopefully @Joe98 will post his code as well. Share this post Link to post Share on other sites
Joe98 92 Posted August 16, 2022 _rNum = selectRandom [1,2,3,4,5]; if ( _rNum == 1 ) then { execVM "script1.sqf"; }; if ( _rNum == 2 ) then { execVM "script2.sqf"; }; if ( _rNum == 3 ) then { execVM "script3.sqf"; }; if ( _rNum == 4 ) then { execVM "script4.sqf"; }; if ( _rNum == 5 ) then { execVM "script5.sqf"; }; I confirm this works beautifully thank you. It does exactly as I intended. There is no code to post as such. I have a mission with a lot of random elements so that it plays differently every time. Except that the hints are the same. In effect they give the game away. So, by having a number of different hints selected at random, the hints no longer give the game away. Share this post Link to post Share on other sites
Harzach 2518 Posted August 16, 2022 44 minutes ago, Joe98 said: There is no code You are randomly calling five empty script files? See @Schatten's post above. Share this post Link to post Share on other sites
pierremgi 4906 Posted August 17, 2022 17 hours ago, Joe98 said: No What's a code for you? Larrow show you a single code, truly more efficient than your bunch of sqf. And, btw, and for further readers, a suite of if then..., if then... lines for a single result is just a waste of code because you are checking all the conditions, one by one. Not a real problem here but not a good habit. So, better: call { if... exitwith {...}; if... exitWith {...}; .... }; or even, in your case: execVM selectRandom ["script1.sqf","script2.sqf","script3.sqf",....]; 3 Share this post Link to post Share on other sites
Joe98 92 Posted August 17, 2022 This is a game. It is meant to be fun and not work. Many people have stated that they dropped the game and left the forum because they were given complex answers they don't understand. Larrow's code is complex and I don't understand. I am not going to study it because that would be work and not fun. Your script uses fewer characters than the one I found. However, your script still lists all the individual scripts. But the list is horizontal. The way I have done it the list is vertical. I can come back in 6 months, glance at the code and know exactly what it does. . Share this post Link to post Share on other sites
Harzach 2518 Posted August 18, 2022 3 hours ago, Joe98 said: The way I have done it Is redundant. You are selecting a number at random, then assigning that number to a script. It's like pouring yourself a glass of water, then pouring that out into a different glass to drink from. @pierremgi's method just selects the script at random. As to the rest, your definition of "fun" is not a universal truth. And running away from knowledge is silly. 3 Share this post Link to post Share on other sites
Joe98 92 Posted August 18, 2022 1 hour ago, Harzach said: . @pierremgi's method just selects the script at random. Yes I agree. And yet and yet and yet and yet. It lists the scripts horizontally. When listed vertically it is much easier to read. It is easier to come back 6 months later and know what it means. it is easier to copy and paste 5 rows and then amend one number in each row. Fun is playing pretend soldier and shooting Ai targets. . 2 Share this post Link to post Share on other sites
Harzach 2518 Posted August 18, 2022 35 minutes ago, Joe98 said: When listed vertically it is much easier to read. So expand it vertically. It's a legal move, no one will be coming for you. execVM selectRandom [ "script1.sqf", "script2.sqf", "script3.sqf" // just remember, no comma after the last element! ]; Large arrays are easier to read this way. 2 Share this post Link to post Share on other sites
Joe98 92 Posted August 18, 2022 53 minutes ago, Harzach said: execVM selectRandom [ "script1.sqf", "script2.sqf", "script3.sqf" // just remember, no comma after the last element! ]; You see (he says referring to the other thread) it is easy to give a accurate instruction thank you 🙂 And now somebody else can utilise this in their mission. Share this post Link to post Share on other sites
Harzach 2518 Posted August 18, 2022 The problem is that you are focusing on surface properties and not attempting to understand the structure. 1 Share this post Link to post Share on other sites