Home   Help Search Login Register  

Author Topic: AI to join one of several groups  (Read 2318 times)

0 Members and 1 Guest are viewing this topic.

Offline CharlieReddog

  • Members
  • *
AI to join one of several groups
« on: 08 Feb 2008, 17:06:22 »
I'm trying to get a script which will join 3 AI crewmen to which ever of the player controlled groups finds them (distance <5) I can manage it with only 1 group, but there are 4 eligible player groups and obviously only one of them should get the crew to join when they find them.

What's the best way of doing this?

I've continued playing with this.
Trigger Anyone activated.
2 groups of 2 each, grp1 and grp2
1 ungrouped AI c1

Code: [Select]
hint format ["%1",  (list trg_1)-units grp2] returns the correct number of units, ie c1 and 2 units in grp1

Code: [Select]
hint format ["%1",  (list trg_1)] returns all 5 units.

Quote
hint format ["%1",  units grp2 in (list trg_1)]
returns false. How can this be?
« Last Edit: 08 Feb 2008, 18:44:39 by CharlieReddog »

Offline CharlieReddog

  • Members
  • *
Re: AI to join one of several groups
« Reply #1 on: 10 Feb 2008, 02:28:35 »
No one knows the answer to this? Crikey, doesn't bode well. :confused:

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: AI to join one of several groups
« Reply #2 on: 10 Feb 2008, 13:49:07 »
Firstly, let me explain why your technique isn't working (before suggesting a better one):
Code: [Select]
hint format ["%1",  units grp2 in (list trg_1)]

Will never work as you expect it to (will always be false), since the result of "units grp2" is an array and thus will never be within another array, at least as far as in is concerned. If you want to know if two arrays have an overlap like this, you need to use something like count:
Code: [Select]
hint format ["%1",  ({  _x in (list trg_1) } count (units grp2)) > 0]

Which would be true if any of the units in grp2 were currently inside trg_1. Using this method, you'd need to manually check if any member of any of the four player groups were in the trigger area and then join them to the specific group.

A possibly less cumbersome way to do the check might be to link each of the four player groups to the trigger, so that it is only triggered by members of those groups and then to use a simple activation like this:
Code: (trigger activation) [Select]
theCrew join (group (thisList select 0))

Where theCrew is an array of the three AI crewmen that has already been created, say in init.sqf.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CharlieReddog

  • Members
  • *
Re: AI to join one of several groups
« Reply #3 on: 10 Feb 2008, 20:24:28 »
I dn't seem to be able to group the trigger to more than one group at a time.

Also, I know it returns an array, so how is it possible to do (list trg1)-units grp as that's an array v array?

Possibly the best way would be to do count(list trg1)>count(list trg1)-units grp as that would mean that one of that group is in the trigger?


Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: AI to join one of several groups
« Reply #4 on: 11 Feb 2008, 09:29:33 »
Sorry, I'm afraid I generally script everything explicitly, since I find that considerably more maintainable, so I don't use the editor for much beyond placing units myself (So I didn't realise you couldn't link more than one group at once to a trigger).

Certainly, the technique you suggest should work fine (and is probably more efficient than my suggestion of using count). Think that rather answers your question then ;P
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CharlieReddog

  • Members
  • *
Re: AI to join one of several groups
« Reply #5 on: 13 Feb 2008, 19:50:45 »
I'm still having problems with this. I'm playing around in a testbed mission. I have a radio trigger to do the following:

Code: [Select]
hint format["%1",count (list trig1)>count (list trig1-units grp1)] which resolves to false when I'm outside the trig1 and to true when I'm inside trig1.

I tried the following in my init.sqf file, but it doesn't seem to work. Pointers as I'm not really familiar with sqf at all and the comref and Biki on waituntil aren't exactly that comprehensive.
Code: [Select]
waituntil {count (list trig1)>count (list trig1-units grp1)};
hint "Success";

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: AI to join one of several groups
« Reply #6 on: 14 Feb 2008, 14:24:40 »
Why not use your snippet:
Code: [Select]
count (list trig1)>count (list trig1-units grp1)as the sole condition for trig1?

trig1 Condition:
Code: [Select]
count thisList > count (thisList - units grp1)
Why are you putting it in the init.sqf?

Also, I think you can group a trigger with more than one group, the trick is to drag the group line from the trigger to the group, not the other way around i.e. drag group line from trigger to grp1, drag group line from trigger to grp1, etc.
« Last Edit: 14 Feb 2008, 14:28:28 by Mr.Peanut »
urp!

Offline CharlieReddog

  • Members
  • *
Re: AI to join one of several groups
« Reply #7 on: 15 Feb 2008, 11:45:08 »
I was putting it in the init.sqf for two reasons, 1 I couldn't get it to work as a condition of trigger, but now I can :confused:, and 2 I was experimenting with the waituntil code. :blink:

Also, I think you can group a trigger with more than one group, the trick is to drag the group line from the trigger to the group, not the other way around i.e. drag group line from trigger to grp1, drag group line from trigger to grp1, etc.

Aha. That wasn't what I was doing, I was dragging from the group to the trigger. I'll have to try that, thanks.