Jump to content

Recommended Posts

Obviously based on my question my Arma scripting experience is limited. I have other coding experience but the Arma nuances make it difficult for me to find out where I am going wrong.  I have done a bunch of research and I have found examples of what I want but none are working.  If anyone has suggestions it would be very helpful.

 

What I would like to do is step through the players cfgpatches and check to see if each element of that array is in another array or not. If not display text and endmission.  I know this question has been asked but in each thread the examples do not work as expected.  

 

Below are the three methods I have tried to get what I want done to work.

First attempt

mods = ["Element1","Element2","Element3"];
_classes = [];
_cfg = (ConfigFile >> "CfgPatches");
_itemCount = (count _cfg) - 1;
for "_i" from 0 to _itemCount do
	{
	if (isClass (_cfg select _i)) then
		{
			_classes = _classes + [configName (_cfg select _i)];
		};
	}; if (!( str _classes in mods)) then {
    player groupChat "You are using a mod that is not allowed, please check list of approved mods.  you are being returned to the lobby in 15 seconds";
	sleep 15;
	"end1" call BIS_fnc_endMission;
    };

Second Attempt

_mods = ["Element1","Element2","Element3"];
_patches = (ConfigFile >> "CfgPatches");
_c = count _patches;
_loop = true;
_n = 0;
_arr [];
while{_loop}do{
  _cur = _patches select _n; 
  if not(_cur in _mods) {
  	player groupChat "You are using a mod that is not allowed, please check list of approved mods.  you are being returned to the lobby in 15 seconds";
	sleep 15;
	"end1" call BIS_fnc_endMission;
  };
  _n = _n + 1;
  if(_n > _c)then{_loop = false;};
};
_arr;

Third Attempt

_mods = ["Element1","Element2","Element3"];
_canPass = true;
{
if (!(["a3_", _x] call BIS_fnc_inString)) then
{
	if (isClass _x) then
	{
		if ((!configName _x) in _mods) exitWith {_canPass = false;};
	};
};
} forEach activatedAddons;
if (!_canPass) exitWith
{
	player groupChat "You are using a mod that is not allowed, please check list of approved mods.  you are being returned to the lobby in 15 seconds";
	sleep 15;
	"end1" call BIS_fnc_endMission;
};

Any suggestions on how I might get one of these are similar code to work would be a big help,

Thanks in advanced.

Share this post


Link to post
Share on other sites
21 minutes ago, pierremgi said:

Look at getDLCs for official ones and getMissionDLCs for the mods.

These references are the mods used in the mission (embeded in the mission.sqf)  I want the players mods which may or may not be in the mission file, and I want to compare that to a list of allowed mods. 

Share this post


Link to post
Share on other sites

It seems to me activatedAddons is not a reliable command for small local addons

If you have some, just compare:

_result = activatedAddons select {!(["a3_",_x] call bis_fnc_inString) && !(["curator",_x] call bis_fnc_inString)}

and:

_result = ("!(['a3_', str _x] call BIS_fnc_inString) && !(['curator',str _x] call bis_fnc_inString)" configclasses (configfile >> "CfgPatches")) apply {configname _x}

 

The second one is based on cfgPatches. It seems to me more exhaustive in regard of cheat codes.

 

Share this post


Link to post
Share on other sites

The problem is not with generating the list of addons, I agree the CfgPatches is a better solution.  The problem is each of the samples I posted do not work at all.  With one of the examples (I believe it is the first, it always fails) ,  I have compared the list of mods that I am using in the mods = array with my real output of cfgPatches,using Notepad ++,  and my cfgpatches does not have any elements that are not in the _mods array.  The other two example always pass my test even when they should not.  I think there is an error somewhere in my code doing the compare, but I do not have enough experience with Arma coding to find the error.  I believe one of the error was related to expecting a string value.  I have thought of converting each element of the array to string and lower case to make sure there could be no type mismatches, but again I am reaching my Arma coding experience.  

 

If anyone could look at the examples and locate any mistakes, or recommend working code using another method, it would be great. 

Share this post


Link to post
Share on other sites

There are several ones.

First of all, you write an array ["Element1","Element2","Element3"] without say what is it. We can't guess what is it! You play with the <in> command which is case sensitive and doesn't allow any difference.

Note: On the other hand, you mix strings and array (str _classes) : forget, or you use isClass for nut..
 

_mods = ["Element1","Element2","Element3"];
{
  if !(_x in _mods) exitWith {
    [ ] spawn {
      player groupChat "You are using a mod that is not allowed, please check list of approved mods. you are being returned to the lobby in 15 seconds";
      sleep 15;
      "end1" call BIS_fnc_endMission;
     }
  }
} forEach (activatedAddons select {! (["a3_", _x] call BIS_fnc_inString) });

 

will check for existing elements in activatedAddons (except the "a3_..." family). It doesn't care with extra addons, but it appears to me it's not your problem.

So, diag_log your activatedaddons like in the command example on BIKI, then copy paste what you want to be mandatory in your _mods array. Simple as that.

 

Share this post


Link to post
Share on other sites

Thank you for the help. 

 

You are correct the _mods is just an export of cfgpatches with all the addons that I what to allow.  I just did not what to include the array here with over 1000 elements in it.  I tried your code and it does not work.  Here is what I did;

I loaded all the mods that I would like to check against

I ran "activatedAddons select {! (["a3_", _x] call BIS_fnc_inString)" in the debug console to create a list of the activatedAddons that I had loaded

I pasted that list as is as the "_mods" array

I created a file AOFL3.sqf in my scripts folder and pasted the above code

I added "_null = [] execVM "scripts\AOFL3.sqf"; to my InitPlayerLocal.sqf

and ran the mission with the exact same mods that I used to generate the _mods array 

 

I get kicked with the exitwith code.

 

I am going to try again with only a couple mods, but this is what has been frustrating me.  Code that I believe should work is not working.

Share this post


Link to post
Share on other sites

Strange! You can try to exitWith { hint str _x } or systemChat that, instead of the spawned code for ending mission.

Share this post


Link to post
Share on other sites

For some reason the export I did of activatedAddons had about 8 items missing. Once I added those items to the Array, the script is working as expected.  I do not know why the list did not match initially, I did not change any mods between doing the export and running the script, but in any case.  Thank you for your help.

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

×