A simple script to add H to Holster on ANY mission file

A simple script to add H to Holster on ANY mission file

« posted: Sep 22, 2016, 07:14 AM »
I'm sure anyone on here that has have a shit worth of scripting knowledge has already solved this issue (surprised its not default in a3wasteland actually) and will not need this. However I spent a good chunk of time trying a few methods to bind H to holster server side and the simplest of all i tried finally worked.

I'm posting this so anyone else struggling can get it too!




Place this code as is into your init.sqf in the main directory.

Code: [Select]
moduleName_keyDownEHId = (findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 35) then {_nul = [] execVM 'Keyholster.sqf'};"]


Place this code in a .sqf text file in the main directory named "Keyholster.sqf" (if you want to change directory make sure you change the execVM command to include that, ex. execVM "addons\KeyholsterFolder\Keyholster.sqf")

Code: [Select]
// Author: Wildstingray
// @filename: Keyholster.sqf


if(vehicle player == player && currentWeapon player == '' && primaryWeapon player != '') then
{
player action ["SwitchWeapon", player, player, 0]
}

else
{
player action ["SwitchWeapon", player, player, 100]
};

Re: A simple script to add H to Holster on ANY mission file

« Reply #1 posted: Sep 22, 2016, 07:17 AM »
I also attempted to use this to get the unholster to work for your handgun if you didn't have a primary but it breaks the entire script, if someone could point out what i did wrong i would appreciate it!

Code: [Select]
if(vehicle player == player && currentWeapon player == '' && primaryWeapon player != '') then
{
player action ["SwitchWeapon", player, player, 0]
}
else
{
if(vehicle player == player && currentWeapon player == '' && primaryWeapon player == '' && secondaryWeapon player != '') then
{
player action ["SwitchWeapon", player, player, 6]
}
else
{
player action ["SwitchWeapon", player, player, 100]
};
};
  • Offline Matt76
  • Mercenary
  • *****
  • Posts: 418
  • co founder of customcombatgaming.com

Re: A simple script to add H to Holster on ANY mission file

« Reply #2 posted: Sep 22, 2016, 07:54 AM »
Sorry I'm not at home at the mo but jump on my server and grab the mission file, look in my onkeypress it's quite simple

Re: A simple script to add H to Holster on ANY mission file

« Reply #3 posted: Sep 22, 2016, 07:58 AM »
*headscratch

I think, it'*s just like ...

Code: [Select]
// Earplugs - End Key
case (_key in A3W_customKeys_earPlugs):
{
if (soundVolume > 0.5) then
{
0.5 fadeSound 0.2;
["You've inserted your earplugs.", 5] call mf_notify_client;
}
else
{
0.5 fadeSound 1;
["You've taken out your earplugs.", 5] call mf_notify_client;
};
};



// Holster /Unholster Weapon - H Key
case (_key == 35):
{
if (currentweapon player != "") then
{
player action ["SwitchWeapon", player, player, 100];
["You holster your weapon!", 5] call mf_notify_client;
}
else
{
player action ["SwitchWeapon", player, player, 0];
["You Unholster your weapon!", 5] call mf_notify_client;
};
};

´.. in client\clientEvents\onKeyPress.sqf
  • Offline Matt76
  • Mercenary
  • *****
  • Posts: 418
  • co founder of customcombatgaming.com

Re: A simple script to add H to Holster on ANY mission file

« Reply #4 posted: Sep 22, 2016, 08:23 AM »
unless that holstering handgun while crouched causing infinite anim loop has been fixed it should be -

Code: [Select]
case (_key in A3W_customKeys_holster):
{

if (currentweapon player != "" && (stance player != 'CROUCH' || currentWeapon player != handgunWeapon player)) then
{
player action ["SwitchWeapon", player, player, 100];
["You holstered your weapon!", 5] call mf_notify_client;
}
else
{
player action ["SwitchWeapon", player, player, 0];
["You Unholster your weapon!", 5] call mf_notify_client;
};
};
  • Offline Matt76
  • Mercenary
  • *****
  • Posts: 418
  • co founder of customcombatgaming.com

Re: A simple script to add H to Holster on ANY mission file

« Reply #5 posted: Sep 22, 2016, 08:24 AM »
unless that holstering handgun while crouched causing infinite anim loop has been fixed it should be -

Code: [Select]
case (_key in A3W_customKeys_holster):
{

if (currentweapon player != "" && (stance player != 'CROUCH' || currentWeapon player != handgunWeapon player)) then
{
player action ["SwitchWeapon", player, player, 100];
["You holstered your weapon!", 5] call mf_notify_client;
}
else
{
player action ["SwitchWeapon", player, player, 0];
["You Unholster your weapon!", 5] call mf_notify_client;
};
};

then in custom keys

