Jump to content
Sign in to follow this  
Koni

Detect if a unit has any weapon

Recommended Posts

I know how to define if a unit has a certain weapon, like unit hasweapon "AK_74", but how can you detect if a unit has any weapon at all, be it a rifle or pistol ?

Only thing I can find from searching is the hasweapon "weaponname" which I know about, but I could do with a way that includes any weapon.

Thanks

Share this post


Link to post
Share on other sites

Maybe like this?

_Primary = primaryWeapon UnitName;
_Secondary = secondaryWeapon UnitName;

if (_Primary == "") then {
hint "No Rifle.";
};

if (_Secondary == "") then {
hint "No Pistol.";
};

if (_Primary == "" && _Secondary == "") then {
hint "No Rifle AND no Pistol.";
};

Share this post


Link to post
Share on other sites

I don't really get how I impliment this.

What condition would I use to execute this as a script ?

If I use in a trigger condition

player hasweapon "weaponName"

then I can use anything as the On Activation as it's a straight forward condition, but how would I use what you put as a condition ?

If I try and use your suggestion as a script, I still need to set a condition that has to be met to execute it, or am I really missing something very obvious ?

What I need is something like unitName hasWeapon "" where a weapon name does not have to be listed.

I've tried

_Primary = primaryWeapon player; but that didn't work.

Thanks

Share this post


Link to post
Share on other sites

Depends a bit on the purpose for this...

You can set a variable to true for example:

Init.sqf:

execVM "WeaponCheck.sqf";

WeaponCheck.sqf:

_Primary = primaryWeapon player;
_Secondary = secondaryWeapon player;

if (_Primary == "") then {
NoRifle = true;
};

if (_Secondary == "") then {
NoPistol = true;
};

Now you can use it with a trigger...

Condition:

[b]NoRifle && NoPistol[/b]

But if you're going to use it with multiple units we have to do something different... And if you're going to use it more than once during the mission too. Please describe the purpose of it. :)

Share this post


Link to post
Share on other sites

Player gets captured, weapons removed, then needs to detect if player gets any weapon again, then triggers other things.

So it would end up like

TriggerActivated triggerName AND player hasweapon "anyWeapon"

Share this post


Link to post
Share on other sites

Then use this as trigger condition:

TriggerActivated triggerName && (!(primaryWeapon player == "") || !(secondaryWeapon player == ""))

It will fire up when triggerName activated AND player has rifle OR pistol. :)

Share this post


Link to post
Share on other sites
Then use this as trigger condition:

TriggerActivated triggerName && (!(primaryWeapon player == "") || !(secondaryWeapon player == ""))

It will fire up when triggerName activated AND player has rifle OR pistol. :)

Thanks sxp2high.

That works fine for the primary weapon, but does not detect just a secondary pistol.

@Buliwyf this works perfectly, thanks

Share this post


Link to post
Share on other sites

Secondary weapon is for launchers, not handguns. AFAIK there is no command for handguns.

#define LEGAL_WEAPON_TYPES [4096,131072]

// place this function into a variable, ex:  weaponCheckFunction = compile preprocessFile "thisscript.sqf"
// then for checking if soldier1 has weapons use: [soldier1] call weaponCheckFunction;

_target = _this select 0;
_weapons = weapons _target;

_hasWeapon = false;

if ((count _weapons) > 0) then
{
	{
	if !(getNumber(configFile >> "CfgWeapons" >> _x >> "type") in LEGAL_WEAPON_TYPES) exitWith
	{
		_hasWeapon = true;
	};
} forEach _weapons;
};

// check if grenade is selected (since it is a magazine and not a weapon it will not be detected by the above part)

if (currentWeapon _target == "Throw") then
{
_hasWeapon = true;
};

// check if target is in a combat vehicle, so vehicle weapons will count too! Combat vehicle here is a vehicle that has a gunner seat.

if (((vehicle _target) != _target) && (vehicle _target emptyPositions "gunner" > 0 || (!isNull (gunner (vehicle _target))))) then
{
_hasWeapon = true;
};

_hasWeapon

Share this post


Link to post
Share on other sites

Its easy to check for pistols, its not that many:

_list_of_Pistols = ["pistolclassname1","pistolclassname2","etc"];  // add here all classsnames of pistols/handguns etc..
if ( ( {_x in _list_of_Pistols} count (weapons _unit) ) != 0) then {hint "_unit have a pistol"};

Share this post


Link to post
Share on other sites

Yes, if you play without mods. If you do, then this solution isn't very feasible.

Share this post


Link to post
Share on other sites

_ispistol = getNumber (configFile >> "CfgWeapons" >> classname >> "Type") == 2;

Replace classname with a weapon class name.

Xeno

Share this post


Link to post
Share on other sites

This returns true if the player has any kind of small arm.

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

Share this post


Link to post
Share on other sites

How would you also include grenades, RPGs, satchels, ACE claymores, etc?

Share this post


Link to post
Share on other sites
How would you also include grenades, RPGs, satchels, ACE claymores, etc?

I have a feeling that actual wieldable small arms are what's up:

Player gets captured, weapons removed, then needs to detect if player gets any weapon again, then triggers other things.

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  

×