Jump to content
Elliot Beckett

Player slot specific whitelisting for trained members and admins

Recommended Posts

So I have a request to make of all the scripting pro's here.

I am making a milsim server and I would like to add in a whitelisting feature for specific player slots I.E Team Leader, Squad Leaders etc. Also I want to have a second whitelist run at the same time that only allows admins into admin slots etc.

Now I have poked around and asked a few people, this is what I have found:

waitUntil {(getPlayerUID player) != ""};

_uid = getPlayerUID player;

_UIDList = ["123456789","123456789","123456789"];

if !(_uid in _UIDList) then{endMission "Loser";};

Now time for some dumb questions;

I assume I have to put this in the Init.sqf file? Also is there an easier way to add GUID's to the list without having to edit the file all the time? I want to have it so other admins can add people to the white list without me having to be there

Thanks all

Share this post


Link to post
Share on other sites

An easy way to use a text file to edit parts of code is with preprocessFile.

_UIDList = call compileFinal preProcessFile "whitelist.txt";

whitelist.txt

["123456789","123456789","123456789"]

Share this post


Link to post
Share on other sites

Ok cool, I assume I just need to make 2 different whitelist files and change the Whitelist.txt to match the right file name? Then the _UIDList etc goes into the player init slot

So I pasted that code in the Init of the player slot and it said local variable in a global space?

Yes you are probably screaming at my stupidity but I am new to this haha my understanding of Arma coding isn't good

Edited by optimashprime

Share this post


Link to post
Share on other sites

Would compileFinal be useful here? Specially for such a data. Interested in the command myself.

UIDWHITELIST = compileFinal "['123456789','123456789','123456789']";

ewww. dread already using it :p

Edited by Iceman77

Share this post


Link to post
Share on other sites
Ok cool, I assume I just need to make 2 different whitelist files and change the Whitelist.txt to match the right file name? Then the _UIDList etc goes into the player init slot

So I pasted that code in the Init of the player slot and it said local variable in a global space?

Yes you are probably screaming at my stupidity but I am new to this haha my understanding of Arma coding isn't good

It really depends on what you want to do, I'm not sure what exactly you want to do or how you want things set up...But I can tell you that error is from putting a local variable in the init line of a unit. Local variables are not allowed to be created in init lines for some reason.

Would compileFinal be useful here? Specially for such a data. Interested in the command myself.

UIDWHITELIST = compileFinal "['123456789','123456789','123456789']";

ewww. dread already using it :p

Yep, compileFinal would be extremely useful here :p

From what I understand, compileFinal prevents the variable the expression is attached to from being overwritten.

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Basically what I want to do is have a unit/player slot restricted to trained/certain members of the server, the normal whitelisting of a specific slot. Then I want to have a second whitelist that says only admins can join the admin slot, that way we can always have an admin on if needed.

The code I pasted was some that I was given and I just wanted to see if there was an easier way to edit it, you suggested the text file which can work. Then I just need to know where I place that code and what code I place in the player slot to activate the whitelisting.

Like I said, I am not good with Arma coding so we should go back to the basics haha Step by step guides are handy :)

Share this post


Link to post
Share on other sites

You can avoid using variables when it isn't necessary to retain the information they would hold. I think it would safely work to use something like this:

if !((getPlayerUID player) in (call compile preprocessFile "whitelist.txt")) then
{
endMission "Loser";
};

Share this post


Link to post
Share on other sites

So I am failing hard at this;

I posted the code you gave me into a player slot init section, it didn't give me the local variable error this time however whenever I join the server it says it can't find the whitelist.txt script. I have moved the .txt into the scripts folder and also had it in the main directory, both had the same results.

Any help?

Share this post


Link to post
Share on other sites

The game searches the mission directory for files, so make sure you include the filepath to the file if you put it inside any folders. For example, if you have a folder called 'scripts' that you put it in, you need to use:

call compile preprocessFile "scripts\whitelist.txt"

If that still doesn't work, post or PM me a download for the mission and I'll take an in-depth look.

