Home   Help Search Login Register  

Author Topic: Spotter to detect certain named groups only (SOLVED)  (Read 3809 times)

0 Members and 1 Guest are viewing this topic.

Offline mrcash2008

  • Members
  • *
I have 2 spotters generated randomly on a map, they are simply there to set a variable true if they spot bluefor. Then a trigger runs if both 2 variables = true (each spotter has a variable each).

I dont want the spotters to use the general "bluefor" detect becuase thats any bluefore on the map (Dont want them spotting bluefor helis/UAV) I know thats not so realistic but its what Im trying in a mission (spotters are only interested in looking out for certain ground troops). I only want them each to enable a variable if they spot/detect certain bluefore groupname(s).

So how do I/whats the syntax for the condition for group names? (Or scripts to run.)

Im slowly getting up to speed and all groups are named (I have 3 SF teams Alpha, bravo, delta) im just not sure specific line to add to trigger condition for all three groups.

Something like:


Quote
_this (group names) detected


(I have no clue what "detected" would be code wise or how to list the group names).

Anyone? Thanks in advance if you can plant the seed or add a pointer. Ive searched here & BI forum and also checked the editing guide but have nothing specific to what im after.
« Last Edit: 19 Sep 2008, 00:31:35 by mrcash2008 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Spotter to detect certain named groups only
« Reply #1 on: 13 Sep 2008, 22:52:20 »
Might be you would prefer to run a script server side instead of using trigger:
Code: [Select]
// Array of spotters
_spotters = _this select 0;
// Array of enemy groups
_groups = _this select 1;
_detected = false;
while {!_detected} do
{
   {
      for [{_i=0},{(_i < count _groups) && !_detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !_detected},{_j=_i+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               _detected = true;
            };
         };
      };
   } forEach _spotters;
};

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #2 on: 13 Sep 2008, 23:06:54 »
I need some spoon feeding here so here goes :

Quote
_spotters = _this select 0;

In this case "_spotters" = the name fields of my two spotters? IE "spotter1" "spotter2" ... do they replace "_this"  ... how do i enter in this line, is it much like the array syntax used in your reinforcements section of mondo bombs?

Quote
_groups = _this select 1;

Is it the same for "_groups" IE: the group names of my three bluefor teams (alpha/bravo/delta) as the same array?

Quote
_detected = true;

Im guessing then in my game trigger I simply add in the condition line "_detected" which will activate as its now = true (exists) right?

(or am i taking it too literal and this variable name can be called anything anyway).

Im also running this all SP play, so do I call this script via each spotter in-gmae, or do I simply add this to my init, i guess this runs globaly?

EDIT:

Quote
// Array of spotters
_spotters = ["spotter1","spotter2"]; select 0;
// Array of enemy groups
_groups = ["alpha","bravo","charlie"]; select 1;
detected = false;
while {!detected} do
{
   {
      for [{_i=0},{(_i < count _groups) && !detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !detected},{_j=_i+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               detected = true;
            };
         };
      };
   } forEach _spotters;
};

I set trigger in game condition "detected" ... even though spotters are far from any units this gets set to true anyway no matter what on mission start (running in init).


ALso I did find this script which uses a range and dynamic trigger for spotter you posted some months ago :

http://www.ofpec.com/forum/index.php?topic=30935.0

I was wondering how this aproach could be implemented with what I already have here so I can still specify an array of units?
« Last Edit: 14 Sep 2008, 00:13:48 by mrcash2008 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Spotter to detect certain named groups only
« Reply #3 on: 14 Sep 2008, 10:51:19 »
Code: [Select]
// mrcash_spotters.sqf
// Execute it from init.sqf

if (!isServer) exitWith {};
Sleep 10;
// Array of spotters
_spotters = [spotter1,spotter2];
// Array of enemy groups
_groups = [alpha,bravo,charlie];
mrcash_detected = false;
while {!mrcash_detected} do
{
   {
      for [{_i=0},{(_i < count _groups) && !mrcash_detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !mrcash_detected},{_j=_j+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               if (alive (vehicle (units (_groups select _i) select _j)) then
               {
                  mrcash_detected = true;
               };
            };
            Sleep 0.25;
         };
      };
   } forEach _spotters;
   Sleep 3;
};

You may use mrcash_detected as the condition for a trigger that executes something else.

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #4 on: 14 Sep 2008, 17:03:47 »
Thankyou for helping on this first of all  :good:

Ok I wiped out my init.sqf to test this. So I block copied the script as-in into my init and saved.

