Jump to content
Sign in to follow this  
Undeceived

Check if unit has weapons but exlude items, binoculars and NVGoggles

Recommended Posts

Hello guys, could you help me with that:

I want to create a script which checks if the unit has a weapon (any weapon). If the player has a weapon then setcaptive will go false.

So far, so easy. :D

But the script should only see deadly weapons like rifles, pistols, launchers, etc.

It should not detect unlethal "weapons" like Binocular, NVGoggles or the items (ItemMap, ItemGPS, ItemRadio and ItemCompass).

So how can I exclude these undeadly ones from the weapons check?

Thanks for your help!

EDIT:

This is what I want to achieve in the end:

- The player (a civilian in the group of a resistance unit that has probably of presence = 0%) has a gun and peaks behind a corner of a house and sees an enemy. The enemy still hasn't seen the player. So the player can drop down his gun (or "holster it with Celery's holster script - which removes it too) and go out of the cover without being suspicious for the enemy. In the eyes of the enemy he is just a harmless civilian.

- But if the player is seen by the enemy unit with a gun in his hands, he will be known as enemy in the region (e.g. village) where he is at the moment.

- On the other side, if the player (who is now known as enemy) can escape the village and goes to another village, I want that the enemy in village 2 doesn't know that he is enemy in village 1.

Edited by Undeceived

Share this post


Link to post
Share on other sites

Give this a whirl. It checks both weapons and magazines in case your players try to get sneaky and hide a grenade. Note that this is a one-time thing, meaning once a player picks up a weapon or magazine the setcaptive will be gone for good. You will need to modify it if you want the player to be able to regain captive again by dropping all of their weapons and magazines.

if (isdedicated) exitwith {};

_guy = _this select 0;

_captive = true;

_safeweapons = ["ItemRadio","ItemMap","ItemCompass","ItemGPS","ItemWatch","NVGoggles","Binocular"];

_safemagazines = [];

while {_captive} do {

if !({_x in _safeweapons} foreach (weapons _guy)) then {

_captive = false;

};

if !({_x in _safemagazines} foreach (magazines _guy)) then {

_captive = false;

};

sleep 1;

};

_guy setcaptive false;

Share this post


Link to post
Share on other sites

Great, Strikor! This works!! :)

I removed the magazines part of your script because I want to make it possible for the player to have hidden mags or grenades. Only visible weapons should effect the loss of the setcaptive.

Thanks a lot so far!

Well, I would modify it further if I could, but I fear that my logical thinking abilities are everything but not sufficient for coding... :o

How would it look like after the first part that you already gave me, if I want to make it possible for the player to regain captive mode again, when he drops his weapons and the enemy has no sight of him?

Maybe something like:

If ((player drops all visible weapons, except the _safeweapons and magazines) AND (the enemy doesn't know about him)) then {

player setcaptive true;
go to first part of the script again;

};

:D :D

Thanks a lot for your help!

---------- Post added at 06:54 PM ---------- Previous post was at 05:11 PM ----------

I found another approach in the OFPEC forums - it's quite simple but does the job (at least I didn't discover any disadvantage):

Create a trigger and put in its condition field:

(primaryweapon player != "") or (secondaryWeapon player != "")

On activation:

player setcaptive false;

Then I tried and got a solution for the second part (set the player captive again when he drops the weapons):

Create a second trigger and put in its condition field:

(primaryweapon player == "") AND (secondaryWeapon player == "")

On activation: player setcaptive true;

Now I only need to implement the part that the enemy has to lose him out of their sight / mind for the setcaptive true part to take effect...

I guess that it would look something like:

Condition field of the second trigger:

((primaryweapon player == "") AND (secondaryWeapon player == "")) AND (enemy knows about player 0)

Or something like that... (?) :)

Share this post


Link to post
Share on other sites

I believe secondaryweapon is the launcher slot, so that wouldn't detect pistols. Anyway here is what I came up with. It's written as multiplayer scripting so it might be a little more complicated than it needs to be in your case, but it should still work. I used a check for east units within 500m rather than a detection check because I simply don't trust the AI. I also added an event handler to remove captive if a player throws something like a grenade.

