Jump to content
Sign in to follow this  
schadler17

Constant Error when no sight attached

Recommended Posts

Trying to get this script to basically restrict specific weapon sights based on Class.

 

It works, but when the player has NO sights, it throws an error based on the _weaponSight variable not being able to find anything..

private ["_rClass", "_rItem", "_weaponSight", "_weaponSightName"];
  
while {true} do
{
	  _rClass = _this select 0;
	  _rItem = _this select 1;

	  _weaponSight = primaryWeaponItems player select 2;
	  _weaponSightName = getText(configFile >> "CfgWeapons" >>_weaponSight >> "displayName");
  
  sleep 3;
  
	  if ((_weaponSight in _rItem)	&&   !(typeOf player in _rClass))
		
	  then {
	  
		player removePrimaryWeaponItem _weaponSight;
		
		hint format ["RESTRICTED WEAPON SIGHT\n\nYour class is not allowed\nto use %1.",_weaponSightName];

	  };
} forEach allUnits;

Share this post


Link to post
Share on other sites
private ["_rClass", "_rItem", "_weaponSight", "_weaponSightName"];
 
while {true} do
{
      _rClass = _this select 0;
      _rItem = _this select 1;

      _weaponSight = primaryWeaponItems player select 2;
      _weaponSightName = getText(configFile >> "CfgWeapons" >>_weaponSight >> "displayName");
 
  sleep 3;
 
      if (!isNil _weaponSight) then //check if _weaponSight is empty
      {
          if ((_weaponSight in _rItem)    &&   !(typeOf player in _rClass)) then
          {
          
            player removePrimaryWeaponItem _weaponSight;
            
            hint format ["RESTRICTED WEAPON SIGHT\n\nYour class is not allowed\nto use %1.",_weaponSightName];

          };
      };
} forEach allUnits;

That should hopefully solve the issue.

Share this post


Link to post
Share on other sites

Fixed it using:

_weaponSight = player weaponAccessories primaryWeapon player select 2;

Thanks for the help though :P

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  

×