I then named my groups by adding
Quote
alpha = group this;
and then bravo/charlie the same for other teams. I then named my single spotters as "spotter1" & "spotter2" in the name field for each of these. then set my trigger to exec on "mrcash_detected".

I saved, quite, reloaded and then played, and I get 2 lots of errors .. these are (I re loaded a few times to double check first) :



and ...



Any ideas, this happens literaly on start up of the mission.

So not to confuse if I copied things correctly, here a direct paste out of my init of your code:

Code: [Select]
// mrcash_spotters.sqf
// Execute it from init.sqf

if (!isServer) exitWith {};
Sleep 10;
// Array of spotters
_spotters = [spotter1,spotter2];
// Array of enemy groups
_groups = [alpha,bravo,charlie];
mrcash_detected = false;
while {!mrcash_detected} do
{
   {
      for [{_i=0},{(_i < count _groups) && !mrcash_detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !mrcash_detected},{_j=_j+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               if (alive (vehicle (units (_groups select _i) select _j)) then
               {
                  mrcash_detected = true;
               };
            };
            Sleep 0.25;
         };
      };
   } forEach _spotters;
   Sleep 3;
};


« Last Edit: 14 Sep 2008, 17:31:28 by mrcash2008 »

Offline nuxil

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #5 on: 14 Sep 2008, 18:09:47 »
The error tells you whats wrong,

