Jump to content
Sign in to follow this  
Sokoloft

3rd Person Script, Kick player if they press numpad enter more than 3 times?

Recommended Posts

Hello, I found this script at armahaulic = www.armaholic.com/page.php?id=26369

 

With a minute amount of editing, I made it do what I want, which is just force first person on the player.

// Author - Sokoloft & Rodeostar42 @ www.armaholic.com/page.php?id=26369

//3rdPersonView.sqf


if (!isDedicated) then {

	waitUntil {!isNull (findDisplay 46)};
	
	if( (difficultyOption "thirdPersonView")isEqualTo 0) then
	{
		while {true} do {};
	};

	if( (difficultyOption "thirdPersonView")isEqualTo 1) then
	{
		while {true} do {

			waitUntil {cameraView == "EXTERNAL" || cameraView == "GROUP"};

			if  (((vehicle player) == player) && (speed ( player)) >= 0) then {
				player switchCamera "INTERNAL";
			};
			sleep 0.1;



		};
	};

};

How would I go about making it to were the player is kicked after numpad enter is hit more than 3 times. As well as in between, is given a warning via side chat, so people in server can shame the person, as well as it should have the persons name. So:

 

%PlayerName% has tried to enter third person, stop now or you will be kicked!

%PlayerName% has tried to enter third person, last chance, stop now!

%PlayerName% has tried to enter third person, for the last time, and will now be kicked!

 

As well as the only reason why I want to do this is because if you run, and spam enter, you can slightly get into third person for a second. This is really not a problem, since my mission is vs AI, however if a player decided to spam it, they can slow down the server quite a bit since the script is being done every time they hit numpad enter. As well as there needs to be a grace for players in vehicles, so that they can still go into third person and not be kicked. But not spam it at the same time! Any info would be helpful as I don't know what I'm doing xD

Share this post


Link to post
Share on other sites

Why don't you just disable the 3rd PV in the difficulty settings?

  • Like 1

Share this post


Link to post
Share on other sites

I honestly wish it were that easy, however I do not have access to the dedicated server params as easily as my friend does. Plus I do not want it to be completely disabled, that is why it's only on infantry via this script. The source script already had snippets for planes, heli's, boats, and ground vehicles, however it took too long to load (high ms) for what I needed, plus I didn't need to define those since I just want 3rd person on vehicles. So less code = faster script.

Share this post


Link to post
Share on other sites

I think he wants it for vehicles. edit: ninja'd

 

This section can probably be removed as it does nothing:

    if( (difficultyOption "thirdPersonView")isEqualTo 0) then
    {
        while {true} do {};
    };

Also, you can detect if a key has been pressed with displayaddeventhandler, then if the key fits, then assign a numerical variable to the player object counting how many times it's been pressed and you can then access it with the script above.

handle = (findDisplay 46) displayAddEventHandler ["KeyDown", "hint str _this; _this call yourKeyDownFunction"];
  • Like 1

Share this post


Link to post
Share on other sites

@das attorney Thanks for the response! As for:

    if( (difficultyOption "thirdPersonView")isEqualTo 0) then
    {
        while {true} do {};
    };

Is for if the veteran difficulty is actually selected, in turn telling the script to do exactly nothing. Correct? I added that in myself for that reason.

 

As well as what if the person has changed their key binding? As well as how do I put the said players name that is actually doing it in the sideChat command? Hope to hear from you soon! Thanks!

Share this post


Link to post
Share on other sites

It's been a while since I messed with it, but something like this could work:

 

(It assumes you will still have your loop running in the other script).