_guy = _this select 0;

_safeweapons = ["ItemRadio","ItemMap","ItemCompass","ItemGPS","ItemWatch","NVGoggles","Binocular"];

_guy addeventhandler ["fired", {if (_this select 1 == "throw") then {(_this select 0) setcaptive false}}];

while {alive _guy} do {

while {captive _guy} do {

if !({_x in _safeweapons} foreach (weapons _guy)) then {

_guy setcaptive false;

};

sleep 1;

};

while {side _guy == west} do {

_red = 0;

_list1= position _guy nearObjects ["SoldierEB",500];

{if ((side _x) == east) then {_red = _red + 1};} forEach _list1;

if (_red < 1) then {

if ({_x in _safeweapons} foreach (weapons _guy)) then {

_guy setcaptive true;

};

};

sleep 10;

};

};

Share this post


Link to post
Share on other sites

It works, I'm impressed, Strikor!! Thanks a lot. :)

Only the 500 meters feature doesn't fit completely in my scenario.

I want to make possible the following situations:

- The player (a civilian in the group of a resistance unit that has probably of presence = 0%) has a gun and peaks behind a corner of a house and sees an enemy. The enemy still hasn't seen the player. So the player can drop down his gun (or "holster it with Celery's holster script - which removes it too) and go out of the cover without being suspicious for the enemy. In the eyes of the enemy he is just a harmless civilian.

- But if the player is seen by the enemy unit with a gun in his hands, he will be known as enemy in the region (e.g. village) where he is at the moment.

- On the other side, if the player (who is now known as enemy) can escape the village and goes to another village, I want that the enemy in village 2 doesn't know that he is enemy in village 1.

I think that this way we will have to work with detection, yes.

But I was wrong with the "Detected by East" thing, because if whole East knowsabout player, the Russians in village 2 will also immideately shoot the player.

Is it possible instead to implement "Detected only by soldiers of village 1" whereas village 2 is still friendly to the player?

Again - thank you very much for your help so far!

Edited by Undeceived

Share this post


Link to post
Share on other sites

Can you or someone demonstrate a quick sample mission utilizing this script please? I would very much like to see how this works but I am having a hard time doing it myself as my mission creating scripting skills are rather limited. Thank you in advance

Share this post


Link to post
Share on other sites

You could try looping over all "weapons player" and check inheritance:

inheritsFrom (configFile >> "CfgWeapons" >> _obj)

returns:

bin\config.bin/CfgWeapons/Pistol for pistols

bin\config.bin/CfgWeapons/Default for binoculars

bin\config.bin/CfgWeapons/ItemCore for radio

You might also check "magazines player" and look for handgrenades the same way.

inheritsFrom (configFile >> "CfgMagazines" >> _obj)

returns:

bin\config.bin/CfgMagazines/CA_Magazine

Edit: Oh just noticed it's a bit dug up thread :p Sorry, can't do the mission, as it's not something I've had use for myself.

Share this post


Link to post
Share on other sites

Hey I'm using your script Striker but for Arma 3 and am attempting to add another condition to setCaptive false; I have a gamelogic named "powCamp" and I want the each individual player to become setCaptive false if they leave 45 meters from the gamelogic. so I have "_unit distance powCamp > 45;" but not sure where to put it, I've tried this:

while {alive _unit} do {

while {captive _unit} do {

if ((_unit distance powCamp > 45) || (!({_x in _safeweapons} foreach (weapons _unit))) then {

_unit setcaptive false;

};

but it's not working, any idea what else I should try or where to put it?

Share this post


Link to post
Share on other sites

I am seeing these scripts I had an similar idea. And I would like to implement this script on my mission. What I want to achieve is that seven BLUFOR infiltrate enemy territory (OPFOR), dressed as civilians, and with a gun in his uniform and if one of they pull out gun of the uniform and have in hand, the OPFOR detect the BLUFOR they are enemies. I would also like to do is if they put back the guns in uniform, true setcaptive (not enemy again). apology for my English (google translate). I appreciate the help. Greetings from Argentina

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×