Jump to content
Violt

Rank + Whitelist Script

Recommended Posts

Hello, 

I am working on a script. 

And i have got it working pretty much. 

I have only got one problem. 

This Script gives every player their rank and kicks players that are not in the rank list.

It gives the players that have their SteamID in here their rank but it does not kick players who don't.

But i can't figure it out. 

Here's my script

/*
Rank.sqf
This Script gives every player their rank and kicks players that are not in the rank list.
*/
sleep 2; //Delay to make sure that the script is beign executed

// Rank and SteamID List
PRIVATE        =    [
"765**************" // SteamID64 here

];
CORPORAL        =    [
"765**************" // SteamID64 here
  
];
SERGEANT        =    [
"765**************" // SteamID64 here
  
];
LIEUTENANT    =    [
"765**************" // SteamID64 here
  
];
CAPTAIN        =    [
"765**************" // SteamID64 Here

];
MAJOR        =    [
"765**************" // SteamID64 Here
  
];
COLONEL        =    [
"765**************" // SteamID64 Here

];


//=========================================================================================================================================================

_playerUID = getPlayerUID player; //Checks PlayerUID


_found = false;
while {!_found} do {
    if (_playerUID in CORPORAL) then {
        player setRank "CORPORAL"; // This sets the ingame Rank
        _found = true; // Stops Searching if the playerUID was found
		
    }else{
		
        if (_playerUID in SERGEANT) then {
            player setRank "SERGEANT";
            _found = true;
			
        }else{
            if (_playerUID in LIEUTENANT) then {
                player setRank "LIEUTENANT";
                _found = true;

            }else{
                if (_playerUID in CAPTAIN) then {
                    player setRank "CAPTAIN";
                    _found = true;

                }else{
                    if (_playerUID in MAJOR) then {
                        player setRank "MAJOR";
                        _found = true;

                    }else{
                        if (_playerUID in COLONEL) then {
                            player setRank "COLONEL";
                            _found = true;

                        }else{
						if (_playerUID in PRIVATE) then {
                            player setRank "PRIVATE";
                            _found = true;
							
							}else{  // If you are not in the Rank List you will get kicked back to the lobby
								disableUserInput true;
								hint "You are not whitelisted! You will be kicked to the lobby in 5 seconds!";
								sleep 5;
								disableUserInput false;
								failMission "end1";
								_found = true;
							};
                        };
                    };
                };
            };    
        };    
    };
};

 

Share this post


Link to post
Share on other sites

My eyes! I recommend you use switch instead of if statements. Also, is there a need for the while loop since you can just check on first join. Something like:

switch (true) do
{
	case (_playerUID in PRIVATE) :
	{
		// code...
	};
	case (_playerUID in CORPORAL) :
	{
		// code...
	};
	case (_playerUID in SERGEANT) :
	{
		// code...
	};
	case (_playerUID in LIEUTENANT) :
	{
		// code...
	};
	case (_playerUID in CAPTAIN) :
	{
		// code...
	};
	case (_playerUID in MAJOR) :
	{
		// code...
	};
	case (_playerUID in COLONEL) :
	{
		// code...
	};
	default
	{
		// NOT whitelisted!
		// kick or do whatever...
	};
};

 

Share this post


Link to post
Share on other sites
1 hour ago, HazJ said:

My eyes! I recommend you use switch instead of if statements. Also, is there a need for the while loop since you can just check on first join. Something like:


switch (true) do
{
	case (_playerUID in PRIVATE) :
	{
		// code...
	};
	case (_playerUID in CORPORAL) :
	{
		// code...
	};
	case (_playerUID in SERGEANT) :
	{
		// code...
	};
	case (_playerUID in LIEUTENANT) :
	{
		// code...
	};
	case (_playerUID in CAPTAIN) :
	{
		// code...
	};
	case (_playerUID in MAJOR) :
	{
		// code...
	};
	case (_playerUID in COLONEL) :
	{
		// code...
	};
	default
	{
		// NOT whitelisted!
		// kick or do whatever...
	};
};

 

For some reason the script is not working at all right now. 

 

Here's my script

What am i doing wrong? 

 

//Ranks.sqf by Violt Created for American-Tactics.com
//This Script gives every player their rank and kicks players that are not in the rank list.

sleep 5; //Delay to make sure that the script is beign executed

// Rank and SteamID list

PRIVATE         =    ["76561198157925156"];
CORPORAL        =    [];
SERGEANT        =    [];
LIEUTENANT      =    [];
CAPTAIN         =    ["76561198137045416"];
MAJOR           =    ["76561198155447330"];
COLONEL         =    ["76561198122914475"];

_playerUID = getPlayerUID player; //Checks Player ID

//check to see if the player matches
switch (true) do {
	case (_playerUID in PRIVATE)    : { player setRank "PRIVATE"; };
    case (_playerUID in CORPORAL)   : { player setRank "CORPORAL"; };
    case (_playerUID in SERGEANT)   : { player setRank "SERGEANT"; };
    case (_playerUID in LIEUTENANT) : { player setRank "LIEUTENANT"; };
    case (_playerUID in CAPTAIN)    : { player setRank "CAPTAIN"; };
    case (_playerUID in MAJOR)      : { player setRank "MAJOR"; };
    case (_playerUID in COLONEL)    : { player setRank "COLONEL"; };
	default { 					
    	disableUserInput true;
		hint "You are not whitelisted! You will be kicked to the lobby in 5 seconds!";
		sleep 5;
		disableUserInput false;
		failMission "end1";;
	};
};

 

