OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Speeder on 25 Aug 2010, 16:50:57

Title: Has weapons then... (SOLVED)
Post by: Speeder on 25 Aug 2010, 16:50:57
I've set up 4 men a1-a4 and set the to "setcaptive true".

Now I would like to make a check (repeatetly) to see if the are carrying anything other than satchels. If they pick up a gun or rifle or anythin but a satchel charge, I what to set them to "setcaptive false".

How do I go about doing that?
Title: Re: Has weapons then...
Post by: zonker3210 on 25 Aug 2010, 21:28:06
I'm guessing...

First, set up a repeating trigger to check if the units are captives.

Each time the trigger fires, check the units' inventory to see whether or not they are carrying the desired stuff. I'm not sure whether or not the "hasWeapon" function will return TRUE for parent classes (i.e., if 'myUnit hasWeapon "Pistol"' will return TRUE if the unit is carrying an M9). If not, then perhaps you can do a check to make sure that {a} they are carrying a weapon at all, and {b} they are *not* carrying the type of weapon you don't want them to carry, such as satchel charges. I haven't specifically tested this but I think the following code should be (mostly) correct...

Code: [Select]
{
  if(typeOf _x != "Put")
  {
    { _x setCaptive false; } foreach units grpAllOfMyCaptiveUnits;
  }
} foreach weapons myUnit;


...I'm sure there's a better way but I think that should, at least, get you started. Really, it's a shame you can't use the "isKindOf" function when checking the units' weapons but according to the BI wiki that doesn't work for weapons.
Title: Re: Has weapons then...
Post by: Speeder on 26 Aug 2010, 07:46:40
Except, my units is SETCAPTIVE TRUE because they have no weapon. When they get a weapon (except for satchel charger) they should be SETCAPTIVE FALSE.
Title: Re: Has weapons then...
Post by: zonker3210 on 26 Aug 2010, 14:08:18
Which is exactly the point of my script example. If the review finds a weapon that is *not* a satchel (i.e., the "PUT " weapon class type defined here (http://community.bistudio.com/wiki/ArmA_2:_Weapons#General_Weapons)), then it does the "_x setCaptive false;" for all of the captive units. The script example is based on the assumption that you've already set your units to "captive" status since that's what you said in your first post. The one thing that's quite likely off about my example is the check of weapons...you might need to check magazines instead.
Title: Re: Has weapons then...
Post by: Speeder on 26 Aug 2010, 14:27:02
Most excellent - I guess I misread the code. I'll try and take it from here.
Title: Re: Has weapons then...
Post by: Speeder on 31 Aug 2010, 09:47:36
My solution:
Make trigger.
Condition: (primaryweapon a1 != "") or (secondaryWeapon a1 != "") or (same for a2 a3 and a4)
On act: a1 setcative false; (same for a2 a3 and a4)


This worked for me, in case some one needs it.

SOLVED
Title: Re: Has weapons then... (SOLVED)
Post by: Undeceived on 22 Aug 2011, 18:42:05
Thanks for this simple solution, it is exactly what I was looking for.

Adding to that: When you want the unit to regain captive mode again when he dropped primary- and secondary weapons, you have to create a second trigger and put in its condition:

(primaryweapon unit == "") AND (secondaryWeapon unit == "")

And on act.: unit setcaptive true;


(thanks again!) :)
Title: Re: Has weapons then... (SOLVED)
Post by: Ext3rmin4tor on 23 Aug 2011, 10:09:46
I would modify the condition you wrote into

{getNumber (configFile/"CfgWeapons"/_x/"type") in [1,2,4,5]} count weapons player == 0

because there is not a function which returns the handgun of the player: secondaryWeapon works only for launcher (i.e. all the weapons put in the secondary weapon slot, that is, the bottom one). This is an optional version of the well known "count" function (which counts the element of an array). You can put a condition for an element to be counted. If that condition is not met, the element is not counted.

In this way we obtain the config number for all small arms from the file CfgWeapons and then check if it is 1,2,4 or 5 (I think handguns have config number = 2). If this condition is met, then the element is counted.

This is necessary because that trigger won't fire if you are holding a handgun and it is your only weapon.
Title: Re: Has weapons then... (SOLVED)
Post by: Undeceived on 23 Aug 2011, 13:11:37
Ah, ok, that's great!
I thought that sec. weapon would be the pistol, but I was totally wrong. :)

Thanks for the code!