Jump to content
vissarion1917

Scripting presence condition based on a random number

Recommended Posts

Hello Everyone

What I am trying to do on the editor is to spawn certain units according to a random number.
So I create a unit which presence condition is "alfa"
I create another unit which presence condition is "beta"

And now I place some triggers and in their "on activation" boxes I write the following:
u=random 3;
if (u>1) then {alfa=true} else {beta=true};

And it does not work. Does anybody knows why? The random number in u is correctly generated because I just hace checked it with:

hint format["the random number calculated is %1",u];

So here is not the problem. The problem must be that 'if-else' statement and I do not know why.

Thanks!

Share this post


Link to post
Share on other sites

this can't work that way for many reasons.

 

Ill give u a solution but I guess for understanding it you have to get much more experience in scripting.

 

The solution is to do it without any trigger but with 2 files.

 

1. File is for defining a function in armas function library. those function is defined to get executed automatically prior executiion of the init fields of objects.

 

The file hase to be named description.ext and has to be located in missions root folder. The root folder is where your missions mission.sqm is located as well.

 

here is the content of that file:

 

description.ext

class CfgFunctions
{
	class vissarion
	{
		class viss_functions
		{
			class  randomVars { preinit = 1; };
		};
	};
};

 

2. file is the script itself which we defined in description.ext. it has to be located in a subfolder of missions root:<ROOT>\functions\viss_functions\fn_randomVars.sqf

 

this file will set the variables Alpha and Bravo first and after that it will change it to the opposite values if the randomization requires it:

 

fn_randomVars.sqf

Alpha = false;
Bravo = true;

if ( random 3 > 1) then
{
 Alpha = true;
 Bravo = false;
};

 

Now you are able to use Alpha and Bravo in your init fields.

 

This solution is not that easy as you thought but its no rocket science as well 🙂

Its a very clean solution and it is tested and works.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you a lot for the response!

But I have tried it and doesn't work, at least in arma 2.

Also, it doesn't report me any error, so no clue what kind o thing doesn`t work

 

Thank you!

Share this post


Link to post
Share on other sites
26 minutes ago, vissarion1917 said:

arma 2

 

Not all commands/functions/etc. from Arma 3 (the topic of this forum) are backward-compatible to Arma 2.

Share this post


Link to post
Share on other sites
11 hours ago, sarogahtyp said:

Now you are able to use Alpha and Bravo in your init fields.

How do I associate the editor placed unit to Alpha or Bravo?

Share this post


Link to post
Share on other sites
41 minutes ago, Soapbox0331 said:

How do I associate the editor placed unit to Alpha or Bravo?

 

In this specific case, using @sarogahtyp's code, "ALPHA" and "BRAVO" are now global variables that will randomly evaluate as either true or false at mission start. That is, one will always be true, and one will always be false, but which is which will be random. In a unit's "Object: Presence" tab, in the "Condition of Presence" field, place either variable, and at mission start the unit will randomly either be there or not.

 

4wj3tT3.pngl

  • Like 1
  • Thanks 1

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

×