sphoenix 11 Posted June 28, 2007 Hi everybody Is there a way to know when a unit spots an enemy, and to return the name of this enemy? I'd like to use that to put a marker on the map upon spotting, automatically. Thank you very much! Kindly SPhoenix Share this post Link to post Share on other sites
sphoenix 11 Posted June 28, 2007 I know about this function but its use is rather erratic. I mean, I'd have to write a line for each friendly unit, and this multiplied by the number of enemy units... ...aren't I right? Is there no other way? Share this post Link to post Share on other sites
Taurus 20 Posted June 28, 2007 You can do it by using arrays, or units in a trigger. I'll post an example if you need me to, I'm too tired now sorry, Share this post Link to post Share on other sites
sphoenix 11 Posted June 28, 2007 No it's ok, I know how to do it myself Thanks I was hoping there was another way, because this way will be very resource-taking. And I don't like it. Anyways... Thanks for the help Kindly SPhoenix Share this post Link to post Share on other sites
5133p39 16 Posted June 28, 2007 Maybe you could use nearTargets. Share this post Link to post Share on other sites
sphoenix 11 Posted June 28, 2007 Hmm, I'm not sure... As I said the point would be to put a marker on the map of the location of the spotted enemy. The nearTargets tool doesn't seem to fulfill the same function, or more clumsily. Share this post Link to post Share on other sites
5133p39 16 Posted June 28, 2007 Hmm, I'm not sure...As I said the point would be to put a marker on the map of the location of the spotted enemy. The nearTargets tool doesn't seem to fulfill the same function, or more clumsily. Well, the nearTargets returns all potential targets the unit's group knows about. You need only to filter the objects/units which side it lists as unknown, civilian, and friendlies - the rest is array of enemies. Then you can easily create/position markers, either on the perceived position which is returned by the nearTargets, or on the exact position of the unit, which you can easily find with getPos. I really don't see any problem here, i think it does exactly what you need. Of course an event handler "enemy_spotted" would be much better, but unfortunately it doesn't exist I think the nearTargets is the best way available to achieve your goal. Share this post Link to post Share on other sites
sphoenix 11 Posted June 29, 2007 Very true. I'll look into it ASAP. Thanks a lot man Share this post Link to post Share on other sites
sphoenix 11 Posted June 29, 2007 I'll be requiring your help once again. This is my script: P01, ... , P07 are units. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#debut; Array01 = P01 nearTargets 100; Array02 = P02 nearTargets 100; Array03 = P03 nearTargets 200; Array04 = P04 nearTargets 100; Array05 = P05 nearTargets 200; Array06 = P06 nearTargets 200; Array07 = P07 nearTargets 100; ArrayEnnemis = [Array01, Array02, Array03, Array04, Array05, Array06, Array07]; { { CampEnnemi = _x select 3; if (CampEnnemi == EAST) then { Ennemi_x = createMarker ["", _x select 1]; Ennemi_x setMarkerShape "ICON"; Ennemi_x setMarkerType "Dot"; Ennemi_x setMarkerColor "ColorRed" }; } forEach _x; } forEach Array; ~30 goto "debut"; I don't know what's wrong; I know my coding's a little clumsy but that's all I have. It says there is a { missing before the forEach _x... Share this post Link to post Share on other sites
5133p39 16 Posted June 29, 2007 I don't know what's wrong; I know my coding's a little clumsy but that's all I have.It says there is a { missing before the forEach _x... 1. First of all, it seems you are using SQF script (which is good), but then there is a "goto" command which (if i am not mistaken) doesn't work in SQF scripts. Instead of the "goto", put everything in a "while" loop, and also replace the pause "~30" with command "sleep 30". Or maybe you are using SQS, which needs the entire forEach block on single line, and hence the error you are getting. 2. in the main forEach loop, you are using variable 'Array' which doesn't exists - you want to use 'ArrayEnnemis' instead. 3. i think the "name" parameter for the "createMarker" command, MUST be supplied. But then again - i can be wrong. Here is how i would wrote it (as an SQF script):<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_i","_m","_oldI"]; _oldI = 0; while {true} do { Array01 = P01 nearTargets 100; Array02 = P02 nearTargets 100; Array03 = P03 nearTargets 200; Array04 = P04 nearTargets 100; Array05 = P05 nearTargets 200; Array06 = P06 nearTargets 200; Array07 = P07 nearTargets 100; ArrayEnnemis = [Array01, Array02, Array03, Array04, Array05, Array06, Array07]; _i = 0; { { CampEnnemi = _x select 3; if (CampEnnemi == EAST) then { _m = format ["mark%1", _i]; // create marker if _m not exists, otherwise only setpos the existing one if ((getMarkerPos _m) select 0 == 0) then { _m = createMarker [_m, _x select 1]; _m setMarkerShape "ICON"; _m setMarkerType "Dot"; _m setMarkerColor "ColorRed"; } else { _m setMarkerPos (_x select 1); }; _i = _i + 1; }; } forEach _x; } forEach ArrayEnnemis; // delete markers of old, forgotten targets while {_oldI >= _i} do { _m = format ["mark%1", _oldI]; if ((getMarkerPos _m) select 0 != 0) then { deleteMarker _m; }; _oldI = _oldI - 1; }; _oldI = _i; sleep 30; }; I haven't tested it, so watch out for errors. Share this post Link to post Share on other sites
sphoenix 11 Posted June 29, 2007 A huge Hooah to you! Thank you very much! Everything works perfectly! You just had a problem in the selects (1 instead of 0, 3 instead of 2 but it's no big deal) Thank you again for your help and time! You'll have your name in the credits ^_^ You're a good scripter. My mistake was to mix SQF and SQS... originally this was an SQS script ^^ Have a good day SPhoenix Share this post Link to post Share on other sites
johnnyboy 3797 Posted June 29, 2007 SPheonix, how about posting your working script so we can benefit from it? If you can, mention how to use it too, like is it run from a trigger, or whatever. Thanks. Also, a question: Are P01, P02, etc., units or groups? The nearTargets command accepts a unit as its input, but since it appears to show only targets that the unit KnowsAbout, and Knowsabout is group knowledge (not unit specific knowledge), I'm wondering if your script only needs to check nearTargets for the each group leader, rather than for every unit? This could improve performance. For your Markers usage, you want all known units once to mark their location, so limiting checks to group leaders should work. For other usages, like finding targets within 50 meters of a particular unit, limiting check to group leader would not be good, as leader might be hundreds of meters away from particular unit. Share this post Link to post Share on other sites
sphoenix 11 Posted June 29, 2007 I refer to P01 as units; but actually P01 is the variable attached to the group leader. Someone (I don't remember who, it's on the BIki) noticed that the knowsAbout value was the same for all members of a same group. So indeed, it only checks the targets of the group leader Quote[/b] ]For other usages, like finding targets within 50 meters of a particular unit, limiting check to group leader would not be good, as leader might be hundreds of meters away from particular unit. It depends. If we're talking, just as it is in my mission, about AI groups then checking only the group leader is a good idea because he never breaks the formation, or not as much as you said. If we're talking about a human-made group, then we could have a problem; but you could very well adjust the range (i.e. instead of 100 meters or 200 meters, 10000 meters) of the nearTargets function. And it would include your lonewolf. I'll release the script Kindly SPhoenix Share this post Link to post Share on other sites