Home   Help Search Login Register  

Author Topic: Has weapons then... (SOLVED)  (Read 3416 times)

0 Members and 1 Guest are viewing this topic.

Offline Speeder

  • Members
  • *
    • OFP.nu
Has weapons then... (SOLVED)
« 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?
« Last Edit: 31 Aug 2010, 09:48:21 by Speeder »
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline zonker3210

  • Members
  • *
Re: Has weapons then...
« Reply #1 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.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: Has weapons then...
« Reply #2 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.
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline zonker3210

  • Members
  • *
Re: Has weapons then...
« Reply #3 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), 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.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: Has weapons then...
« Reply #4 on: 26 Aug 2010, 14:27:02 »
Most excellent - I guess I misread the code. I'll try and take it from here.
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Speeder

  • Members
  • *
    • OFP.nu
Re: Has weapons then...
« Reply #5 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
There are 10 kinds of people in this world. Those who get it, and those who don't.

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: Has weapons then... (SOLVED)
« Reply #6 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!) :)
Current project: Black Lands (Arma 3)

Offline Ext3rmin4tor

  • Members
  • *
Re: Has weapons then... (SOLVED)
« Reply #7 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.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: Has weapons then... (SOLVED)
« Reply #8 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!
Current project: Black Lands (Arma 3)