example you are missing one ) in this line
Code: [Select]
if (alive (vehicle (units (_groups select _i) select _j)) then


Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #6 on: 14 Sep 2008, 20:08:33 »
Ok  :D obvious isnt always the case with code, I added the extra ")" at the end of the line and all working well thanks & thanks mandoble  :good:

I still have another problem though ....  :scratch:

I actualy want it so that each spotter executes a variable of there own, currently this works whereas any spotter will make it true if they spot whoever is in the array, but I actualy want it so "each" spotter sets its own variable true so my trigger would activate based on condition 
Quote
spotter1_detect && spotter2_detect
....

The reason is I want it to be random whether im spotted (each spotter is using patrol script with random placement on map) and also more random that it will take more than one spotter seeing any of the group array names to set the trigger.

This will work for me as is, I tried activating as "_this" than array via the executing under spotter itself and then setting variable separate and making 2 .sqf files and running for each spotter but it just threw up more errors.

If ther is a neat way to do this as this global script that would be great rather than lots of triggers.

I think my norrowed down question is, "How can I tie an individual variable to each spotter to set true, or how can I implement so this is ran via each spotter to do this?".

« Last Edit: 14 Sep 2008, 20:16:32 by mrcash2008 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Spotter to detect certain named groups only
« Reply #7 on: 14 Sep 2008, 20:24:54 »
Code: [Select]
/* mrcash_spotters.sqf
Parameters:
    Array of spotters
    Array of groups to spot
    name of global var to set to true if there is a positive detection as string (between "").

Execute it from init.sqf
*/

private ["_detected", "_i", "_j", "_groups", "_spotters", "_varname", "_alldead"];
_groups = _this select 0;
_spotters = _this select 1;
_varname = _this select 2;


if (!isServer) exitWith {};
Sleep 10;
_detected = false;
_alldead = false;
call compile format["%1=false;", _varname];
while {!_detected && !_alldead} do
{
   {
      for [{_i=0},{(_i < count _groups) && !_detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !_detected},{_j=_j+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               if (alive (vehicle (units (_groups select _i) select _j)) then
               {
                  _detected = true;
               };
            };
            Sleep 0.25;
         };
      };
   } forEach _spotters;

   if (({alive _x} count _spotters) == 0) then
   {
      _alldead = true;
   };
   Sleep 3;
};

if (!_alldead) then
{
   call compile format["%1=true;", _varname];
};

Code: [Select]
// init.sqf
// Two arrays of spotters (a single spotter per array)
[[spotter1], [alpha,bravo,charlie], "spotter1_saw_something"]execVM"mrcash_spotters.sqf";
[[spotter2], [alpha,bravo,charlie], "spotter2_saw_something"]execVM"mrcash_spotters.sqf";

Then you may check spotter1_saw_something and spotter2_saw_something global vars in a trigger to see if spotter1 OR spotter2 have detected someone in the indicated enemy groups.

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #8 on: 15 Sep 2008, 02:01:10 »
Great thankyou ... Im still getting an error and trying to "learn" what it is ... so im guessing, but here goes  ... :-[

The error i get:



I changed things slightly with naming so I have this in init:

Code: [Select]
// Two arrays of spotters (a single spotter per array)

[[spotter1], [alpha,bravo,charlie], "spotter1_saw"]execVM"spotter.sqf";
[[spotter2], [alpha,bravo,charlie], "spotter2_saw"]execVM"spotter.sqf";

Then in spotter.sqf i have:

Code: [Select]
/* mrcash_spotters.sqf
Parameters:
    Array of spotters
    Array of groups to spot
    name of global var to set to true if there is a positive detection as string (between "").

Execute it from init.sqf
*/

private ["_detected", "_i", "_j", "_groups", "_spotters", "_varname", "_alldead"];
_groups = _this select 0;
_spotters = _this select 1;
_varname = _this select 2;


if (!isServer) exitWith {};
Sleep 10;
_detected = false;
_alldead = false;
call compile format["%1=false;", _varname];
while {!_detected && !_alldead} do
{
   {
      for [{_i=0},{(_i < count _groups) && !_detected},{_i=_i+1}] do
      {
         for [{_j=0},{(_j < count units (_groups select _i))  && !_detected},{_j=_j+1}] do
         {
            if (_x knowsAbout vehicle (units (_groups select _i) select _j) > 0) then
            {
               if (alive (vehicle (units (_groups select _i) select _j))) then
               {
                  _detected = true;
               };
            };
            Sleep 0.25;
         };
      };
   } forEach _spotters;

   if (({alive _x} count _spotters) == 0) then
   {
      _alldead = true;
   };
   Sleep 3;
};

if (!_alldead) then
{
   call compile format["%1=true;", _varname];
};

As you might notice The line:

Quote
if (alive (vehicle (units (_groups select _i) select _j))) then

I changed due to the same error from a post further up on the previouse code which was:

Quote
error missing )


so I adding this missing ")" on that line which resolves that error, as it also did in the previous code.

I notice the new error with this new code is
Quote
type group, object expected


the group in this line = _spotters now as before both my spotters Im using have "spotter1" and "spotter2" in the name field so I assume as before this should be enough, so why is it suggesting some thing should be "expected" here? Is it that the spotter names arent being detected or something causing me to look in the wrong place? Or is it that the adding of the addition ")" on that line is now throwing the script?




« Last Edit: 15 Sep 2008, 02:09:19 by mrcash2008 »

Offline nuxil

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #9 on: 15 Sep 2008, 02:33:20 »
i not tested your code but it seams like your running the magical variable _x outside a foreach loop
Code: [Select]
while
{
   {
       _x bla bla
   } foreach spotters

   if (({alive _x} count _spotters) == 0) then
   {
      _alldead = true;
   };
};

i think thats why you are getting this error.

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #10 on: 15 Sep 2008, 13:24:40 »
Ok its in the guts of the script then, well as I cant understand areas of that script (i can read it parrot fashion buts thats all) and _x value  :dunno: and where it should be placed, plus how to re-jig things, can someone show me how that should be rectified please  :good:

As you can tell im half way into scripting and half way back out at the same time  :-[

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Spotter to detect certain named groups only
« Reply #11 on: 15 Sep 2008, 13:56:40 »
I'll try to test it this afternoon, so far it was written without ArmA.

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only
« Reply #12 on: 18 Sep 2008, 12:31:01 »
Hello again, I tried some trigger ideas to get this to work, but its too limited and a global script solution would be the best Ive ended up holding out a mission to see if I can get this puppy implemented (then used on other missions too) opens alot of possibilities for me and new ideas to spawn from it (excuse the pun)  :P

Anyway I have learned never to bite the hand that feeds you, and I respect the fact you chaps are doing this for free and in your own time too. So I thought I clock back in and just ask Mandoble if you have had a peep at this running live within arma to iron out that error to re-jig and have it working fully  :cool2:?

I was thinking of then making a demo mission of some kind and maybe its worth a submit into the depot  :scratch:? Just seems that if its working fully its quite an open script and usefull in say sniper missions or "intel" / informants (maybe used for civvies) who may rat on your presence etc.

Anyway .. any update or fix on this would be cool, then i can wrap up this mission I have, cant thank enough the help so far. I started fully searching this forum and found many other gems to plant the seed too.  :good:

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Spotter to detect certain named groups only
« Reply #13 on: 18 Sep 2008, 22:11:39 »
Sorry for the delay, see attached mission.

Offline mrcash2008

  • Members
  • *
Re: Spotter to detect certain named groups only (SOLVED)
« Reply #14 on: 19 Sep 2008, 00:34:35 »
Thank you very much indeed  :clap: :good:

All works a treat and implemented into mission, much more fun for random trigger situations ;)

It seems as always, above and beyond the call of duty with your help.

I will stick around here more often and be a lot more trigger happy on the search button too.