bumyplum 10 Posted March 2, 2019 I'm trying to make a restrain script, how ever the player isn't being restrained whilst the variable is true, can some one tell me what i'm doing wrong here: _pla = player; _RestrainedQuery = _pla getvariable "Restrained"; While {_RestrainedQuery == "true"} do { _pla playmove "AmovPercMstpSnonWnonDnon_Ease"; }; hint str _RestrainedQuery; Share this post Link to post Share on other sites
bumyplum 10 Posted March 2, 2019 ///// After further research I have found works to detect if its true or false: _RestrainedQuery = player getvariable "Restrained"; if(_RestrainedQuery isEqualTo true ) then {hint "1"} else {hint "2";}; ///// How ever _RestrainedQuery = player getvariable "Restrained"; While {typename _RestrainedQuery == typename true} do { player playmove "AmovPercMstpSnonWnonDnon_Ease"; }; Restrains the player If _RestrainedQuery Is true, how ever when it's false it doesn't stop playing the move (Unrestrain them) Share this post Link to post Share on other sites
Leopard20 813 Posted March 2, 2019 49 minutes ago, bumyplum said: ///// After further research I have found works to detect if its true or false: _RestrainedQuery = player getvariable "Restrained"; if( typename _RestrainedQuery == typename true ) then {hint "1";} else {hint "2"}; ///// How ever _RestrainedQuery = player getvariable "Restrained"; While {typename _RestrainedQuery == typename true} do { player playmove "AmovPercMstpSnonWnonDnon_Ease"; }; Restrains the player If _RestrainedQuery Is true, how ever when it's false it doesn't stop playing the move (Unrestrain them) Maybe you should update the variable? Besides, don't use while for such stuff (at least not without sleep). You only need a loop that runs on each frame, at most. A while loop runs multiple times per frame and wastes performance. Do it like this instead: _pla = player; if (_pla getvariable ["Restrained", false]) then { waitUntil { _pla playmove "AmovPercMstpSnonWnonDnon_Ease"; !(_pla getvariable ["Restrained", false]) } }; _pla switchMove ""; You can make this even better (and prettier) with a little effort yourself. Edit: Fixed a couple of typos. Share this post Link to post Share on other sites
bumyplum 10 Posted March 2, 2019 10 minutes ago, Leopard20 said: Maybe you should update the variable? Besides, don't use while for such stuff (at least not without sleep). You only need a loop that runs on each frame, at most. A while loop runs multiple times per frame and wastes performance. Do it like this instead: _pla = player; if (_pla getvariable ["Restrained", false]) then { waitUntil { _pla playmove "AmovPercMstpSnonWnonDnon_Ease"; !(_pla getvariable ["Restrained", false]) } } The animation "AmovPercMstpSnonWnonDnon_Ease" doesn't look and the only way to get the player to stay in the animation you have to keep running it on them Share this post Link to post Share on other sites
Leopard20 813 Posted March 2, 2019 3 minutes ago, bumyplum said: The animation "AmovPercMstpSnonWnonDnon_Ease" doesn't look and the only way to get the player to stay in the animation you have to keep running it on them I know. That's what waitUntil is for. While is not needed. Share this post Link to post Share on other sites
bumyplum 10 Posted March 2, 2019 7 minutes ago, Leopard20 said: I know. That's what waitUntil is for. While is not needed. I don't seem to be able to get wait until to work, it still only plays the animation once _RestrainedQuery = player getvariable "Restrained"; _pla = player; if (_RestrainedQuery isEqualTo true) then { waitUntil { _pla playmove "AmovPercMstpSnonWnonDnon_Ease"; !(_RestrainedQuery isEqualTo true) } } Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted March 2, 2019 1 hour ago, bumyplum said: !(_RestrainedQuery isEqualTo true) Don't do stuff like that, it's terrible practice and nonsensical. It's hard to tell at first glance what you're trying to check. You can simply condense it down to !_RestrainedQuery And that's it. Also naming convention could be better since the variable name doesn't really tell you anything about the contents of a variable. If it's a bool you can use something like _isRestrained or similar. To make an animation play only when needed use animationState or an animation eventhandler, not a waitUntil loop that's getting executed on every frame. Cheers 1 Share this post Link to post Share on other sites
bumyplum 10 Posted March 2, 2019 50 minutes ago, Grumpy Old Man said: To make an animation play only when needed use animationState or an animation eventhandler, not a waitUntil loop that's getting executed on every frame. Cheers 2 When i use an animation event handler the character just replays the same animation Share this post Link to post Share on other sites
HazJ 1288 Posted March 2, 2019 Use KeyDown handler. If key pressed, prevent action. Have whitelist keys for whatever like Esc, etc... https://community.bistudio.com/wiki/User_Interface_Event_Handlers 1 Share this post Link to post Share on other sites