Update keyboard eventhandler and add rules.sqf

See: https://github.com/EpochModTeam/DayZ-Epoch/pull/1673
This commit is contained in:
ebaydayz
2016-02-16 21:59:01 -05:00
parent 23179c079f
commit 441e9fb231
84 changed files with 1530 additions and 245 deletions

View File

@@ -1,205 +0,0 @@
private ["_dikCode","_handled","_primaryWeapon","_secondaryWeapon","_nearbyObjects","_nill","_shift","_ctrl","_alt","_dropPrimary","_dropSecondary","_iItem","_removed","_iPos","_radius","_item"];
_dikCode = _this select 1;
_handled = false;
if (_dikCode in[0x02,0x03,0x04,0x58,0x57,0x44,0x43,0x42,0x41,0x40,0x3F,0x3E,0x3D,0x3C,0x3B,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05]) then {
_handled = true;
};
if ((_dikCode == 0x3E || _dikCode == 0x0F || _dikCode == 0xD3)) then {
if(diag_tickTime - dayz_lastCheckBit > 10) then {
dayz_lastCheckBit = diag_tickTime;
call dayz_forceSave;
};
call dayz_EjectPlayer;
};
// esc
if (_dikCode == 0x01) then {
DZE_cancelBuilding = true;
call dayz_EjectPlayer;
};
// Disable ESC after death
if (_dikCode == 0x01 && r_player_dead) then {
_handled = true;
};
// surrender
if (_dikCode in actionKeys "Surrender") then {
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_canDo = (!r_drag_sqf && !r_player_unconscious && !_onLadder && !_inVehicle);
if (_canDo && !DZE_Surrender && !(player isKindOf "PZombie_VB")) then {
DZE_Surrender = true;
_dropPrimary = false;
_dropSecondary = false;
_primaryWeapon = primaryWeapon player;
if (_primaryWeapon != "") then {_dropPrimary = true;};
_secondaryWeapon = "";
{
if ((getNumber (configFile >> "CfgWeapons" >> _x >> "Type")) == 2) exitWith {
_secondaryWeapon = _x;
};
} count (weapons player);
if (_secondaryWeapon != "") then {_dropSecondary = true;};
if (_dropPrimary || _dropSecondary) then {
player playActionNow "PutDown";
_iPos = getPosATL player;
_radius = 1;
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item setposATL _iPos;
if (_dropPrimary) then {
_iItem = _primaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
if (_dropSecondary) then {
_iItem = _secondaryWeapon;
_removed = ([player,_iItem,1] call BIS_fnc_invRemove);
if (_removed == 1) then {
_item addWeaponCargoGlobal [_iItem,1];
};
};
player reveal _item;
};
// set publicvariable that allows other player to access gear
player setVariable ["DZE_Surrendered", true, true];
// surrender animation
player playMove "AmovPercMstpSsurWnonDnon";
};
_handled = true;
};
if (_dikCode in actionKeys "MoveForward") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveLeft") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveRight") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
if (_dikCode in actionKeys "MoveBack") exitWith {r_interrupt = true; if (DZE_Surrender) then {call dze_surrender_off};};
//Prevent exploit of glitching through doors
if (_dikCode in actionKeys "Prone") then {
_doors = nearestObjects [player, DZE_DoorsLocked, 3];
if (count _doors > 0) then {
_handled = true;
};
};
//Prevent exploit of drag body
if ((_dikCode in actionKeys "Prone") && r_drag_sqf) exitWith { force_dropBody = true; };
if ((_dikCode in actionKeys "Crouch") && r_drag_sqf) exitWith { force_dropBody = true; };
_shift = _this select 2;
_ctrl = _this select 3;
_alt = _this select 4;
//diag_log format["Keypress: %1", _this];
if ((_dikCode in actionKeys "Gear") && (vehicle player != player) && !_shift && !_ctrl && !_alt && !dialog) then {
createGearDialog [player, "RscDisplayGear"];
_handled = true;
};
if (_dikCode in (actionKeys "GetOver")) then {
if (player isKindOf "PZombie_VB") then {
_handled = true;
DZE_PZATTACK = true;
} else {
_nearbyObjects = nearestObjects[getPosATL player, dayz_disallowedVault, 8];
if (count _nearbyObjects > 0) then {
if((diag_tickTime - dayz_lastCheckBit > 4)) then {
[objNull, player, rSwitchMove,"GetOver"] call RE;
player playActionNow "GetOver";
dayz_lastCheckBit = diag_tickTime;
} else {
_handled = true;
};
};
};
};
//if (_dikCode == 57) then {_handled = true}; // space
//if (_dikCode in actionKeys 'MoveForward' || _dikCode in actionKeys 'MoveBack') then {r_interrupt = true};
if (_dikCode == 210) then {
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
if (_dikCode in actionKeys "ForceCommandingMode") then {_handled = true};
if (_dikCode in actionKeys "PushToTalk" && (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "VoiceOverNet" && (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,50,true,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "PushToTalkDirect" && (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "Chat" && (diag_tickTime - dayz_lastCheckBit > 10)) then {
dayz_lastCheckBit = diag_tickTime;
[player,15,false,(getPosATL player)] spawn player_alertZombies;
};
if (_dikCode in actionKeys "User20" && (diag_tickTime - dayz_lastCheckBit > 5)) then {
dayz_lastCheckBit = diag_tickTime;
_nill = execvm "\z\addons\dayz_code\actions\playerstats.sqf";
};
// numpad 8 0x48 now pgup 0xC9 1
if ((_dikCode == 0xC9 && (!_alt || !_ctrl)) || (_dikCode in actionKeys "User15")) then {
DZE_Q = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 && (!_alt || !_ctrl)) || (_dikCode in actionKeys "User16")) then {
DZE_Z = true;
};
// numpad 8 0x48 now pgup 0xC9 0.1
if ((_dikCode == 0xC9 && (_alt && !_ctrl)) || (_dikCode in actionKeys "User13")) then {
DZE_Q_alt = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 && (_alt && !_ctrl)) || (_dikCode in actionKeys "User14")) then {
DZE_Z_alt = true;
};
// numpad 8 0x48 now pgup 0xC9 0.01
if ((_dikCode == 0xC9 && (!_alt && _ctrl)) || (_dikCode in actionKeys "User7")) then {
DZE_Q_ctrl = true;
};
// numpad 2 0x50 now pgdn 0xD1
if ((_dikCode == 0xD1 && (!_alt && _ctrl)) || (_dikCode in actionKeys "User8")) then {
DZE_Z_ctrl = true;
};
// numpad 4 0x4B now Q 0x10
if (_dikCode == 0x10 || (_dikCode in actionKeys "User17")) then {
DZE_4 = true;
};
// numpad 6 0x4D now E 0x12
if (_dikCode == 0x12 || (_dikCode in actionKeys "User18")) then {
DZE_6 = true;
};
// numpad 5 0x4C now space 0x39
if (_dikCode == 0x39 || (_dikCode in actionKeys "User19")) then {
DZE_5 = true;
};
// F key
if ((_dikCode == 0x21 && (!_alt && !_ctrl)) || (_dikCode in actionKeys "User6")) then {
DZE_F = true;
};
_handled

View File

@@ -0,0 +1,214 @@
private ["_event", "_onLadder", "_inVehicle", "_isOk", "_primary", "_current", "_rifle", "_pistol", "_melee"];
_event = if (count _this > 1) then { _this select 3 } else { _this select 0 };
_findRifle = {
private ["_return", "_primary"];
_return = "";
_primary = primaryWeapon player;
if (_primary != "") then {
if !(_primary in MeleeWeapons) then {
_return = _primary;
};
};
if (dayz_onBack != "" && _return == "") then {
if !(dayz_onBack in MeleeWeapons) then {
_return = dayz_onBack;
};
};
_return;
};
_findMelee = {
private ["_return", "_primary"];
_return = "";
_primary = primaryWeapon player;
if (_primary != "") then {
if (_primary in MeleeWeapons) then {
_return = _primary;
};
};
if (dayz_onBack != "" && _return == "") then {
if (dayz_onBack in MeleeWeapons) then {
_return = dayz_onBack;
};
};
_return;
};
_findPistol = {
private ["_return"];
_return = "";
{
if (getNumber (configFile >> "CfgWeapons" >> _x >> "type") == 2) then {
_return = _x;
};
} foreach (weapons player);
_return;
};
_selectMuzzle = {
private ["_return", "_wpn", "_muzzles"];
_wpn = _this select 0;
_muzzles = getArray(configFile >> "cfgWeapons" >> _wpn >> "muzzles");
if (_muzzles select 0 != "this") then {
_return = (_muzzles select 0);
} else {
_return = _wpn;
};
_return;
};
_clearActions = {
if (s_player_equip_carry > -1) then {
player removeAction s_player_equip_carry;
s_player_equip_carry = -1;
};
};
_switchPrimary = {
private ["_primary", "_current"];
_primary = primaryWeapon player;
_current = currentWeapon player;
_timer = 0;
[] call _clearActions;
if (_primary != "") then {
// check if player is still in the 'open gear' animation state and force him out of it (caused major issues)
_animState = animationState player;
switch (true) do {
// current weapon is a rifle
case (_animState == "amovpknlmstpsraswrfldnon_gear" || _animState == "amovpercmstpsraswrfldnon_gear"): {
player playMove "amovpknlmstpslowwrfldnon_amovpknlmstpsraswrfldnon";
waitUntil { animationState player == "amovpknlmstpslowwrfldnon_amovpknlmstpsraswrfldnon" };
};
// current weapon is a pistol
case (_animState == "amovpknlmstpsraswpstdnon_gear" || _animState == "amovpercmstpsraswpstdnon_gear"): {
player playMove "amovpknlmstpslowwpstdnon_gear_amovpknlmstpsraswpstdnon";
waitUntil { animationState player == "amovpknlmstpslowwpstdnon_gear_amovpknlmstpsraswpstdnon" };
};
// is standing with weapon lowered
case (["aidlpercmstpslowwrfldnon", _animState] call fnc_inString): {
player playMove "amovpercmstpslowwrfldnon_amovpercmstpsraswrfldnon";
waitUntil { animationState player == "amovpercmstpslowwrfldnon_amovpercmstpsraswrfldnon" };
};
};
player removeWeapon _primary;
// make sure animation is playing to prevent instant switch (if current weapon is not pisol)
if (!dayz_quickSwitch) then {
if (_current != [] call _findPistol) then {
_timeout = diag_tickTime + 2;
_animArray = [
"amovpercmstpsraswrfldnon_amovpercmstpsnonwnondnon", // is standing, has no pistol / is crouched, has no pistol
"amovpercmstpsraswrfldnon_amovpercmstpsraswpstdnon", // is standing, has pistol
"amovpknlmstpsraswrfldnon_amovpknlmstpsraswpstdnon", // is crouched, has pistol
"amovppnemstpsraswrfldnon_amovppnemstpsnonwnondnon", // is prone, has no pistol
"amovppnemstpsraswrfldnon_amovppnemstpsraswpstdnon" // is prone, has pistol
];
waitUntil { (animationState player) in _animArray || diag_tickTime >= _timeout };
waitUntil { !((animationState player) in _animArray) || diag_tickTime >= _timeout };
};
};
};
if (dayz_onBack != "") then {
player addWeapon dayz_onBack;
player selectWeapon ([dayz_onBack] call _selectMuzzle);
};
dayz_onBack = _primary;
call dayz_meleeMagazineCheck;
};
_switchPrimaryUI = {
private ["_primary", "_current"];
_primary = primaryWeapon player;
_current = currentWeapon player;
[] call _clearActions;
if (_primary != "") then {
player removeWeapon _primary;
};
if (dayz_onBack != "") then {
player addWeapon dayz_onBack;
if (_primary == _current) then {
player selectWeapon ([dayz_onBack] call _selectMuzzle);
};
};
dayz_onBack = _primary;
[[(findDisplay 106)],"onLBSelChanged"] execVM "\z\addons\dayz_code\system\handleGear.sqf"; // update gear dialog
};
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_inVehicle = (vehicle player != player);
_isOK = (!_onLadder && !_inVehicle && !r_player_unconscious && !dayz_onBackActive);
if (_isOK) then { dayz_onBackActive = true };
switch (_event) do {
case "action": {
if (_isOK) then {
[] call _switchPrimary;
};
};
case "gear": {
[] call _switchPrimaryUI;
};
case "rifle": {
if (_isOK) then {
_rifle = [] call _findRifle;
if (_rifle != "") then {
if (_rifle == dayz_onBack) then {
[] call _switchPrimary;
} else {
player selectWeapon ([_rifle] call _selectMuzzle);
};
};
};
};
case "pistol": {
if (_isOK) then {
_pistol = [] call _findPistol;
if (_pistol != "") then {
player selectWeapon ([_pistol] call _selectMuzzle);
};
};
};
case "melee": {
if (_isOK) then {
_melee = [] call _findMelee;
if (_melee != "") then {
if (_melee == dayz_onBack) then {
[] call _switchPrimary;
} else {
player selectWeapon ([_melee] call _selectMuzzle);
};
};
};
};
};
if (_isOK) then { dayz_onBackActive = false };