Jump to content
Sign in to follow this  
galzohar

PrimaryWeapon, SecondaryWeapn and what about sidearms?...

Recommended Posts

I want to have a script detect whether a unit has any weapon at all. Using (primaryWeapon _unit != "" || secondaryWeapon _unit != "") would only detect a main weapon and rifles, but afaik would not detect a sidearm. Am I just missing the command that checks for the unit's sidearm or is a dirty hack needed to get around that?

Share this post


Link to post
Share on other sites

Dirty hack it is!

_unit = player;

// Function for pistol data - by Spooner
isPistol =
{
private ["_isPistol","_unknownConfig","_unknownWeaponClass","_pistolConfig"];
_unknownWeaponClass = _this select 0;

_unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;
_pistolConfig = configFile >> "CfgWeapons" >> "PistolCore";

_isPistol = false;
while {isClass _unknownConfig} do
{
    if (_unknownConfig == _pistolConfig) exitWith
    {
        _isPistol = true;
    };

    _unknownConfig = inheritsFrom _unknownConfig;
};

_isPistol; // Return.
};

// Do we have a pistol?
_items = items _unit;
_weaps = (weapons _unit) - _items;
_pistol = "";

// Check weapons for pistols.
if (!(_weaps select 0 == "")) then {
for [{_i = 0}, {_i < count _weaps}, {_i = _i + 1}] do {
	_weap = _weaps select _i;
	if ([_weap] call isPistol) then {_pistol = _weap};
};				
};

// Display result
if (_pistol == "") then {
hint "No sidearm found!";
} else {
hint format["We're rocking a %1 up in here!", getText (configFile >> "CfgWeapons" >> _pistol >> "displayname")];
};

There's also some kind of weapon class check, 1, 2, 3, 4... something I found last night but have since lost. :)

Edited by kylania
Fixed script order.

Share this post


Link to post
Share on other sites

To help the new guy, might want to let him know that the isPistol function should be declared before the main script is run. ;)

Share this post


Link to post
Share on other sites
To help the new guy, might want to let him know that the isPistol function should be declared before the main script is run. ;)

I thought it was supposed to be declared before, but it seems to work? Was looking all cluttery at the top! heh

The cleanest solution would be to have the function in it's own file and just #include it?

Share this post


Link to post
Share on other sites

I think it "works" because you get an error the first time it is run, but after that the function is defined and thus works. Cleanest would be to define the function once at the start of the mission rather than re-defining it every time the script runs.

Anyway, something even more simple would be to instead just check if the (weapons _unit)-(items _unit) array is empty or not, since after all the purpose is to check if the unit has any weapons, but using the weapons array includes some items as well. Hopefully I'm not missing anything and you can't kill anyone with any item in ACE.

---------- Post added at 04:05 AM ---------- Previous post was at 03:48 AM ----------

(weapons _unit)-(items _unit) doesn't work, binoculars count as a weapon but not an item, need to go back to dirty fixes :(

Share this post


Link to post
Share on other sites

Nevermind

---------- Post added at 02:25 PM ---------- Previous post was at 02:19 PM ----------

_pistol = {if (tolower(getText(configFile/"CfgWeapons"/_x/"nameSound")) == "Pistol") exitwith {_x};nil} foreach (weapons player);
if (isnil "_pistol") then {hint "no pistol";} else {hint ("you have an " + _pistol);};

Since they all inherit from the pistol class. :rolleyes:

Thanks to http://browser.dev-heaven.net/cfg_weapons/config/glock17_EP1?version=27 for allowing me to find a value that was inherited from the pistol class, and pretty much is consistent with ALMOST ALL pistols. Tested with all OA pistols.

Edited by Rommel

Share this post


Link to post
Share on other sites

Much better solution would be to check the weapon's type. Handguns are 2 IIRC:

if ({getNumber(configFile >> "CfgWeapons" >> _x >> "type") == 2} count (weapons player) > 0) then {hint "You have a handgun"} else {hint "No handgun"};

Share this post


Link to post
Share on other sites

Same result, different config value :P, either way, the concept remains the same. As long as that value is consistent in addons; all is good.

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  

×