diff --git a/Sources/epoch_code/compile/EPOCH_AutoRun.sqf b/Sources/epoch_code/compile/EPOCH_AutoRun.sqf new file mode 100644 index 00000000..5e435554 --- /dev/null +++ b/Sources/epoch_code/compile/EPOCH_AutoRun.sqf @@ -0,0 +1,66 @@ +/* + Author: [Ignatz] He-Man + + Contributors: + + Description: + Autorun script + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_AutoRun.sqf +*/ + +private ["_myheight","_nextpos","_newheight"]; + +// _EPOCH_Autorunspeed is NOT a private variable, it is defined in Masterloop init! + +_myheight = (getposasl player) select 2; +_nextpos = player modelToWorld [0,1,0]; +_nextpos set [2,0]; +_newheight = (atltoasl _nextpos) select 2; +if (surfaceiswater position player || ((getposatl player) select 2) > 0.5) then { + _newheight = _myheight; +}; +if (_myheight-_newheight > 0.8 || _myheight-_newheight < -0.6) then { + if (_EPOCH_Autorunspeed != 1) then { + player playActionnow 'PlayerWalkF'; + } + else { + player playAction 'PlayerWalkF'; + }; + _EPOCH_Autorunspeed = 1; +} +else { + if (_myheight-_newheight > 0.5 || _myheight-_newheight < -0.35) then { + if (_EPOCH_Autorunspeed != 2) then { + player playActionnow 'PlayerSlowF'; + } + else { + player playAction 'PlayerSlowF'; + }; + _EPOCH_Autorunspeed = 2; + } + else { + if (getFatigue player < 0.8) then { + if (_EPOCH_Autorunspeed != 3) then { + player playActionnow 'FastF'; + } + else { + player playAction 'FastF'; + }; + _EPOCH_Autorunspeed = 3; + } + else { + if (_EPOCH_Autorunspeed != 2) then { + player playActionnow 'PlayerSlowF'; + } + else { + player playAction 'PlayerSlowF'; + }; + _EPOCH_Autorunspeed = 2; + }; + }; +}; diff --git a/Sources/epoch_code/compile/EPOCH_AutoRun_Check.sqf b/Sources/epoch_code/compile/EPOCH_AutoRun_Check.sqf new file mode 100644 index 00000000..d41a7c9f --- /dev/null +++ b/Sources/epoch_code/compile/EPOCH_AutoRun_Check.sqf @@ -0,0 +1,44 @@ +/* + Author: He-Man + + Contributors: + + Description: Check, if Player can Autorun + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_AutoRun_Check.sqf + + Usage: call EPOCH_AutoRun_Check; + + Returns: + BOOL +*/ + +private["_canAutoRun","_currentPos"]; +_canAutoRun = true; +if !(istouchingground player) exitwith { + false; +}; +if !((vehicle player) == player) exitwith { + false; +}; +if ((getPosasl player) select 2 < -0.5) exitwith { + false; +}; +if ((player getHitPointDamage "HitLegs") >= 0.5) exitwith { + ["Can not AutoRun - Your legs are Broken!",5] call Epoch_Message; + false; +}; +if !(player nearObjects["Const_All_Walls_F", 6] isEqualTo[]) then { + _currentPos = player modelToWorld [0, 1, 1]; + if !(surfaceIsWater _currentPos) then { + _currentPos = ATLtoASL _currentPos; + }; + if (lineIntersects[eyePos player, _currentPos, player, objNull]) then { + _canAutoRun = false; + }; +}; +_canAutoRun diff --git a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf index 4a2ede58..4d32ad7a 100644 --- a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf +++ b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf @@ -242,7 +242,12 @@ if (vehicle player == player) then { // _handled = call EPOCH_lootTrash; }; }; - + if (EPOCH_IsAutoRunning) then { + if (_dikCode in ((actionKeys "moveForward") + (actionKeys "TurnLeft") + (actionKeys "TurnRight") + (actionKeys "moveBack"))) then { + EPOCH_IsAutoRunning = false; + player switchMove ""; + }; + }; }; // end player only code EPOCH_favBar_itemConsumed = false; diff --git a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyUp.sqf b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyUp.sqf index 51960002..a065a922 100644 --- a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyUp.sqf +++ b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyUp.sqf @@ -47,5 +47,28 @@ if (_dikCode == EPOCH_keysAction) then { if (_dikCode in(actionKeys "Gear")) then { EPOCH_gearKeyPressed = false; }; +if (player == vehicle player) then { + if (_dikCode == EPOCH_keysAutoRun) then { + if (EPOCH_IsAutoRunning) then { + EPOCH_IsAutoRunning = false; + player switchMove ""; + } + else { + if (EPOCH_keysAutoRun in (actionKeys "moveForward")) then { + if (EPOCH_LastAutoRunKeyPressed + 0.2 > diag_ticktime) then { + if (call EPOCH_AutoRun_Check) then { + EPOCH_IsAutoRunning = true; + }; + }; + } + else { + if (call EPOCH_AutoRun_Check) then { + EPOCH_IsAutoRunning = true; + }; + }; + }; + EPOCH_LastAutoRunKeyPressed = diag_ticktime; + }; +}; _handled diff --git a/Sources/epoch_code/compile/setup/EPOCH_clientKeyMap.sqf b/Sources/epoch_code/compile/setup/EPOCH_clientKeyMap.sqf index 98040de3..0452d8fb 100644 --- a/Sources/epoch_code/compile/setup/EPOCH_clientKeyMap.sqf +++ b/Sources/epoch_code/compile/setup/EPOCH_clientKeyMap.sqf @@ -32,6 +32,7 @@ _keyMap = ["Action","EPOCH_keysAction",0x39], ["Holster Weapon", "EPOCH_keysHolster", 35], ["Debug Monitor", "EPOCH_keysDebugMon", 41], + ["AutoRun", "EPOCH_keysAutoRun", 0x11], ["Volume + (ctrl)","EPOCH_keysVolumeUp",0x0D], ["Volume - (ctrl)","EPOCH_keysVolumeDown",0x0C], diff --git a/Sources/epoch_code/compile/setup/masterLoop/Event0.sqf b/Sources/epoch_code/compile/setup/masterLoop/Event0.sqf new file mode 100644 index 00000000..bde43f25 --- /dev/null +++ b/Sources/epoch_code/compile/setup/masterLoop/Event0.sqf @@ -0,0 +1,12 @@ +// runs every 0.4 seconds + +if (EPOCH_IsAutoRunning) then { + if (call EPOCH_AutoRun_Check) then { + call EPOCH_AutoRun + } + else { + EPOCH_IsAutoRunning = false; + player switchMove ""; + ["Autorun stopped",5] call Epoch_Message; + }; +}; \ No newline at end of file diff --git a/Sources/epoch_code/compile/setup/masterLoop/init.sqf b/Sources/epoch_code/compile/setup/masterLoop/init.sqf index 1e41c494..d2819211 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/init.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/init.sqf @@ -111,7 +111,7 @@ _isOnFoot = isNull objectParent player; _panic = false; _prevEnergy = missionNamespace getVariable [_playerEnergyKey, _playerEnergyDefault]; - +_EPOCH_Autorunspeed = 1; // init config data _antagonistRndChance = ["CfgEpochClient", "antagonistRngChance", 100] call EPOCH_fnc_returnConfigEntryV2; diff --git a/Sources/epoch_code/init/client_init.sqf b/Sources/epoch_code/init/client_init.sqf index ec1049bf..65a1686c 100644 --- a/Sources/epoch_code/init/client_init.sqf +++ b/Sources/epoch_code/init/client_init.sqf @@ -57,6 +57,8 @@ EPOCH_arr_interactedObjs = []; EPOCH_buildOption = 0; EPOCH_nearestLocations = []; EPOCH_lastFiredLocation = []; +EPOCH_IsAutoRunning = false; +EPOCH_LastAutoRunKeyPressed = diag_ticktime; //Radiation EPOCH_geiger_shown = false; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index d04e569b..1cd7c5e0 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -49,6 +49,8 @@ class CfgClientFunctions class makeMarker {}; class removeMarker {}; class unit_onKilledEH {}; + class AutoRun_Check {}; + class AutoRun {}; }; class building { diff --git a/Sources/epoch_config/Configs/CfgMasterLoop.hpp b/Sources/epoch_config/Configs/CfgMasterLoop.hpp index 5d5ca975..36e58f7e 100644 --- a/Sources/epoch_config/Configs/CfgMasterLoop.hpp +++ b/Sources/epoch_config/Configs/CfgMasterLoop.hpp @@ -16,6 +16,10 @@ class CfgMasterLoop { condition = "alive player"; file = "epoch_code\compile\setup\masterLoop"; + class Event0 + { + delay = 0.4; + }; class Event1 { delay = 1; diff --git a/changelog.md b/changelog.md index b91c88f4..5f01c738 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,13 @@ All changes for [Arma 3](https://arma3.com/) [Epoch Mod](https://epochmod.com) a - Reduce rads over time at cost of immunity @Raymix - Wearable Male & Female wearable full radiation suit @Helion4 - December seasonal items (Santa / Snowman) @Helion4 +- Autorun function (suggested by Ghostrider) @He-Man + - Default Key is "W" + - You can change the key in EPOCH ESC Menu + - If choosen key is same as "moveforward" (default), you have to 2x tap it, else you only have to 1x tap it + - If your legs are broken, you get a hint "can not autorun - legs are broken" + - If the terrain is too steep, you only walk in AutoRun + - Inside Water, you can not Autorun ### Fixed - False BE kicks since Arma 3 1.80 update. - Nightlight now also follow players inside Vehicles @He-Man