tophe 69 Posted July 8, 2010 (edited) In my mission I have a trigger that puts all enemy units in a list and all player units in another list. Now I would like to have a trigger that starts if anyone in the enemylist has knowsAbout 3 about anyone in the playerlist. Does anyone have a good idea how to attack the problem? Edited July 8, 2010 by Tophe Share this post Link to post Share on other sites
Deadfast 43 Posted July 8, 2010 {_x knowsAbout player > 3} count TAG_EnemyList > 0 ...with fixed array {if (size _x == east) then {_x knowsAbout player > 3}} count AllUnits > 0 ...universal per side Share this post Link to post Share on other sites
tophe 69 Posted July 8, 2010 Thanks again man! That really did the trick! Share this post Link to post Share on other sites
tophe 69 Posted July 13, 2010 (edited) I just realized that player is local, so the trigger fires locally. How on earth do I get it to check if anyone on the enemyArray knows anything about anyone in playerArray? {_x knowsAbout anyoneIn playerArray > 0} count enemyArray > 0 Should I do something like this? {_x knowsAbout ({_x} forEach playerArray) > 0} count enemyArray > 0 Edited July 13, 2010 by Tophe Share this post Link to post Share on other sites
shuko 59 Posted July 14, 2010 Probably something along these lines. I didnt test it though. checkKnowledge = { private ["_e","_r"]; _r = false; for [{_i=0},{!_r && _i < (count enemyArray - 1)},{_i=_i+1}] do { _e = enemyArray select _i; { if (_e knowsabout _x >= 3) exitwith {_r = true}; } foreach playerArray; }; _r }; trigger cond: call checkKnowledge Share this post Link to post Share on other sites
CarlGustaffa 4 Posted July 14, 2010 Keep in mind that knowAbout is automatically shared within a group, so you only need to consider the group leaders and not every element of the group. Share this post Link to post Share on other sites
shuko 59 Posted July 14, 2010 True, but we don't have a group list of the units unless we make one, which would mean going through them all anyway. I doubt it will improve performance if you add "_e == leader group _e" check. Share this post Link to post Share on other sites
CarlGustaffa 4 Posted July 14, 2010 Probably not (unsure), but building the array using "leader allGroups select _x" (I guess, not tested) instead of building it using "allUnits select _x" would make the actual check be done quicker since it had a lot less units in it. Share this post Link to post Share on other sites
shuko 59 Posted July 14, 2010 Yeah, that came to me while I was away from the computer. However, it's probably better to save the groups instead of leader as he might die and thus be removed from the group. So, we end up still having to go through all of them, at least indirectly because of command leader. enemyGroups = []; { _grp = group _x; if !(_grp in enemyGroups) then { enemyGroups set [count enemyGroups, _grp]; }; } foreach thislist; isDetected = { private ["_e","_r"]; _r = false; for [{_i=0},{!_r && _i < (count enemyArray - 1)},{_i=_i+1}] do { _e = leader (enemyGroups select _i); { if (_e knowsabout _x >= 3) exitwith {_r = true}; } foreach playerArray; }; _r }; call isDetected Share this post Link to post Share on other sites
Jezuro 452 Posted July 14, 2010 {_who = _x; {_who knowsAbout _x > 3} count playerArray > 0} forEach enemyArray Share this post Link to post Share on other sites
CarlGustaffa 4 Posted July 14, 2010 Now that's what I call a sweet one-liner :) Share this post Link to post Share on other sites
shuko 59 Posted July 14, 2010 (edited) But it brings us back to iterating through every single unit. Edit: This at least stops at the first positive check. Edited July 14, 2010 by Shuko Share this post Link to post Share on other sites
Jezuro 452 Posted July 14, 2010 (edited) If it's performance you're concerned about, I'm pretty positive my code is less demanding than calling a function which uses a for-cycle. But I can be wrong of course, whatever works. Edited July 14, 2010 by Jezuro typo Share this post Link to post Share on other sites
shuko 59 Posted July 14, 2010 Could be, but not like you can put your code directly into a trigger condition field without call? So it comes down to for vs foreach and amount of units to go through? Share this post Link to post Share on other sites
Jezuro 452 Posted July 14, 2010 Oh right, Tophe wants to check it in a trigger. My bad. call {{_who = _x; {_who knowsAbout _x > 0} count list a > 0} forEach list b} Now that's maybe a little more demanding, but really, we're talking miliseconds at the most. Share this post Link to post Share on other sites
tophe 69 Posted July 14, 2010 Oh right, Tophe wants to check it in a trigger. My bad. call {{_who = _x; {_who knowsAbout _x > 0} count list a > 0} forEach list b} Now that's maybe a little more demanding, but really, we're talking miliseconds at the most. Thanks alot guys! This is very educating... I've just started working with arrays and it's so much easier to get complex stuff done. It actually seems to work by doing this: {_x knowsAbout ({_x} forEach playerArray) > 0} count enemyArray > 0 I haven't tried it in MP yet though, but the AI in enemyArray do detect me when I am playing. Is that just another way of doing your suggestion Jezuro? Share this post Link to post Share on other sites
Jezuro 452 Posted July 15, 2010 This construct: {_x knowsAbout ({_x} forEach playerArray) > 0} count enemyArray > 0 can be used in scripts or FSMs. call {{_who = _x; {_who knowsAbout _x > 0} count list a > 0} forEach list b} This is totally the same except you can use it directly in a trigger. Share this post Link to post Share on other sites