handle = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call fnc_keyCheck"];
fnc_keyCheck = {
    /*Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.*/
    params ["_ctrl","_keyCode","_shiftKey","_ctrlKey","_altKey","_handled","_menuOpen","_keys"];
    _handled = false;
    _keys = actionKeys "name of action key";// look it up here: https://community.bistudio.com/wiki/inputAction/actions  (i think it might be "personView")
    if (_keyCode in _keys) then {
        player sideChat "pressed 1st/3rd person button"; // test message
        // your code here
        _times = player getVariable ["badBoyAccess",0];
        call {
            if (_times == 0) exitWith {
                // remoteExecCall your message (%PlayerName% has tried to enter third person, stop now or you will be kicked!)
            };
            if (_times == 1) exitWith {
                // remoteExecCall your message (%PlayerName% has tried to enter third person, last chance, stop now!)
            };
            if (_times == 2) exitWith {
                // remoteExecCall your message (%PlayerName% has tried to enter third person, for the last time, and will now be kicked!)
            };
            if (_times == 3) exitWith {
                endMission "end1"
            };
        };
        if (_times < 3) then {
            player setVariable ["badBoyAccess",_times + 1];
        };
        //
        _handled = true; // change to true if you want to override default key behaviour (in fact, you could maybe do this and then the game would not change it to 3rd person so you don't need all that code above) - try it out!
    };
    _handled
};

You might need to have a timeout for the function in case they try to spam the key like a moron.

  • Like 1

Share this post


Link to post
Share on other sites

I do believe I am missing something xD Much trial and error later I got it working. However that was due to me not actually initializing the fnc. Currently initializing it via this method I learned from theend3r here on the forums.

 

 

I deleted fnc_keyCheck = {} and am instead defining it via my 3 inits. The way I'm doing it with all my other fnc's

//custom fnc
fnc_boatInf = compile preprocessFile "scripts\functions\fnc_boatInf.sqf";
fnc_MG42Inf = compile preprocessFile "scripts\functions\fnc_MG42Inf.sqf";
fnc_keyCheck = compile preprocessFile "scripts\functions\fnc_keyCheck.sqf";

Now, how do I do it via your method?

 

Also, second noob question of the day, I'm using the setDate command in my 3 init's as well, do I need to have it on all 3 inits or how do I determine what command can be on what init? Does it say and I'm just not reading it? x_x

 

Thanks for all your help! It's much appreciated! You'll be in my diary module for sure!

  • Like 1

Share this post


Link to post
Share on other sites

if you do this:

fnc_MG42Inf = compile preprocessFile "scripts\functions\fnc_MG42Inf.sqf";

It's the same as doing this:

fnc_MG42Inf = {
       // code that's in the script
};

So yes what you did is ok, but you could also have left the code as is in the init.sqf for example.  Anyway, that's not important right now.

 

