Jump to content
Sign in to follow this  
anthonyfromtheuk

Script to randomly call other scripts

Recommended Posts

I have multiple scripts which spawn different groups and units how can I randomly call them with another script?

I have 3 scripts named 1.sqf 2.sqf and 3.sqf. I would like a script to randomly choose which of these scripts to call when it itself is called.

I really need to learn to randomise my missions, they are way less immersive when I know what's going to be where.

Share this post


Link to post
Share on other sites

Probably something like this will work:

_scriptsArray = ["1.sqf", "2.sqf", "3.sqf"];
_script = _array select floor random count _scriptsArray;
[] execVM _script;

If it won't execute, try this code

_script = (floor random 3) + 1;
switch (_script) do
{
  case 1 : { [] execVM "1.sqf"; };
  case 2 : { [] execVM "2.sqf"; };
  case 3 : { [] execVM "3.sqf"; };
};

Edited by Semiconductor

Share this post


Link to post
Share on other sites

@semiconductor : Easier to use bis function for _script value

_script = [1,3] call BIS_fnc_randomInt;

Share this post


Link to post
Share on other sites

_script = [1,3] call BIS_fnc_randomInt;
switch (_script) do
{
  case 1 : { [] execVM "1.sqf"; };
  case 2 : { [] execVM "2.sqf"; };
  case 3 : { [] execVM "3.sqf"; };
};

This works perfectly thank you for your help!

Edited by Anthonyfromtheuk
  • Like 1

Share this post


Link to post
Share on other sites
Thanks, I didn't know that there is such convenient function :)

you can find them in the editor by clicking Fx

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  

×