Jump to content
Sign in to follow this  
galzohar

Disable commanding mode script?

Recommended Posts

I was trying to get something to disable spacebar scanning for Arma 2 free using a script.

I digged up many different solutions, none of which really worked.

Non-working solution 1:

http://forums.bistudio.com/showthread.php?77965-Spacebar-scanning/page5

player disableConversation true;

Doesn't seem to do anything. As far as I'm aware it only disables BIS conversation system or something? In any case, after running this I could still get range reading via spacebar as well as names of objects I was pointing at.

Non-working solution 2:

// Run key press handler (disable spacebar scanning etc)
disableSerialization;
waituntil {!(IsNull (findDisplay 46))};
fnc_keyDown = compile preprocessFileLineNumbers "keydown.sqf";
_display = findDisplay 46;
_display displayAddEventHandler ["keyDown", "_this call fnc_keyDown"];

private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;

_handled = false;

//if (!_shift && !_ctrlKey && !_alt) then
//{
if (_dikCode in (actionKeys "ForceCommandingMode")) then
{
	player sideChat localize "STR_Spacebar";
	_handled = true;
};
//};

_handled

Basically this works if it is bound to a simple keyboard key, but if you use a modifier (ctrl/alt/shift) or use a mouse/joystick key instead, this obviously fails.

Is there any way to make any of the above solutions actually work or maybe another solution I haven't found? Again, script-only, as mods are not really an option for the purpose of what I am working on.

Share this post


Link to post
Share on other sites
I was trying to get something to disable spacebar scanning for Arma 2 free using a script.

I digged up many different solutions, none of which really worked.

Non-working solution 1:

http://forums.bistudio.com/showthread.php?77965-Spacebar-scanning/page5

player disableConversation true;

Doesn't seem to do anything. As far as I'm aware it only disables BIS conversation system or something? In any case, after running this I could still get range reading via spacebar as well as names of objects I was pointing at.

Non-working solution 2:

// Run key press handler (disable spacebar scanning etc)
disableSerialization;
waituntil {!(IsNull (findDisplay 46))};
fnc_keyDown = compile preprocessFileLineNumbers "keydown.sqf";
_display = findDisplay 46;
_display displayAddEventHandler ["keyDown", "_this call fnc_keyDown"];

private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;

_handled = false;

//if (!_shift && !_ctrlKey && !_alt) then
//{
if (_dikCode in (actionKeys "ForceCommandingMode")) then
{
	player sideChat localize "STR_Spacebar";
	_handled = true;
};
//};

_handled

Basically this works if it is bound to a simple keyboard key, but if you use a modifier (ctrl/alt/shift) or use a mouse/joystick key instead, this obviously fails.

Is there any way to make any of the above solutions actually work or maybe another solution I haven't found? Again, script-only, as mods are not really an option for the purpose of what I am working on.

Create a sqf file and put this code in it and then call it from your init.sqs Like this. [] exec "disableCommandMode.sqf";

if (isNull player) exitwith {} ;

CMbindings = [];
Salutebindings = [];
CMoffbindings=[];
CMblocking =false ;

VAR_DEFAULT(CTF_disableCommandMode,true) ;

updateKeyBindings =
{
    while {true} do {
  //DBG [time,"keys"] ;
  if (CTF_disableCommandMode) then {
       CMbindings = actionKeys "ForceCommandingMode";
  } ;

  Salutebindings = actionKeys "Salute";

  sleep 2;
    };
};

grenadeModeTimer=0 ;
fireButtonDown=false;
grenadeSelectState ="idle";
grenadeKeyDown=false;

grenadeSelect={
    private ["_muz"];
    //to get here, the user must have pressed the salute button
    grenadeModeTimer = time ;
    //assume the player wanted a hand-grenade by default
    player selectweapon "handgrenademuzzle" ;
    waituntil {
  (time -grenadeModeTimer > 0.5) ||
       !grenadeKeyDown } ;
    if (grenadeKeyDown) then {
       //this was a long press so switch to grenade-launcher if appropriate
       _muz =  getArray(configFile>>"CfgWeapons">>(primaryWeapon player)>>"muzzles");
       if (1 < (count _muz)) then {
		 player selectweapon EL(_muz,1);
	    } ; 
  } else {
  //this was a short press so check for another one 
  grenadeModeTimer = time ;
  waituntil {
       (time -grenadeModeTimer > 0.5) ||
	    grenadeKeyDown } ;
  if (grenadeKeyDown) then {
	    //we got a second press
	    player selectWeapon "SmokeShellMuzzle" ;
       } else {
       //looks like this was a single press after all
  };
    } ;
    sleep 2;
    while {fireButtonDown} do {sleep 0.5;} ;
    [player,primaryWeapon player] call safeSelectWeapon;
    grenadeSelectState="idle";
} ;

dokeyDown={
    private ["_r"] ;
    _r = false ; 
    if ((_this select 1) in CMbindings) then {
  hint "Command mode disabled" ;
  _r=true;
    };
    if ((_this select 1) in Salutebindings) then {
       grenadekeydown=true ;
       if (grenadeSelectState == "idle") then {
		 grenadeSelectState = "running" ;
		 [] spawn grenadeSelect;
	    } ;
       _r=true;
  };
    _r;
} ;

dokeyUp={
    private ["_r"] ;
    _r = false ;
    if ((_this select 1) in Salutebindings) then {
       grenadeKeyDown=false;
       _r = true;
  };
    _r ;
} ;

//
//I don't know why a delay is necessary :-(
sleep 5;
(FindDisplay 46) DisplaySetEventHandler [
    "keydown",
    "_this call dokeyDown"
    ];
(FindDisplay 46) DisplaySetEventHandler [
    "keyup",
    "_this call dokeyUp"
    ];
(FindDisplay 46) DisplaySetEventHandler ["mousebuttondown","fireButtonDown=true;"] ;
(FindDisplay 46) DisplaySetEventHandler ["mousebuttonup","fireButtonDown=false;"] ;

[] call updateKeyBindings ;

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  

×