Jump to content
Sign in to follow this  
lethal

test if one unit is enemy of another?

Recommended Posts

ok, i know this is a very 'noobish' question but nevertheless i haven't come up with an answer yet. Here is the situation:

i have one unit and an array of units. Now i want to run through the array and create a new one just containing units out of the first array hostile to the single unit.

i thought about doing it 'manually' by using several if's and then's depending on the side of the first unit but on second thought i dismissed that because, as you know, the resistance side can be hostile to several or no sides depending on the mission settings...

Maybe the answer is obvious but for some reason i can't seem to find it. Any helpful pointers would be apprecieted wink_o.gif

Share this post


Link to post
Share on other sites

if (side _unit != side _yourunit ) then { blah blah };

Share this post


Link to post
Share on other sites

huh? what if unit1 is resistance (friendly to blue) and unit2 is blue? they're not enemies but on different sides nevertheless aren't they?

Share this post


Link to post
Share on other sites

well if you also need to check the type of the unit,, use typeof.

_class=typof _unit

that will show you if hes east west or whatever,, but you need an array containg all the classes

Share this post


Link to post
Share on other sites
well if you also need to check the type of the unit,, use typeof.

_class=typof _unit

that will show you if hes east west or whatever,, but you need an array containg all the classes

not sure you understand my problem.

i'm trying to make a (universally useful) helper function in which this is needed. and because of that i don't 'know' beforehand to which side, if any, resitance is friendly to. finding the side of each unit is no problem whatoever. i only need to know who that side is hostile (or friendly) to...

dunno what unittype has to do with this though? i used that before in the script but it's only useful for determining which class a unit belongs to...

Share this post


Link to post
Share on other sites

countEnemy

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? (_u countEnemy [_badguy]) == 1 : Hint "_badguy is enemy of _u"

Share this post


Link to post
Share on other sites

Has been discussed before, but you need to know that the

units actually need to knowsabout each other.

Otherwise the command will return nothing.

And that can take a considerable amount of time even when you place them 1m next to each other (Sometimes up to 10 seconds).

So if your application is time critical, countenemy is useless.

Share this post


Link to post
Share on other sites
countEnemy

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? (_u countEnemy [_badguy]) == 1 : Hint "_badguy is enemy of _u"

i think that might work for me in this case. thanks, haven't thought of that for some reason smile_o.gif

what i'm doing is linking the knowlege of an array of units to another array of units. thats why knowsabout doesn't really matter in this case since i need to check that anyway wink_o.gif

Share this post


Link to post
Share on other sites
Has been discussed before, but you need to know that the

units actually need to knowsabout each other.

Otherwise the command will return nothing.

And that can take a considerable amount of time even when you place them 1m next to each other (Sometimes up to 10 seconds).

So if your application is time critical, countenemy is useless.

I never had this experience.

To be sure i made a test mission where i put one civilian (the player), one Blufor (named 's1' ), and one Opfor (named 's2' ).

Each of these soldiers (including the civ player) were 6Km away from each other, so no way they could know about any other.

And into the init field of the civ player i put<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Hint Format["%1", (s1 countEnemy [s2])]

...the result was instant, and the value of the result was 1.

So, i don't know who and where had any problems with that, but clearly in ArmA 1.05 it works and it DOES NOT RELY ON KnowsAbout.

Share this post


Link to post
Share on other sites

There seems to be a brief fraction of a second, during the mission initialization, when countEnemy returns the correct value, but then it goes down right away. Try reading the value in a loop and you'll see.

I haven't tested it in 1.05 yet, but since Suma only acknowledged the behaviour just a few days before 1.05 came out, I doubt that it was fixed in that version already.

Share this post


Link to post
Share on other sites
There seems to be a brief fraction of a second, during the mission initialization, when countEnemy returns the correct value, but then it goes down right away. Try reading the value in a loop and you'll see.

I haven't tested it in 1.05 yet, but since Suma only acknowledged the behaviour just a few days before 1.05 came out, I doubt that it was fixed in that version already.

Thanks for correcting me, and sorry everyone, it's like Charonos wrote earlier.

I tried it after a little pause and within a loop, and sudenly it ceased to work.

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  

×