Jump to content
Sign in to follow this  
mistaparadox

Animations with Keybinds

Recommended Posts

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

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 by JShock

Share this post


Link to post
Share on other sites

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 by Iceman77

Share this post


Link to post
Share on other sites
(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

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 by Iceman77

Share this post


Link to post
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×