Share this post


Link to post
Share on other sites

Loading the whitelist file like that will only make sense if the script runs exclusively on the server (or if the whitelist data is transferred to all clients).

The way you currently have it, it won't work properly. Only files inside the mission pbo get transfered to the clients.

Here is what I would do. (Put this in your init.sqf):

if (isServer) then {
reservedSlots = [someunit,someotherunit];

["reserved", "onPlayerConnected", {
	private ["_uid","_player","_UIDList"];
	_UIDList = call compile preProcessFile "whitelist.txt";
	if (_uid < 1) exitWith {};

	_player = objNull;
	while {isNull _player} do {
		sleep 1;
		{
			if (_uid == getPlayerUID _x) then {
				_player = _x;
			};
		} forEach playableUnits;
	};

	if (_player in reservedSlots) then {
		if (! _uid in _UIDList ) then {
			[["You are not entitled to use this slot!"], "BIS_fnc_infoText", _player, false] call BIS_fnc_MP;
			sleep 1;
			[["end1",false], "BIS_fnc_endMission", _player, false] call BIS_fnc_MP;
		};
	};
}] call BIS_fnc_addStackedEventHandler;
};

Put the witelist.txt directly in the ArmA-directory on the server, that way you dont have to edit the mission at all and you can even change the whitelist at runtime.

Also, put every unit that is supposed to be reserved into the "reservedSlots" array.

Edited by Tajin
  • Like 2

Share this post


Link to post
Share on other sites
if (isServer) then {
reservedSlots = [Instructor_1,Instructor_2,Instructor_3,Instructor_4,Instructor_5];

["reserved", "onPlayerConnected", {
	private ["_uid","_player","_UIDList"];
	_UIDList = call compile preProcessFile "whitelist.txt";
	if (_uid < 1) exitWith {};

	_player = objNull;
	while {isNull _player} do {
		sleep 1;
		{
			if (_uid == getPlayerUID _x) then {
				_player = _x;
			};
		} forEach playableUnits;
	};

	if (_player in reservedSlots) then {
		if (! _uid in _UIDList ) then {
			[["You are not entitled to use this slot!"], "BIS_fnc_infoText", _player, false] call BIS_fnc_MP;
			sleep 1;
			[["end1",false], "BIS_fnc_endMission", _player, false] call BIS_fnc_MP;
		};
	};
}] call BIS_fnc_addStackedEventHandler;
};

This is not working. I get an error at the start of the mission

Share this post


Link to post
Share on other sites

Its because this line here 

Quote

reservedSlots = [Instructor_1,Instructor_2,Instructor_3,Instructor_4,Instructor_5];

Should look like this, you didn't put in the quotation marks before and after

reservedSlots = ["Instructor_1","Instructor_2","Instructor_3","Instructor_4","Instructor_5"];

Anytime you have an array like above you need quotations before and after each class name along with a comma between them

Hope this helps

Share this post


Link to post
Share on other sites

now i have the Problem arma 3 shows me a error taht a ; is missing

my code look like this 

if (isServer) then {
reservedSlots = ["klon_medic1","klon_medic2","klon_medic3","klon_medic4"];

["reserved", "onPlayerConnected", {
	private ["_uid","_player","_UIDList"];
	_UIDList = call compile preProcessFile "Whitelists\medic_whitelist.txt";
	if (_uid < 1) exitWith {};

	_player = objNull;
	while {_player isNull} do {
		sleep 1;
		{
			if (_uid == getPlayerUID _x) then {
				_player = _x;
			};
		} forEach playableUnits;
	};

	if (_player in reservedSlots) then {
		if (! _uid in _UIDList ) then {
			[["Du bist kein Medic!"], BIS_fnc_infoText, _player, false] call BIS_fnc_MP;
			sleep 1;
			[["end1",false], "BIS_fnc_endMission", _player, false] call BIS_fnc_MP;
		};
	}; 
}] call BIS_fnc_addStackedEventHandler;
};

 

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

×