Code: [Select]
private ["_varName", "_defKeys", "_customKeys", "_isValid", "_voiceKeys"];

{
_varName = _x select 0;
_defKeys = _x select 1;
_customKeys = profileNamespace getVariable _varName;

// check that each variable read from profile is an array strictly containing between 1 to 10 numbers, otherwise use default values
_isValid = !isNil "_customKeys" && {_customKeys isEqualType [] && {count _customKeys > 0 && count _customKeys <= 10 && {_customKeys isEqualTypeAll 0}}};

missionNamespace setVariable [_varName, if (_isValid) then { _customKeys } else { _defKeys }];
}
forEach
[
["A3W_customKeys_adminMenu", [22]], // 22 = U
["A3W_customKeys_playerMenu", [41]], // 41 = Tilde (above Tab)
["A3W_customKeys_playerNames", [199,219,220]], // 199 = Home, 219 = LWin, 220 = RWin
["A3W_customKeys_earPlugs", [207]], // 207 = End
["A3W_customKeys_Eject", [211]], //Del Key
["A3W_customKeys_holster", [35]] // 35 = H
];

_voiceKeys = [];
{ _voiceKeys append actionKeys _x } forEach
[
"NextChannel",
"PrevChannel",
"PushToTalk",
"PushToTalkAll",
"PushToTalkCommand",
"PushToTalkDirect",
"PushToTalkGroup",
"PushToTalkSide",
"PushToTalkVehicle"
];

A3W_allVoiceChatKeys = compileFinal str _voiceKeys;

Re: A simple script to add H to Holster on ANY mission file

« Reply #6 posted: Sep 23, 2016, 12:55 AM »
*headscratch

I think, it'*s just like ...

Code: [Select]
// Earplugs - End Key
case (_key in A3W_customKeys_earPlugs):
{
if (soundVolume > 0.5) then
{
0.5 fadeSound 0.2;
["You've inserted your earplugs.", 5] call mf_notify_client;
}
else
{
0.5 fadeSound 1;
["You've taken out your earplugs.", 5] call mf_notify_client;
};
};



// Holster /Unholster Weapon - H Key
case (_key == 35):
{
if (currentweapon player != "") then
{
player action ["SwitchWeapon", player, player, 100];
["You holster your weapon!", 5] call mf_notify_client;
}
else
{
player action ["SwitchWeapon", player, player, 0];
["You Unholster your weapon!", 5] call mf_notify_client;
};
};

´.. in client\clientEvents\onKeyPress.sqf

Did you write that or is that from a different release? I looked in my onKeyPress and its not included. Thinking about it, i knew this file existed so i don't know why i didn't just put the script here, thanks for the reply

Re: A simple script to add H to Holster on ANY mission file

« Reply #7 posted: Sep 23, 2016, 12:56 AM »
then in custom keys

Code: [Select]
private ["_varName", "_defKeys", "_customKeys", "_isValid", "_voiceKeys"];

{
_varName = _x select 0;
_defKeys = _x select 1;
_customKeys = profileNamespace getVariable _varName;

// check that each variable read from profile is an array strictly containing between 1 to 10 numbers, otherwise use default values
_isValid = !isNil "_customKeys" && {_customKeys isEqualType [] && {count _customKeys > 0 && count _customKeys <= 10 && {_customKeys isEqualTypeAll 0}}};

missionNamespace setVariable [_varName, if (_isValid) then { _customKeys } else { _defKeys }];
}
forEach
[
["A3W_customKeys_adminMenu", [22]], // 22 = U
["A3W_customKeys_playerMenu", [41]], // 41 = Tilde (above Tab)
["A3W_customKeys_playerNames", [199,219,220]], // 199 = Home, 219 = LWin, 220 = RWin
["A3W_customKeys_earPlugs", [207]], // 207 = End
["A3W_customKeys_Eject", [211]], //Del Key
["A3W_customKeys_holster", [35]] // 35 = H
];

_voiceKeys = [];
{ _voiceKeys append actionKeys _x } forEach
[
"NextChannel",
"PrevChannel",
"PushToTalk",
"PushToTalkAll",
"PushToTalkCommand",
"PushToTalkDirect",
"PushToTalkGroup",
"PushToTalkSide",
"PushToTalkVehicle"
];

A3W_allVoiceChatKeys = compileFinal str _voiceKeys;

Thanks for the reply. If i'm not worried about continuity with the other commands, I can just set case == 35 can't I?
  • Offline Matt76
  • Mercenary
  • *****
  • Posts: 418
  • co founder of customcombatgaming.com

Re: A simple script to add H to Holster on ANY mission file

« Reply #8 posted: Sep 23, 2016, 06:27 AM »
Thanks for the reply. If i'm not worried about continuity with the other commands, I can just set case == 35 can't I?

Yes chap