ShadowRanger24 50 Posted June 19, 2017 So I noticed that I haven't seen many missions use any sort of auto-run feature, so I decided to write my own script for it which I thought some people might want to use. I've put it into a KeyDown event handler to demonstrate how it could be implemented, but feel free to use it however you like. (findDisplay 46) displayAddEventHandler ["KeyDown", { params ["_control", "_dikCode", "_shift", "_ctrl", "_alt"]; private _handled = false; switch (_dikCode) do { // Key 0 case 11: { if (isNil "AR_active") then {AR_active = false;}; if (AR_active) exitWith {AR_active = false; _handled = true;}; if (!isNull objectParent player) exitWith {}; if (surfaceIsWater (getPos player)) exitWith {}; AR_active = true; AR_weapon = currentWeapon player; AR_animation = switch (true) do { case (AR_weapon isEqualTo ""): {"AmovPercMevaSnonWnonDf"}; case (AR_weapon isEqualTo (primaryWeapon player)): {"AmovPercMevaSlowWrflDf"}; case (AR_weapon isEqualTo (secondaryWeapon player)): {"AmovPercMevaSlowWrflDf"}; case (AR_weapon isEqualTo (handgunWeapon player)): {"AmovPercMevaSlowWpstDf"}; }; player playMoveNow AR_animation; player addEventHandler ["AnimChanged", { if ((!AR_active) || {!((currentWeapon player) isEqualTo AR_weapon)} || {!isNull objectParent player} || {surfaceIsWater (getPos player)}) exitWith { player removeEventHandler ["AnimChanged", _thisEventHandler]; AR_weapon = currentWeapon player; AR_animation = switch (true) do { case (AR_weapon isEqualTo ""): {"AmovPercMstpSnonWnonDnon"}; case (AR_weapon isEqualTo (primaryWeapon player)): {"AmovPercMstpSlowWrflDnon"}; case (AR_weapon isEqualTo (secondaryWeapon player)): {"AmovPercMevaSlowWlnrDf"}; case (AR_weapon isEqualTo (handgunWeapon player)): {"AmovPercMstpSlowWpstDnon"}; }; player playMoveNow AR_animation; AR_active = false; AR_weapon = nil; AR_animation = nil; }; player playMoveNow AR_animation; }]; _handled = true; }; }; _handled }]; There is only one caveat to this script that I've noticed, which is that when running up hills it doesn't slow you down like it would if you were to run up one normally. Updated (21/06/2017): - Auto run now automatically disables when the player runs into water or gets into a vehicle - Auto run can no longer be started if in water or a vehicle - Changed an occurrence of playMove to playMoveNow 5 1 Share this post Link to post Share on other sites
kremator 1065 Posted June 19, 2017 If you can run up hills without penalty it needs to be renamed IRONMAN or HERCULES script :) 2 Share this post Link to post Share on other sites
Tschuuut 6 Posted June 19, 2017 Looks nice. You can try to use something like https://community.bistudio.com/wiki/surfaceNormal to, to test if you are running up hills Share this post Link to post Share on other sites
bad benson 1733 Posted June 19, 2017 player addEventHandler ["KeyDown",... what's that? is this pseudo code? or did i miss something? interesting approach though. although i'd personally think about designign the mission in a way that something liek auto run is not needed. but i understand the need for it for dayZ like modes. Share this post Link to post Share on other sites
ShadowRanger24 50 Posted June 19, 2017 4 minutes ago, bad benson said: player addEventHandler ["KeyDown",... what's that? is this pseudo code? or did i miss something? You shouldn't be seeing it like that? For me it's like this: player addEventHandler ["KeyDown", { Share this post Link to post Share on other sites
bad benson 1733 Posted June 19, 2017 4 minutes ago, ShadowRanger24 said: You shouldn't be seeing it like that? For me it's like this: player addEventHandler ["KeyDown", { what i'm saying is that you need this (findDisplay 46) displayAddEventHandler ["Keydown",... maybe i just missed a few too many changelogs but what you did there i have never seen before. meaning: an eventhandler applied to an object that is of the type "keyDown". by my knowledge that type does only exist for display eventhandlers. i'm assuming you just confused yourself since your params look spot on for a display eventhandler. basically difference between https://community.bistudio.com/wiki/Arma_3:_Event_Handlers and https://community.bistudio.com/wiki/User_Interface_Event_Handlers 1 Share this post Link to post Share on other sites
ShadowRanger24 50 Posted June 19, 2017 1 minute ago, bad benson said: what i'm saying is that you need this (findDisplay 46) displayAddEventHandler ["Keydown",... maybe i just missed a few too many changelogs but what you did there i have never seen before. meaning: an eventhandler applied to an object that is of the type "keyDown". by my knowledge that type does only exist for display eventhandlers. i'm assuming you just confused yourself since your params look spot on for a display eventhandler. Oh wow I'm a goose completely didn't notice. I had this code implemented differently in my mission so I extracted it out and wasn't thinking when I put it in this thread. I've corrected it. Thanks for pointing that out. 1 Share this post Link to post Share on other sites
bad benson 1733 Posted June 19, 2017 1 minute ago, ShadowRanger24 said: Oh wow I'm a goose completely didn't notice. I had this code implemented differently in my mission so I extracted it out and wasn't thinking when I put it in this thread. just what i thought lol. no worries. just trying to help 2 Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted June 19, 2017 It's always a good idea to test a snippet before posting it on the forums. This holds true especially when extracting it out of your own framework. Just a quick paste into the debug console does suffice. For beginners scripting can be confusing enough without non working examples floating around in the forums. Cheers 2 Share this post Link to post Share on other sites
ShadowRanger24 50 Posted June 19, 2017 1 minute ago, Grumpy Old Man said: It's always a good idea to test a snippet before posting it on the forums. This holds true especially when extracting it out of your own framework. For beginners scripting can be confusing enough without non working examples floating around in the forums. Cheers Yeah I definitely will for future. This is my first script release so haven't done it many times before. Cheers for the advice though. 1 Share this post Link to post Share on other sites
xDrokZ 1 Posted June 20, 2017 Great job! Works fine so far. Im trying to make it beeing disabled when entering a vehicle, running up hills or entering water but no success yet. Maybe anyone else can help out :) This is what i got al least to make em not start running when already in water: https://pastebin.com/5fjbPh8F 1 Share this post Link to post Share on other sites
ShadowRanger24 50 Posted June 21, 2017 14 hours ago, xDrokZ said: Great job! Works fine so far. Im trying to make it beeing disabled when entering a vehicle, running up hills or entering water but no success yet. Maybe anyone else can help out :) This is what i got al least to make em not start running when already in water: https://pastebin.com/5fjbPh8F I updated the code to prevent auto run in water or in a vehicle and to automatically disable it if the player does so. Just gotta work on the running up hills part now. Share this post Link to post Share on other sites
bad benson 1733 Posted June 21, 2017 12 hours ago, ShadowRanger24 said: I updated the code to prevent auto run in water or in a vehicle and to automatically disable it if the player does so. Just gotta work on the running up hills part now. to check slope you can frequently check the player's positions height and the height of a position infront of him/her. Share this post Link to post Share on other sites
Isaac-Neo 11 Posted June 20, 2018 Any idea how to get this working with wasteland? Share this post Link to post Share on other sites
Isaac-Neo 11 Posted June 20, 2018 On 6/20/2017 at 10:44 PM, ShadowRanger24 said: Just gotta work on the running up hills part now. Umm please dont, we want to run up hills lolz Share this post Link to post Share on other sites
Donnie_Plays 435 Posted December 9, 2018 I have been toying around with this but cannot seem to get it to work. Where do I place the dik code for the key I want to use? I'm assuming this script is just going into an sqf and being executed on init.sqf? Share this post Link to post Share on other sites
EO 11275 Posted December 9, 2018 @Donnie_Plays If your still using Ravage these days, why not use it's autowalk/run feature... 1 Share this post Link to post Share on other sites
Donnie_Plays 435 Posted December 9, 2018 22 minutes ago, EO said: @Donnie_Plays If your still using Ravage these days, why not use it's autowalk/run feature... I actually figured out a solution already. I thought Ravage had an autowalk feature. There is an autorun with it? Share this post Link to post Share on other sites
pSiKO 124 Posted May 28, 2019 Hi everybody, it's an old version but still very useful, I give you my own version of this script - different animation added - stop when blocked - stop on any key I use a different addEventHandler (at the end of the animation) that makes the code smaller and the animation more fluid I add another EH binded on any key to stop running. I hope it's help, anyway thank you very much for your post! the example below uses the custom user action key # 2 // Alway run // from https://forums.bohemia.net/forums/topic/205916-release-auto-run-script/ // revisited by pSiKO (findDisplay 46) displayAddEventHandler ["KeyDown", { if (_this select 1 == (actionKeys 'User2') select 0) then { if (isNil "AR_active") then {AR_active = false}; if (AR_active) exitWith {AR_active = false}; if (!isNull objectParent player) exitWith {}; if (surfaceIsWater (getPos player)) exitWith {}; AR_active = true; AR_weapon = currentWeapon player; AR_animation = switch (true) do { case (AR_weapon isEqualTo ""): {"AmovPercMevaSnonWnonDf"}; case (AR_weapon isEqualTo (handgunWeapon player)): {"AmovPercMevaSlowWpstDf"}; case (AR_weapon isEqualTo (primaryWeapon player)): {"AmovPercMevaSlowWrflDf"}; case (AR_weapon isEqualTo (secondaryWeapon player)): {"AmovPercMevaSlowWlnrDf"}; }; player addEventHandler ["AnimDone", { if ((!AR_active) || {!((currentWeapon player) isEqualTo AR_weapon)} || {!isNull objectParent player} || {surfaceIsWater (getPos player)} || {_this select 1 == AR_animation && speed (vehicle player) <= 0}) exitWith { player removeEventHandler ["AnimDone", _thisEventHandler]; AR_active = false; AR_weapon = nil; AR_animation = nil; }; player playMoveNow AR_animation; }]; player playMoveNow AR_animation; }; }]; // Stop running (findDisplay 46) displayAddEventHandler ["KeyDown", { if (_this select 1 != (actionKeys 'User2') select 0) then { if (AR_active) then {AR_active = false}; }; }]; 1 Share this post Link to post Share on other sites
jimbouk1977 1 Posted August 29, 2019 Does this still work? Also what do you need to make it load correctly? Share this post Link to post Share on other sites
Donnie_Plays 435 Posted April 20, 2021 I cannot get this to work on a server. It will work MP hosted with friends, but for whatever reason it will not work on a server. Share this post Link to post Share on other sites
pierremgi 4862 Posted April 20, 2021 3 hours ago, Donnie_Plays said: I cannot get this to work on a server. It will work MP hosted with friends, but for whatever reason it will not work on a server. You need to run the code on every client anyway. The best place is in initPlayerLocal.sqf A dedicated server has no player. 1 Share this post Link to post Share on other sites
Donnie_Plays 435 Posted April 21, 2021 9 hours ago, pierremgi said: You need to run the code on every client anyway. The best place is in initPlayerLocal.sqf A dedicated server has no player. I'm running it on initPlayerLocal and it will not work on a server. It runs in MP hosted, but not an actual server. I'm troubleshooting the issue now. Share this post Link to post Share on other sites
RCA3 593 Posted April 21, 2021 (edited) There's this little trick for findDisplay on JIP sessions: if (hasInterface) then{ //bypass headless clients waitUntil {!isNull findDisplay 46}; //code here }; Edited April 21, 2021 by RCA3 1 1 Share this post Link to post Share on other sites
Donnie_Plays 435 Posted April 21, 2021 13 minutes ago, RCA3 said: There's this little trick for findDisplay on JIP sessions: waitUntil {!isNull findDisplay 46}; Add it before code. Working! Thank you! 1 Share this post Link to post Share on other sites