Jump to content
razzored

Random script selector.

Recommended Posts

Jello.
Im working on something, where i need an addaction like
This addAction ["Get random effect","scripts\randomizer.sqf",[],1,false,true,"","_this distance _target < 2"]; // this being example.
Where the script "randomizer.sqf" then has a list of scripts/scripts paths and runs 1 random of them as a remote server execution (Ie if they spawn something, it has to spawn so everyone sees it, in dedicated environment, though i suppose for that, i just need to put if (isServer) then {Long script that does stuff}; inside the "end scripts" chosen by the randomizer..)
So the thing i need help with is the "randomizer" or selection script itself.

So far what ive come up with is something along the lines of

(NOTE, Scripts are all located in mission folder)

_Rscripts = ["scripts\script1.sqf","scripts\script2.sqf","scripts\script3.sqf","scripts\script1.sqf","scripts\script4.sqf"];
_Rselector = _Rscripts select floor random count _Rscripts;
_handle = [] execVM "_Rselector";

 

Cheers.

Share this post


Link to post
Share on other sites

So like dis
 

_Rscripts = ["scripts\script1.sqf","scripts\script2.sqf","scripts\script3.sqf","scripts\script1.sqf","scripts\script4.sqf"];
_Rselector = _Rscripts select floor random count _Rscripts;
_handle = [] execVM _Rselector  // I also removed ; since i dont actually think its required here.

OR


_Rscripts = selectRandom ["scripts\script1.sqf","scripts\script2.sqf","scripts\script3.sqf","scripts\script1.sqf","scripts\script4.sqf"];

_handle = [] execVM _Rscripts  // I also removed ; since i dont actually think its required here.


// This is a very syntax based question, i am not at a pc with arma 3 installed right now, so i am not able to test it for another couple of hours, so im just hoping to to pinpoint the most likely to give good results, until i can actually test ^_^

Share this post


Link to post
Share on other sites
7 minutes ago, razzored said:

_handle = [] execVM _Rselector  // I also removed ; since i dont actually think its required here.

 

it is required if you have more script lines after that

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Another way:

 

Write 5 scripts.

Create 5 triggers. Each trigger runs one of the scripts. The 5 triggers are placed in an out of the way place on the other side of the map.

 

The five triggers are named from  zero to four.

trig0

trig1

trig2

trig3

trig4

 

Place a 6th trigger on the map in the centre of the action. When this trigger is fired, it selects one of the five triggers at random and fires that trigger.

 

.

 

 

 

 

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for the info, the script method has been exactly what i needed, especially since there are 40+ scripts in place.. that's a lot of triggers ^^ 
I do however appreciate the pitch none the less and could use it for something else one day, or someone else might swing by and find it to be just what they need 😄

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, Joe98 said:

Another way:

 

Write 5 scripts.

Create 5 triggers. Each trigger runs one of the scripts. The 5 triggers are placed in an out of the way place on the other side of the map.

 

The five triggers are named from  zero to four.

trig0

trig1

trig2

trig3

trig4

 

Place a 6th trigger on the map in the centre of the action. When this trigger is fired, it selects one of the five triggers at random and fires that trigger.

 

If he wants to use his Scripts again, this is hell a lot of work.

 

I would do it like this:

 

1) Create some Sqf-files (1 file =1 function)

2) Add all your files to CfgFunctions (in the "Description.ext" file)

class CfgFunctions
{

	class JF
	{
	
		class Scripts
		{
		
			class function_1 {file = "MyPath\function1.sqf"};
			class function_2 {file = "MyPath\function2.sqf"};
			class function_3 {file = "MyPath\function3.sqf"};
		};
			
	};

};

--> your functions are compiled to:

JF_fnc_function_1, JF_fnc_function_2, JF_fnc_function_3

 

3) Create some sort of Array (for Example in the initServer.sqf) and add the functions

private _Functions = [JF_fnc_function_1, JF_fnc_function_2, JF_fnc_function_3];
missionNamespace setVariable ["JF_Functions", _Functions];

 4) Add a random function to an unit (for example the player)

private _functions = [];
private ["_function"]; 

_functions = missionNamespace getVariable "JF_Functions";
_function = selectRandom _functions;

player addAction ["Some Function", _function];

 

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

_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"; };

etc.

 

If you want to stack the probably of a script (example #1), you can do:

_rNum = selectRandom [1,1,1,1,2,3,4,5];

 

And so on.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
27 minutes ago, Von Quest said:

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"; };

etc.

Use switch do instead 

  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites

If we keep this up, we will have a compiled list of every possible way to select random arrays of scripts in the real virtuality engine before 2021 🙂

  • Haha 2

Share this post


Link to post
Share on other sites

Another option is min/max for the random number if you have a large range :

_rNum = [1,40] call BIS_fnc_randomInt;

Share this post


Link to post
Share on other sites

Why does Arma have so many different commands to call a random string from an array.

Share this post


Link to post
Share on other sites

Precision, Flexibility, and Age.

 

And I assume you mean commands, as variables are created by the coder/user as you invent the variable/word and spelling at your discretion.

 

_one = 1;

_num = 1;

_blah = 1;

_two = 1;

_bgsAvH = 1;

 

All local variables on the left side of the equals sign, are all 1. You make them up. They are just data holders.

_num + _blah = 2

 

ArmA Scripting Commands (for other new players) :

https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

  • Haha 1

Share this post


Link to post
Share on other sites

yeah, Ooga forgot wordy words. Luckily Vooga from Bonga tribe remembers.

Share this post


Link to post
Share on other sites

Also @Von Quest why did you pull the plug on Fuse?
tried it out some time ago, was quite sad that it does not explode on a dedicated server and that... development stopped.

Share this post


Link to post
Share on other sites

Just paused for now. Will be continuing it this winter I think.

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

×