Jump to content
schadler17

Varying Classnames?

Recommended Posts

Basically I'm trying to create a script that detects if a player has a radio in his inventory, and if not, to assign him one.

 

My problem is, sometimes the radio classname shows up as tf_anprc152, tf_anprc152_1, tf_anprc152_2, etc.

 

My question is an easy way to find out which one is equipped without having to add an endless array of radio classname possibilities.

 

What I want:

if (!("tf_anprc152" in assignedItems player)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";};

Share this post


Link to post
Share on other sites

 

Basically I'm trying to create a script that detects if a player has a radio in his inventory, and if not, to assign him one.

 

My problem is, sometimes the radio classname shows up as tf_anprc152, tf_anprc152_1, tf_anprc152_2, etc.

 

My question is an easy way to find out which one is equipped without having to add an endless array of radio classname possibilities.

 

What I want:

if (!("tf_anprc152" in assignedItems player)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";};

if (!({tolower(_x) find "tf_anprc152" > 0} count (assignedItems player) > 0)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";};

Share this post


Link to post
Share on other sites

Doesn't work.

https://community.bistudio.com/wiki/toLower

 

My issue, is sometimes the classname is "tf_anprc152"

If you assign another radio, or if the player picks one up, it'll switch to "tf_anprc152_1", "tf_anprc152_2", "tf_anprc152_2", etc.

 

I need to detect all possibilities of the _x up to about 10.

Share this post


Link to post
Share on other sites

// make sure all these classnames are lower case



_found = false;
_radios =[
tf_anprc152,
tf_anprc152_1,
tf_anprc152_2,
tf_anprc152_3,
tf_anprc152_4,
tf_anprc152_5,
tf_anprc152_6
];

{
if((ToLower_x) in assigneditems player)exitwith{_found = true};
}foreach _radios;

if !(_found)then{Player linkitem "tf_anprc152";};


Share this post


Link to post
Share on other sites
_hasRadio = { toLower _x find "tf_anprc152" >= 0 } count ( items player + assignedItems player ) > 0

Share this post


Link to post
Share on other sites

Fixed.

_unit = _this select 0;

    while {true} do {

        sleep 3;
        _assignedItems = assignedItems _unit;
        _Items = items _unit;
        _hasRadio = { toLower _x find "tf_anprc152" >= 0 } count (_items + _assignedItems) > 0;
        
        {
            if (_hasRadio) then {
                hint format ["Radio Found!"];
            } else {
                hint format ["Radio Not Found!"];
            };
            
        } forEach [
            "tf_anprc152",
            "tf_anprc152_1",
            "tf_anprc152_2",
            "tf_anprc152_3",
            "tf_anprc152_4",
            "tf_anprc152_5",
            "tf_anprc152_6",
            "tf_anprc152_7",
            "tf_anprc152_8",
            "tf_anprc152_9"
        ];
    };

Share this post


Link to post
Share on other sites

No need for the foreach the Find will automatically find all tf_anprc152_# variants..

_unit = _this select 0;

    while {true} do {

        sleep 3;
        _assignedItems = assignedItems _unit;
        _Items = items _unit;
        _hasRadio = { toLower _x find "tf_anprc152" >= 0 } count (_items + _assignedItems) > 0;
        
        if (_hasRadio) then {
            hint format ["Radio Found!"];
        } else {
            hint format ["Radio Not Found!"];
        };
      
    };

OR
 

//Give player radio at start
player linkItem "tf_anprc152";

//If he drops the radio re-add it
player addEventHandler [ "Put", {
	params[
		"_unit",
		"_container",
		"_item"
	];
	
	//If its a radio
	if ( toLower _item find "tf_anprc152" >= 0 ) then {
		//Re add it
		player linkItem "tf_anprc152";
		//Remove dropped radio
		_itemCargo = getItemCargo _container;
		clearItemCargoGlobal _container;
		{
			if ( toLower _x find "tf_anprc152" < 0 ) then {
				_container addItemCargoGlobal [ _x, _itemCargo select 1 select _forEachIndex ];
			};
		}forEach ( _itemCargo select 0 ) ;
	};
}];

//If he uses arsenal and does not have radio when exiting arsenal re-add it
[ missionNamespace, "arsenalClosed", {
	if ( { toLower _x find "tf_anprc152" >= 0 } count ( assignedItems player ) isEqualTo 0 ) then {
		player linkItem "tf_anprc152";
	};
} ] call BIS_fnc_addScriptedEventHandler;

So they cant drop or move it out of the assigned slot at all. :evil:

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

×