To make the fncs permanent (can't be overwritten by hacker for example), you should compileFInal them:

fnc_boatInf = compileFinal preprocessFileLineNumbers "scripts\functions\fnc_boatInf.sqf";
fnc_MG42Inf = compileFinal preprocessFileLineNumbers "scripts\functions\fnc_MG42Inf.sqf";
fnc_keyCheck = compileFinal preprocessFileLineNumbers "scripts\functions\fnc_keyCheck.sqf";
  • Like 1

Share this post


Link to post
Share on other sites

Copy that, I got "compileFinal preprocessFileLineNumbers" Running my fnc compiling now in just my init.sqf

 

Now, the fnc_keyCheck works great, however I have yet to test if it works with vehicles, were third person is enabled. Therefore they need to be able to go into third person without being kicked. So, were would I go about implementing the "timeout" you were talking about at the end of your second post? Essentially I need something like sleep for 1ms then loop to line 1. after line 12, so on 13 the sleep would start. So if the player were to hit it before the 1ms point it would go through with the next line. Which is 14, still not sure how to loop it :(

 

As well as, I'm still not sure how to get the players name to appear in the chat, how would I do that as well? Don't tell me it's another fnc to script :( Let me know!

// Author - Sokoloft & das attorney @ BIS forums mission editing & scripting.

//fnc_keyCheck.sqf


    /*Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.*/
    params ["_ctrl","_keyCode","_shiftKey","_ctrlKey","_altKey","_handled","_menuOpen","_keys"];
    _handled = false;
    _keys = actionKeys "PersonView";
    if (_keyCode in _keys) then {
	
        player sideChat "pressed 1st/3rd person button";
		
        _times = player getVariable ["badBoyAccess",0];
        call {
            if (_times == 0) exitWith {
				[independent,"HQ"] sideChat "%PlayerName% has tried to enter third person, stop now or you will be kicked!";
            };
            if (_times == 1) exitWith {
				[independent,"HQ"] sideChat "%PlayerName% has tried to enter third person, last chance, stop now!";
            };
            if (_times == 2) exitWith {
				[independent,"HQ"] sideChat "%PlayerName% has tried to enter third person, for the last time, and will now be kicked!";
            };
            if (_times == 3) exitWith {
                endMission "end1"
            };
        };
        if (_times < 3) then {
            player setVariable ["badBoyAccess",_times + 1];
        };

        _handled = true;
		
    };
_handled

Again, Thanks for all the help! Hope to hear back from you soon!

 

Edit: Forgot to include 3rdPersonView.sqf  >_<

if (!isDedicated) then {

	waitUntil {!isNull (findDisplay 46)};
	
	if( (difficultyOption "thirdPersonView")isEqualTo 0) then
	{
		while {true} do {};
	};

	if( (difficultyOption "thirdPersonView")isEqualTo 1) then
	{
		while {true} do {

			waitUntil {cameraView == "EXTERNAL" || cameraView == "GROUP"};

			if  (((vehicle player) == player) && (speed ( player)) >= 0) then {
				player switchCamera "INTERNAL";
			};
			sleep 0.1;

		handle = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call fnc_keyCheck"];

		};
	};

};

:D

Share this post


Link to post
Share on other sites

Did a little bit of editing to it, now I just need a loop to make it to were it will only go through kicking the player if they repeadedly press it within 1 ms intervals? So a sleep someweres like I mentioned last time but were?

 

Probably on line 13 (After "player sideChat "has pressed 3rd Person Button";") and have it go back to 1, not sure how to do that but here's what I've got.

// Author - Sokoloft & das attorney @ BIS forums mission editing & scripting.

//fnc_keyCheck.sqf


    /*Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.*/
    params ["_ctrl","_keyCode","_shiftKey","_ctrlKey","_altKey","_handled","_menuOpen","_keys"];
    _handled = false;
    _keys = actionKeys "PersonView";
    if (_keyCode in _keys) then {
	
        player sideChat "has pressed 3rd Person Button";
		
		_times = player getVariable ["badBoyAccess",0];
        call 
		{
            if (_times == 0) exitWith {
			player sideChat "has tried to enter third person, stop now or you will be kicked!";
            };
            if (_times == 1) exitWith {
			player sideChat "has tried to enter third person, last chance, stop now!";
            };
            if (_times == 2) exitWith {
			player sideChat "has tried to enter third person, for the last time, and will now be kicked!";
			endMission "end1";
            };

        };
		 if (_times < 3) then {
            player setVariable ["badBoyAccess",_times + 1];
		};
       
	   _handled = true;
		
    };
_handled

Any suggestions? Thanks a bunch!

Share this post


Link to post
Share on other sites

Hello! I just made a slight edit to the script to it exit's with the BIS preferred fnc. Instead of the endMission command, I then found out I could have my own debriefing, so I put one saying the player messed up xD. I'm still not sure how to implement the said loop I was talking about in my prior post, any help will be much appreciated!

// Author - Sokoloft & das attorney @ BIS forums mission editing & scripting.

//fnc_keyCheck.sqf


    /*Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.*/
    params ["_ctrl","_keyCode","_shiftKey","_ctrlKey","_altKey","_handled","_menuOpen","_keys"];
    _handled = false;
    _keys = actionKeys "PersonView";
    if (_keyCode in _keys) then {
	
        player sideChat "has pressed 3rd Person Button";
		
		_times = player getVariable ["badBoyAccess",0];
        call 
		{
            if (_times == 0) exitWith {
			player sideChat "has tried to enter third person, stop now or you will be kicked!";
            };
            if (_times == 1) exitWith {
			player sideChat "has tried to enter third person, last chance, stop now!";
            };
            if (_times == 2) exitWith {
			player sideChat "has tried to enter third person, for the last time, and will now be kicked!";
			["3rdPersonExit",false,5] spawn BIS_fnc_endMission;
            };

        };
		 if (_times < 3) then {
            player setVariable ["badBoyAccess",_times + 1];
		};
       
	   _handled = true;
		
    };
_handled

Thanks again!

Share this post


Link to post
Share on other sites

I just tried this and it kicks me after I press it a second time. What I'm trying to pull off is that the player is warned that they pressed the third person button in side chat, and it sleeps for a second and restarts the script. So it's only if you spam it repeatedly. Not sure what I'm doing wrong >_< Not really sure what I'm doing period...

// Author - Sokoloft & das attorney @ BIS forums mission editing & scripting.

//fnc_keyCheck.sqf


    /*Returns the control, the keyboard code and the state of Shift, Ctrl and Alt.*/
while {true} do 
	{
    params ["_ctrl","_keyCode","_shiftKey","_ctrlKey","_altKey","_handled","_menuOpen","_keys"];
    _handled = false;
    _keys = actionKeys "PersonView";
    if (_keyCode in _keys) then {
	
	
		_times = player getVariable ["badBoyAccess",0];
        call 
		{
            if (_times == 0) exitWith {
			player sideChat "has tried to enter third person, stop now or you will be kicked!";
            };
            if (_times == 1) exitWith {
			player sideChat "has tried to enter third person, last chance, stop now!";
            };
            if (_times == 2) exitWith {
			player sideChat "has tried to enter third person, for the last time, and will now be kicked!";
			["3rdPersonExit",false,5] spawn BIS_fnc_endMission;
            };

        };
		 if (_times < 3) then {
            player setVariable ["badBoyAccess",_times + 1];
		};
       
	   _handled = true;
		
    };
	player sideChat "has pressed 3rd Person Button";
	Sleep 1;
	};
_handled

Let me know were I went wrong!!!

Share this post


Link to post
Share on other sites

There's a new eventhandler on dev branch that could help out: PlayerViewChanged

 

No documentation yet but it's a lot better then while loops. So you just have to test the parameters.

KEY_MAX_TIMES = 3;
KEY_MESSAGES = [
"%1 has tried to enter third person, stop now or you will be kicked!", 
"%1 has tried to enter third person, last chance, stop now!",
"%1 has tried to enter third person, for the last time, and will now be kicked!"
];

player addEventHandler ["PlayerViewChanged", 
	_viewName = _this select 0; //Entirly speculation did not test yet
	if(_viewName == "EXTERNAL") then
	{
		_keyTimes = _player getVariable ["keyTimesVar", 0];
		_keyTimes = _keyTimes + 1;

		[[west,"HQ"], format [KEY_MESSAGES select (_keyTimes-1), name player]] remoteExec ["sideChat"];
		
		if(_keyTimes >= KEY_MAX_TIMES) then
		{
			["",false,5] spawn BIS_fnc_endMission;
		};	
		player setVariable ["keyTimesVar",_keyTimes];
		player switchCamera "INTERNAL";
	};
];

  • Like 1

Share this post


Link to post
Share on other sites

Tried to fix it and now I've got to a point were I can't fix. It says generic error in expression 1 elements provided 2 expected. I have:

KEY_MAX_TIMES = 3;
KEY_MESSAGES = [
"%1 has tried to enter third person, stop now or you will be kicked!", 
"%1 has tried to enter third person, last chance, stop now!",
"%1 has tried to enter third person, for the last time, and will now be kicked!"
];

player addEventHandler ["PlayerViewChanged"];
	_viewName = _this select 0; //Entirly speculation did not test yet
	if(_viewName == "EXTERNAL") then
	{
		_keyTimes = _player getVariable ["keyTimesVar", 0];
		_keyTimes = _keyTimes + 1;

		[[independent,"HQ"], format [KEY_MESSAGES select (_keyTimes-1), name player]] remoteExec ["sideChat"];
		
		if(_keyTimes >= KEY_MAX_TIMES) then
		{
			["3rdPersonExit",false,5] spawn BIS_fnc_endMission;
		};	
		player setVariable ["keyTimesVar",_keyTimes];
		player switchCamera "INTERNAL";
};

Thanks!

 

Edit:

 

This was on line 15, so the first if statement. Is it actually line 14 causing the issue were _viewName is defined? Should I un-define it? Not sure, let me know!

Edited by Sokoloft

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  

×