Jump to content
Sign in to follow this  
A-SUICIDAL

Unable to detect if player has magazine "LaserBatteries"

Recommended Posts

Why is it that this works for detecting if a player has a grenade...

_mags = magazines player;

if ("HandGrenade_West" in _mags) exitWith {
   hint "You have a grenade";
};

if !("HandGrenade_West" in _mags) exitWith {
   hint "You do not have a grenade";
};

but this does not work for detecting if a player has a battery...

_mags = magazines player;

if ("LaserBatteries" in _mags) exitWith {
   hint "You have a battery";
};

if !("LaserBatteries" in _mags) exitWith {
   hint "You do not have a battery";
};

This makes no sense. In the ammo crate the batteries are called "Laser Marker", which seems to be a mistake since it should obviously be called "Battery" or "Laser Battery".

Is there some other way of detecting if the player has a battery in their inventory?"

This is the part of the script that I am trying to get working correctly, but it simply will not detect if I have a battery or not. It always tells me that I do not have a battery even if I do have one.

_weps = weapons player;
_mags = magazines player;

if ((isNull _primarytarget) && ("Laserdesignator" in _weps) && !("LaserBatteries" in _mags)) exitWith {
   hint "No laser target detected. You do not have a Battery. Get one from an ammo crate.";
};

if ((isNull _primarytarget) && !("Laserdesignator" in _weps) && ("LaserBatteries" in _mags)) exitWith {
   hint "No laser target detected. You do not have a Laser Marker. Get one from an ammo crate.";
};

if ((isNull _primarytarget) && !("Laserdesignator" in _weps) && !("LaserBatteries" in _mags)) exitWith {
   hint "No laser target detected. You do not have a Laser Marker or a Battery. Get them from an ammo crate.";
};

if ((isNull _primarytarget) && (currentWeapon s1=="LaserDesignator") && ("LaserBatteries" in _mags)) exitWith {
   hint "No laser target detected. You need to turn your Laser Marker on.";
};

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

Both of these returned false for me even when I possesed the item(s).

_Mags = Magazines Player;
If ("HandGrenade_West" In _Mags) Then {Hint "True"} Else {Hint "False"};
If ("LaserBatteries" In _Mags) Then {Hint "True"} Else {Hint "False"};

Edited by Iceman77

Share this post


Link to post
Share on other sites

It's working perfectly - there are no "LaserBatteries" in _mags, however if you check for "Laserbatteries" you will find you have them!

_mags = magazines player;
hint format ["%1",_mags];

if ("Laserbatteries" in _mags) exitWith {
   player sidechat "You have a battery";
};

if !("Laserbatteries" in _mags) exitWith {
   player sidechat "You do not have a battery";
};

If you have problems with checking an array - hint it - it will show you exactly whats in it. Strings are case sensitive.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Yes they're case sensitive when being checked but not when adding them for some reason.

Share this post


Link to post
Share on other sites
Yes they're case sensitive when being checked but not when adding them for some reason.

The same applies to some SCAR magazines. I think that it's some config typos :p

If you don't want to be bothered with case-sensitivity on magazines/weapons you can use count as a workaround.

_mags = magazines player;

if ({_x == "LaserBatteries"} count _mags > 0)  exitWith {
   hint "You have a battery";
};

if ({_x == "LaserBatteries"} count _mags < 1) exitWith {
   hint "You do not have a battery";
};

Share this post


Link to post
Share on other sites

I got it working thanks to all your help. I didn't realize that it was case sensitive, and after learning that, I still missed a few letters that needed to be uncapped, but all is good now.

Thanks so much guys. I hope somebody else learns from this, because I wouldn't want anybody else to lose their mind over some script that doesn't work because they weren't aware that some things are case sensitive.

Benny's sample actually worked even though it is not case sensitive.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I guess your code could looks like:

//--- Local function to find an element in an array (case-insensitive). Returns true if found otherwise false.
_in_array = {
Private ["_find", "_array"];
_find = _this select 0;
_array = _this select 1;

if ({_x == _find} count _array > 0) then {true} else {false};
};

_weps = weapons player;
_mags = magazines player;

if (isNull _primarytarget && (["Laserdesignator", _weps] call _in_array) && !(["LaserBatteries", _mags] call _in_array)) exitWith {
   hint "No laser target detected. You do not have a Battery. Get one from an ammo crate.";
};

if (isNull _primarytarget && !(["Laserdesignator", _weps] call _in_array) && (["LaserBatteries", _mags] call _in_array)) exitWith {
   hint "No laser target detected. You do not have a Laser Marker. Get one from an ammo crate.";
};

if (isNull _primarytarget && !(["Laserdesignator", _weps] call _in_array) && !(["LaserBatteries", _mags] call _in_array)) exitWith {
   hint "No laser target detected. You do not have a Laser Marker or a Battery. Get them from an ammo crate.";
};

if (isNull _primarytarget && (currentWeapon s1=="LaserDesignator") && (["LaserBatteries", _mags] call _in_array)) exitWith {
   hint "No laser target detected. You need to turn your Laser Marker on.";
};

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  

×