mistaparadox 10 Posted October 7, 2014 Hey guys, I'm a pretty new scripter here, so I've just been testing out experimental things, learning what I can. With this specific situation, I'm able to bind an animation to the Tab key, but when they press it, all that happens is the animation plays for a split second, then they go back to normal. What I want to happen is for them to be able to click Tab, have them stay in the animation until they want to click Tab again to go back to normal. I have all the files on hand if you'd like to see them. Thank you very much, -MistaParadox Share this post Link to post Share on other sites
jshock 513 Posted October 7, 2014 (edited) It sounds like you need to have it check for the key press, play the animation in a looping manner with a waitUntil key pressed again to break out of that loop. At least that's my best guess, I haven't used custom key bindings before, but that sounds like it could be the issue. So in a really simplistic concept look at the code: _pressed = false; waitUntil { key pressed }; _pressed = true; while (_pressed) do { //play animation if (key pressed) then {_pressed = false;}; sleep 5; //or whatever the time it takes to completed said animation }; Edited October 7, 2014 by JShock Share this post Link to post Share on other sites
dreadedentity 278 Posted October 7, 2014 Can you post the code for your displayAddEventHandler ["KeyDown", {}]? Share this post Link to post Share on other sites
iceman77 18 Posted October 7, 2014 (edited) Tested with an unarmed blufor unit in the SP editor. init.sqf MY_KEYDOWN_FNC = { toggled = toggled + 1; if (_this == 15) then { nul = [] execVM "keytest.sqf"; }; }; toggled = 0; waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","(_this select 1) call MY_KEYDOWN_FNC;false;"]; keyTest.sqf while {toggled == 1} do { if (animationState player != "AmovPercMstpSnonWnonDnon_Ease") then { player playMove "AmovPercMstpSnonWnonDnon_Ease"; }; }; player switchMove ""; toggled = 0; Edited October 7, 2014 by Iceman77 Share this post Link to post Share on other sites
dreadedentity 278 Posted October 7, 2014 (findDisplay 46) displayAddEventHandler ["KeyDown","(_this select 1) call MY_KEYDOWN_FNC;false;"]; My thoughts exactly, Iceman. It sounds like you forgot to return false. Returning false overrides the default behavior of the pressed key. Share this post Link to post Share on other sites
iceman77 18 Posted October 7, 2014 (edited) Updated for smooth transition, initial key press works and optimization. Tested with an unarmed Blufor soldier as the player, in the SP editor. init.sqf MY_KEYDOWN_FNC = { if (_this == 15) then { // using if instead of switch since it's faster when evaluating only one condition nul = [] execVM "keytest.sqf"; }; }; toggled = 0; waituntil {!(isNull (findDisplay 46))}; (findDisplay 46) displayAddEventHandler ["KeyDown","(_this select 1) call MY_KEYDOWN_FNC;false;"]; keytest.sqf toggled = toggled + 1; while {toggled == 1} do { if ((animationState player) != "AmovPercMstpSnonWnonDnon_Ease") then { player playMove "AmovPercMstpSnonWnonDnon_Ease"; }; }; if ((animationState player) != "AmovPercMstpSnonWnonDnon_EaseOut") then { player switchMove "AmovPercMstpSnonWnonDnon_EaseOut"; toggled = 0; }; Edited October 7, 2014 by Iceman77 Share this post Link to post Share on other sites
thesnypr 38 Posted November 28, 2016 lokking for something similar, i need to show a help screen and close it by pressing any key goout = false; (findDisplay 46) displaySetEventHandler ["KeyDown", "goout=true"]; waituntil {goout ==true}; i don't hundertand how to pass goout = false by goout = true before the waituntil?? Share this post Link to post Share on other sites
ProKosovich 13 Posted December 5, 2016 Worked for me, thanks. Share this post Link to post Share on other sites
Tajin 349 Posted December 5, 2016 For the love of god please avoid using hardcoded keybinds in scripts. Not everyone uses the same control layout. You might end up overwriting important keys for a user! Use the actionKeys command to get keybinds for default actions (if you want to overwrite something specific) or use one of the Useraction keybinds that users can set up. https://community.bistudio.com/wiki/inputAction/actions (the ones named "User1 - 20") Share this post Link to post Share on other sites