Share this post


Link to post
Share on other sites

Did you output the player rank after the switch?

hintSilent format [":: %1", rank player];

Also... Try:

private _playerUID = getPlayerUID player;

You can also output a test message inside each case block for testing. How do you execute this?

Share this post


Link to post
Share on other sites
8 hours ago, HazJ said:

Did you output the player rank after the switch?


hintSilent format [":: %1", rank player];

Also... Try:


private _playerUID = getPlayerUID player;

You can also output a test message inside each case block for testing. How do you execute this?

I do not understand this fullt yet. If you mean by executing the script. The executing code is in the init.sqf

Share this post


Link to post
Share on other sites

Anyways, i will try to rework the script. After i get home.

As it worked before i added the switches. 

I’ll let you know when it’s working or if i’m totally lost.

Share this post


Link to post
Share on other sites
16 hours ago, HazJ said:

Did you output the player rank after the switch?


hintSilent format [":: %1", rank player];

Also... Try:


private _playerUID = getPlayerUID player;

You can also output a test message inside each case block for testing. How do you execute this?

Hello again, i found out that if i add the case

case (_playerUID in PRIVATE)    : { player setRank "PRIVATE"; };

It will not work so i commented it out and it works now. 

But the script has to have Private's to be able to be "whitelisted"

 

 

//Ranks.sqf by Violt Created for American-Tactics.com
//This Script gives every player their rank and kicks players that are not in the rank list.

sleep 2; //Delay to make sure that the script is beign executed

//Rank and SteamID list
//PRIVATE         =    ["76561198157925156"];
CORPORAL        =    [];
SERGEANT        =    [];
LIEUTENANT      =    [];
CAPTAIN         =    ["76561198137045416"];
MAJOR           =    ["76561198155447330"];
COLONEL         =    ["76561198122914475"];

_playerUID = getPlayerUID player; //Get Player UID

//check to see if the player matches
switch (true) do {
//	case (_playerUID in PRIVATE)    : { player setRank "PRIVATE"; };
    case (_playerUID in CORPORAL)   : { player setRank "CORPORAL"; };
    case (_playerUID in SERGEANT)   : { player setRank "SERGEANT"; };
    case (_playerUID in LIEUTENANT) : { player setRank "LIEUTENANT"; };
    case (_playerUID in CAPTAIN)    : { player setRank "CAPTAIN"; };
    case (_playerUID in MAJOR)      : { player setRank "MAJOR"; };
    case (_playerUID in COLONEL)    : { player setRank "COLONEL"; };

    default { hint "Test"; }; //setting default rank for all others    
};

 

Share this post


Link to post
Share on other sites
23 minutes ago, Violt said:

Hello again, i found out that if i add the case


case (_playerUID in PRIVATE)    : { player setRank "PRIVATE"; };

It will not work so i commented it out and it works now. 

But the script has to have Private's to be able to be "whitelisted"

 

 


//Ranks.sqf by Violt Created for American-Tactics.com
//This Script gives every player their rank and kicks players that are not in the rank list.

sleep 2; //Delay to make sure that the script is beign executed

//Rank and SteamID list
//PRIVATE         =    ["76561198157925156"];
CORPORAL        =    [];
SERGEANT        =    [];
LIEUTENANT      =    [];
CAPTAIN         =    ["76561198137045416"];
MAJOR           =    ["76561198155447330"];
COLONEL         =    ["76561198122914475"];

_playerUID = getPlayerUID player; //Get Player UID

//check to see if the player matches
switch (true) do {
//	case (_playerUID in PRIVATE)    : { player setRank "PRIVATE"; };
    case (_playerUID in CORPORAL)   : { player setRank "CORPORAL"; };
    case (_playerUID in SERGEANT)   : { player setRank "SERGEANT"; };
    case (_playerUID in LIEUTENANT) : { player setRank "LIEUTENANT"; };
    case (_playerUID in CAPTAIN)    : { player setRank "CAPTAIN"; };
    case (_playerUID in MAJOR)      : { player setRank "MAJOR"; };
    case (_playerUID in COLONEL)    : { player setRank "COLONEL"; };

    default { hint "Test"; }; //setting default rank for all others    
};

Got it working!

Of course "Private" doesn't work, since it's already a command.

Stick to your own naming conventions, especially for global variables, to prevent this kind of stuff from happening, your array of UIDs valid for the various ranks could look like this:

VIO_uids_private = [];
VIO_uids_corporal = [];
VIO_uids_sergeant = [];
//etc

This will most likely avoid conflicts with already existing commands and third party scripts.

 

Cheers

  • Like 3

Share this post


Link to post
Share on other sites

LOL! Completely missed that, was late haha.

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites
4 hours ago, HazJ said:

LOL! Completely missed that, was late haha.

Same here! 

Share this post


Link to post
Share on other sites

Though it was odd that it worked with if statements. He said it worked before. Didn't test myself. Surely it shouldnot work for either?

Share this post


Link to post
Share on other sites
2 minutes ago, HazJ said:

Though it was odd that it worked with if statements. He said it worked before. Didn't test myself. Surely it shouldnot work for either?

Maybe he never tested it where that statement was true?

Share this post


Link to post
Share on other sites

Probably. Or maybe just...

ArmA

:hang:

  • Haha 1

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

×