Jump to content
Palmi69

one condition "if" for fews objects

Recommended Posts

hi,

 

i want to define same condition  for two objets  ("obj1" and "obj2") and scripted in one condition: "if"

 

\\i've tryed this:

if (obj1 or obj2 distance player < 20) then {....    \\but "or" gone wrong !

 

\\i don' t want to repeat condition for each obj like this:

if (obj1 distance player < 20 ) then {...     

if (obj2 distance player < 20) then {...

 

thanks for help !

 

 

Share this post


Link to post
Share on other sites
1 hour ago, sil.lau@free.fr said:

hi,

 

i want to define same condition  for two objets  ("obj1" and "obj2") and scripted in one condition: "if"

 

\\i've tryed this:

if (obj1 or obj2 distance player < 20) then {....    \\but "or" gone wrong !

 

\\i don' t want to repeat condition for each obj like this:

if (obj1 distance player < 20 ) then {...     

if (obj2 distance player < 20) then {...

 

thanks for help !

 

 


 

Quote

if(player distance obj1 < 20 OR player distance obj2 <20) then { };


You can use OR or || for both conditions.

EDIT:

Your if condition doesn't work because when you wrote obj1 OR obj2 distance player < 20. the condition is basically saying if variable "obj1" returns true OR obj2 is less than 20m from the player.

You must type the whole condition and separate them using alias, like OR, AND, or isEqualTo.
Your second if statement is correct, you just need to combine both conditions together using alias. Like I mentioned.

  • Like 3

Share this post


Link to post
Share on other sites

@sil.lau@free.fr,

Loop the condition and identify the nearest activator.

//method 1
[obj_0, obj_1] spawn {
	waitUntil { sleep 1;
		_near= _this select {_x distance player < 20};
		if !(_near isEqualTo []) then {systemChat str (_near #0); true} else {false}
	}
};

//method 2 (probably faster)
[obj_0, obj_1] spawn {
	waitUntil { sleep 1;
		_near= _this findIf {_x distance player < 20};
		if (_near> -1) then {systemChat str (_this select _near); true} else {false}
	}
};

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, wogz187 said:

@sil.lau@free.fr,

Loop the condition and identify the nearest activator.


//method 1
[obj_0, obj_1] spawn {
	waitUntil { sleep 1;
		_near= _this select {_x distance player < 20};
		if !(_near isEqualTo []) then {systemChat str (_near #0); true} else {false}
	}
};

//method 2 (probably faster)
[obj_0, obj_1] spawn {
	waitUntil { sleep 1;
		_near= _this findIf {_x distance player < 20};
		if (_near> -1) then {systemChat str (_this select _near); true} else {false}
	}
};

Have fun!

I understand "player" is used for SP. How does this look for MP dedicated? Is it just replacing with "anyPlayer"? I am thinking it is more than that, but I may be a little code paranoid by now;)

  • Like 2

Share this post


Link to post
Share on other sites

Many Thanks SCHATTEN ! it's a good code when there are a lot of objetcs to define .

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

{if (allPlayers inAreaArray [getpos _x, 20, 20] isNotEqualTo []) exitWith {TRUE}; FALSE} forEach [obj_0,obj_1]

@pierre MGI When I add to trigger condition I get this error: Condition: Missing ]

  • Like 1

Share this post


Link to post
Share on other sites

copy/paste known bug on forum. Not on my side.

Anyway, that works as condition in a loop, that doesn't work in a trigger condition, due to undefined result in 3den.

Prefer:

[obj_0,obj_1] findIf {allPlayers inAreaArray [getpos _x, 20, 20] isNotEqualTo []} >-1

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

copy/paste known bug on forum. Not on my side.

Anyway, that works as condition in a loop, that doesn't work in a trigger condition, due to undefined result in 3den.

Prefer:


[obj_0,obj_1] findIf {allPlayers inAreaArray [getpos _x, 20, 20] isNotEqualTo []} >-1

 

My misunderstanding, thanks!

  • Like 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

×