Jump to content
thy_

[SOLVED] findNearestEnemy command looks NOT okay (for me, a noob)

Recommended Posts

Am I misunderstanding some or findNearestEnemy is like isTouchingGround (more) that also doesn't work well?

 

Btw, I got the feeling that "Example 2" of findNearestEnemy is wrong inside the wiki.

 

 

// Wiki / Example 2:
_myNearestEnemy = player findNearestEnemy player;  //????

// This wiki page was last edited on 7 September 2022, at 12:43.

 

 

Share this post


Link to post
Share on other sites

Define "doesn't work well."

 

The second example is finding the the enemy of the player that is closest to the player's's position.

Quote

Syntax:    object findNearestEnemy position

 

Share this post


Link to post
Share on other sites
47 minutes ago, pierremgi said:

https://feedback.bistudio.com/T122914

Probably didn't disturb anyone, and certainly no dev. Create your own function.

 

Not good enough but functional that is going well so far, because the result is not just "the nearest" but "someone probably the nearest".

 

THY_fnc_CSWR_OCCUPY_nearEnemies = {
	// This function searches for enemies around a specific unit.
	// Returns _isEnemyClose: bool.

	params ["_unit", "_range"];
	private ["_isEnemyClose", "_nearUnits", "_nearEnemies"];

	// Initial values:
	_isEnemyClose = false;
	// Searching:
	_nearUnits = _unit nearEntities ["CAManBase", _range];
	_nearEnemies = _nearUnits select { (side _unit != side _x) AND (alive _x) AND ((incapacitatedState _x) != "UNCONSCIOUS") };
	if ( (count _nearEnemies) > 0 ) then { _isEnemyClose = true };
	// Return:
	_isEnemyClose;
};

 

Edited by thy_
pierremgi, thanks!
  • Like 1

Share this post


Link to post
Share on other sites

Use "CAManBase" instead of "man". I'm afraid "man" returns (civilian) rabbits (and snakes,and...) in Armarvelous world. 😊

  • Haha 1

Share this post


Link to post
Share on other sites
1 minute ago, pierremgi said:

Use "CAManBase" instead of "man". I'm afraid "man" returns (civilian) rabbits (and snakes,and...) in Armarvelous world. 😊

Oh, thanks for that! 😄

Share this post


Link to post
Share on other sites
1 hour ago, Harzach said:

Define "doesn't work well." The second example is finding the the enemy of the player that is closest to the player's's position.

 

 

Ma man, from this wiki page isolated, I excepted "for dummies" (me) explanation because the syntax is...

_object findNearestEnemy [x, y] or [x, y, z];

... but Example 2 shows up _object command _object. In my noob mind, somethin' was not so clear. Trust me, I tried hard (hehe) to use the command as simple as it seemed to be and I just gave up and created the function above. In the end we will survive 🙂

Share this post


Link to post
Share on other sites

@thy_   an enemy is not an entity with a different side than the player. That depends for relationship between the sides.
you can use bis_fnc_enemySides (be careful it's an array of sides)
or diy:
... select { side _unit getFriend side _x <0.6 &&  lifeState _x in ["HEALTHY","INJURED"] };

  • Like 2

Share this post


Link to post
Share on other sites
2 hours ago, thy_ said:

the syntax is

 

Quote

Syntax:    object findNearestEnemy position

 

Parameters:    object: Object

                          position: Object or Array in format PositionAGL or Position2D

 

Looking at your function, I think you might have missed this detail of findNearestEnemy:

Quote

This command will return nearest object that is known to the unit and is considered enemy.

 

  • Like 2

Share this post


Link to post
Share on other sites
15 hours ago, Harzach said:

Looking at your function, I think you might have missed this detail of findNearestEnemy:

 

Morning, pal. (9am). I didn't miss it. The CSWR_OCCUPY_nearEnemies returns a bool that the goal is to tell another function the AI teleport must be ignored—no need to check if AI knows the enemy/enemy position.

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

×