ayser 1 Posted August 10, 2012 So basically I want this script to choose an animation from a list at random, then play it on _man (this). I'm getting errors on line 7 "Switch ( _Anim ) do {". I'm still fairly new to this type of scripting. Can anyone lead me in the right direction? _man = _this select 0; _Anim = _this select 1; _RandomAnim = (random 4); _PlayingAnim == 0 Switch ( _Anim ) do { Case "Random": { If ( _RandomAnim == 0) then { _Anim = "AidlPercMstpSlowWrflDnon_i02"; }; If ( _RandomAnim == 1) then { _Anim = "AidlPercMstpSlowWrflDnon_i04"; }; If ( _RandomAnim == 2) then { _Anim = "AidlPercMstpSlowWrflDnon_i05"; }; If ( _RandomAnim == 3) then { _Anim = "AidlPercMstpSlowWrflDnon_i06"; }; }; }; While { _PlayingAnim == 0 } do { _PlayingAnim = 1; _man playMove _Anim hint "PLAYING MOVE"; sleep 3; _PlayingAnim = 0; }; Share this post Link to post Share on other sites
kylania 568 Posted August 10, 2012 Missing a ; after _PlayingAnim == 0 and _man playMove _Anim Share this post Link to post Share on other sites
ayser 1 Posted August 10, 2012 (edited) Missing a ; after _PlayingAnim == 0 and _man playMove _Anim Ohhhh, nice find, my eyes, blah :P I see that the character wont switch/play the animation when I have: _man playMove _Anim; but if I have: _man playMove "AidlPercMstpSlowWrflDnon_i06"; it'll play the animation. Am I doing something wrong? Tried it with switchMove too. Edited August 10, 2012 by ayser Easier on the eyes Share this post Link to post Share on other sites
kylania 568 Posted August 10, 2012 Try this: private["_man"]; _man = _this select 0; while {alive _man} do { //_anim = ["AidlPercMstpSlowWrflDnon_i02", "AidlPercMstpSlowWrflDnon_i04", "AidlPercMstpSlowWrflDnon_i05", "AidlPercMstpSlowWrflDnon_i06"] call BIS_fnc_selectRandom; //_anim = ["aidlpercmstpsraswrfldnon_idlesteady01n", "aidlpercmstpsraswrfldnon_idlesteady02n", "aidlpercmstpsraswrfldnon_idlesteady03n", "aidlpercmstpsraswrfldnon_idlesteady04n"] call BIS_fnc_selectRandom; _anim = ["aidlpknlmstpslowwrfldnon_idlesteady02", "aidlpknlmstpslowwrfldnon_idlesteady04", "aidlpercmstpsraswrfldnon_idlesteady03n", "aidlpercmstpsraswrfldnon_idlesteady04n"] call BIS_fnc_selectRandom; hint format["Playing animation %1", _anim]; _man playMoveNow _anim; sleep 3; }; First commented out list were your animations, I didn't see them on the animation list so replaced them with similar ones from ArmA2. They were extremely subtle though, so the active list is two standing and two kneeling ones so you can see it working. Share this post Link to post Share on other sites
ayser 1 Posted August 10, 2012 Try this: private["_man"]; _man = _this select 0; while {alive _man} do { //_anim = ["AidlPercMstpSlowWrflDnon_i02", "AidlPercMstpSlowWrflDnon_i04", "AidlPercMstpSlowWrflDnon_i05", "AidlPercMstpSlowWrflDnon_i06"] call BIS_fnc_selectRandom; //_anim = ["aidlpercmstpsraswrfldnon_idlesteady01n", "aidlpercmstpsraswrfldnon_idlesteady02n", "aidlpercmstpsraswrfldnon_idlesteady03n", "aidlpercmstpsraswrfldnon_idlesteady04n"] call BIS_fnc_selectRandom; _anim = ["aidlpknlmstpslowwrfldnon_idlesteady02", "aidlpknlmstpslowwrfldnon_idlesteady04", "aidlpercmstpsraswrfldnon_idlesteady03n", "aidlpercmstpsraswrfldnon_idlesteady04n"] call BIS_fnc_selectRandom; hint format["Playing animation %1", _anim]; _man playMoveNow _anim; sleep 3; }; First commented out list were your animations, I didn't see them on the animation list so replaced them with similar ones from ArmA2. They were extremely subtle though, so the active list is two standing and two kneeling ones so you can see it working. Works as intended, nice one :) Now adding a little thing. I want the animation to play only when _man's behavior is CARELESS/SAFE, and when he's not already doing an animation that's in the list... I've tried Behavior, but I think that's not what i'm supposed to use.. Basically - If Safe/careless/no animation being done, do an animation. This is what i've tried, with no success: while {(animationState _man == _Anim)} do { sleep 1; }; if (animationState _man != _Anim) then { _man switchMove _Anim }; Sleep 1; if (animationState _man != _Anim) then { _man switchMove "AidlPercMstpSrasWrflDnon_i13"}; Sleep 1; Instead, it does an animation every second. I think it's because since the "call BIS_fnc_selectRandom;", the _Anim and the animationState pull 2 random animations, and until they find the same one, it'll keep spamming. To try to remedy this, I tried making another list "_Animm" with the same animations as "_Anim", and did if (animationState _man != _Animm) then { _man switchMove _Anim }; Got a long error, and just undid the _Animm changes. How can I get the behavior trick to work? I took a look at ArmA 2 Scripting Commands, but can't seem to find anything close to isAnimation/isBehavior, or related. Share this post Link to post Share on other sites
ayser 1 Posted August 11, 2012 Still need a method for the above :( Share this post Link to post Share on other sites
Muzzleflash 111 Posted August 11, 2012 (edited) So basically I want this script to choose an animation from a list at random, then play it on _man (this). I'm getting errors on line 7 "Switch ( _Anim ) do {". I'm still fairly new to this type of scripting. Can anyone lead me in the right direction? Some couple of things: 1. You are missing some semi colons. I marked where they are missing in red. 2. You miswrote the statement in orange 3. random 4 does not give one of the numbers 0,1,2,3, it gives a number 0 <= X < 4, that is a number between 0 and 4 (that might have fractions eg. 2.134, so you if cases will almost always fail since 4.001 is not equal to 4) that might be 0 but will never be 4 exact. A correct way to get a number 0 <= X that is a whole number is: floor (random X); These are points 1 and 2 (and 3): _RandomAnim = [color="#FF8C00"](random 4);[/color] [color="#FF8C00"]_PlayingAnim == 0[/color] [color="#FF0000"];[/color] _man playMove _Anim[color="#FF0000"];[/color] So by fixing these you end up with: _man = _this select 0; _Anim = _this select 1; _RandomAnim =[color="#008000"] floor (random 4)[/color]; _PlayingAnim = [color="#008000"]0;[/color] Switch ( _Anim ) do { Case "Random": { If ( _RandomAnim == 0) then { _Anim = "AidlPercMstpSlowWrflDnon_i02"; }; If ( _RandomAnim == 1) then { _Anim = "AidlPercMstpSlowWrflDnon_i04"; }; If ( _RandomAnim == 2) then { _Anim = "AidlPercMstpSlowWrflDnon_i05"; }; If ( _RandomAnim == 3) then { _Anim = "AidlPercMstpSlowWrflDnon_i06"; }; }; }; While { _PlayingAnim == 0 } do { _PlayingAnim = 1; _man playMove _Anim[color="#008000"];[/color] hint "PLAYING MOVE"; sleep 3; _PlayingAnim = 0; }; You do realize that the while loop in the bottom will never finish right? As long as it _PlayingAnim == 0 it will run and right before that check you keep setting it to 0. Edited August 11, 2012 by Muzzleflash Share this post Link to post Share on other sites
ayser 1 Posted August 11, 2012 Some couple of things:1. You are missing some semi colons. I marked where they are missing in red. 2. You miswrote the statement in orange 3. random 4 does not give one of the numbers 0,1,2,3, it gives a number 0 <= X < 4, that is a number between 0 and 4 (that might have fractions eg. 2.134, so you if cases will almost always fail since 4.001 is not equal to 4) that might be 0 but will never be 4 exact. A correct way to get a number 0 <= X that is a whole number is: floor (random X); These are points 1 and 2 (and 3): _RandomAnim = [color="#FF8C00"](random 4);[/color] [color="#FF8C00"]_PlayingAnim == 0[/color] [color="#FF0000"];[/color] _man playMove _Anim[color="#FF0000"];[/color] So by fixing these you end up with: _man = _this select 0; _Anim = _this select 1; _RandomAnim =[color="#008000"] floor (random 4)[/color]; _PlayingAnim = [color="#008000"]0;[/color] Switch ( _Anim ) do { Case "Random": { If ( _RandomAnim == 0) then { _Anim = "AidlPercMstpSlowWrflDnon_i02"; }; If ( _RandomAnim == 1) then { _Anim = "AidlPercMstpSlowWrflDnon_i04"; }; If ( _RandomAnim == 2) then { _Anim = "AidlPercMstpSlowWrflDnon_i05"; }; If ( _RandomAnim == 3) then { _Anim = "AidlPercMstpSlowWrflDnon_i06"; }; }; }; While { _PlayingAnim == 0 } do { _PlayingAnim = 1; _man playMove _Anim[color="#008000"];[/color] hint "PLAYING MOVE"; sleep 3; _PlayingAnim = 0; }; You do realize that the while loop in the bottom will never finish right? As long as it _PlayingAnim == 0 it will run and right before that check you keep setting it to 0. I know that now :P I'm a messy scripter and usually do without thinking. I've got the following so far, since I deleted my bit of code yesterday and started using kylanias. Still getting the animation repeat. Is there a way to grab a animation from the animation list instead of using "call BIS_fnc_selectRandom;"? I think that's whats causing the problem for looping.. private["_man"]; _man = _this select 0; While { alive _man } do {// && !(animationState _man == _Anim) _Anim = [ "AidlPercMstpSlowWrflDnon_i02", "AidlPercMstpSlowWrflDnon_i04", "AidlPercMstpSlowWrflDnon_i05", "AidlPercMstpSlowWrflDnon_i06", "AidlPercMstpSlowWrflDnon_i07", "AidlPercMstpSlowWrflDnon_i08", "AidlPercMstpSlowWrflDnon_i09", "AidlPercMstpSlowWrflDnon_i10", "AidlPercMstpSlowWrflDnon_i11", "AidlPercMstpSlowWrflDnon_i12", "AidlPercMstpSlowWrflDnon_i13", "AidlPercMstpSrasWrflDnon01", "AidlPercMstpSrasWrflDnon02", "AidlPercMstpSrasWrflDnon03", "AidlPercMstpSrasWrflDnon04", "AidlPercMstpSrasWrflDnon05", "AidlPercMstpSrasWrflDnon06", "AidlPercMstpSrasWrflDnon_i01", "AidlPercMstpSrasWrflDnon_i02", "AidlPercMstpSrasWrflDnon_i03", "AidlPercMstpSrasWrflDnon_i04", "AidlPercMstpSrasWrflDnon_i05", "AidlPercMstpSrasWrflDnon_i06", "AidlPercMstpSrasWrflDnon_i07", "AidlPercMstpSrasWrflDnon_i08", "AidlPercMstpSrasWrflDnon_i09", "AidlPercMstpSrasWrflDnon_i10", "AidlPercMstpSrasWrflDnon_i11", "AidlPercMstpSrasWrflDnon_i12", "AidlPercMstpSrasWrflDnon_i13" ] call BIS_fnc_selectRandom; if (animationState _man != _Anim) then { hint "!= _Anim"; Sleep 2; _man switchMove _Anim }; if (animationState _man == _Anim) then { hint "== _Anim"; sleep 1; }; hint format["Playing animation %1", _Anim]; sleep 1; }; Share this post Link to post Share on other sites
kylania 568 Posted August 11, 2012 Is there a way to grab a animation from the animation list instead of using "call BIS_fnc_selectRandom;"? I think that's whats causing the problem for looping.. Yes, there is however the method for doing it is exactly what BIS_fnc_selectRandom does. It just does it with a single built in function call instead of having to write out what you wanted to do. _westAircraft = ["A10_US_EP1","AH64D_EP1","AH6J_EP1","CH_47F_EP1","MH6J_EP1","UH60M_EP1","UH60M_MEV_EP1"] call BIS_fnc_selectRandom; _reward = _westAircraft createVehicle getMarkerPos _spawnPoint; vs _westAircraft = ["A10_US_EP1","AH64D_EP1","AH6J_EP1","CH_47F_EP1","MH6J_EP1","UH60M_EP1","UH60M_MEV_EP1"]; _reward = _westAircraft select floor(random count _westAircraft) createVehicle getMarkerPos _spawnPoint; Share this post Link to post Share on other sites
Muzzleflash 111 Posted August 11, 2012 (edited) No BIS_fnc_selectRandom is not the cause. The cause is that it plays the animation but the script continues. It waits 1s and then plays an animation again. Instead you should wait for the animation to be over. Perhaps this will work. As long as the player is alive: We wait until he is ready (safe and not animating already). Then we animate and wait until ready again. private ["_currentAnim","_goodBehaviour","_readyForAnimation","_animation","_man","_animations"]; _man = _this select 0; //All the animations: _animations = [ "AidlPercMstpSlowWrflDnon_i02", "AidlPercMstpSlowWrflDnon_i04", "AidlPercMstpSlowWrflDnon_i05", "AidlPercMstpSlowWrflDnon_i06", "AidlPercMstpSlowWrflDnon_i07", "AidlPercMstpSlowWrflDnon_i08", "AidlPercMstpSlowWrflDnon_i09", "AidlPercMstpSlowWrflDnon_i10", "AidlPercMstpSlowWrflDnon_i11", "AidlPercMstpSlowWrflDnon_i12", "AidlPercMstpSlowWrflDnon_i13", "AidlPercMstpSrasWrflDnon01", "AidlPercMstpSrasWrflDnon02", "AidlPercMstpSrasWrflDnon03", "AidlPercMstpSrasWrflDnon04", "AidlPercMstpSrasWrflDnon05", "AidlPercMstpSrasWrflDnon06", "AidlPercMstpSrasWrflDnon_i01", "AidlPercMstpSrasWrflDnon_i02", "AidlPercMstpSrasWrflDnon_i03", "AidlPercMstpSrasWrflDnon_i04", "AidlPercMstpSrasWrflDnon_i05", "AidlPercMstpSrasWrflDnon_i06", "AidlPercMstpSrasWrflDnon_i07", "AidlPercMstpSrasWrflDnon_i08", "AidlPercMstpSrasWrflDnon_i09", "AidlPercMstpSrasWrflDnon_i10", "AidlPercMstpSrasWrflDnon_i11", "AidlPercMstpSrasWrflDnon_i12", "AidlPercMstpSrasWrflDnon_i13" ]; while {alive _man} do { //Assume unit is busy _readyForAnimation = false; while {not _readyForAnimation} do { sleep 1+(random 2); //Already playing animation? _currentAnim = animationState _man; //Current behaviour _goodBehaviour = (behaviour _man) in ["CARELESS", "SAFE"]; //Good behaviour and not currently performing animation? Then exit loop _readyForAnimation = _goodBehaviour && not (_currentAnim in _animations); }; //Now we ready for animation _animation = _animations call BIS_fnc_selectRandom; _man playMove _animation; sleep 5.0; }; I don't know what the animation is for not doing anything but I guess it could be differ on whether standing, kneeling and prone. Also sometimes when units stand still they perform "idle" animations so it can be tricky trying to figure out which animations are played when not doing anything. But if you find them then you can put them in an array (like _animations) called _idleAnims and add to the condition. In fact you can replace the condition: _readyForAnimation = _goodBehaviour && (_currentAnim in _idleAnims); Edited August 11, 2012 by Muzzleflash Share this post Link to post Share on other sites
ayser 1 Posted August 11, 2012 (edited) Just looked at this thread and saw a animation loop method. Tried the waitUntil that was there, and it works pretty well! private["_man"]; _man = _this select 0; While { alive _man } do {// && !(animationState _man == _Anim) _Anim = [ "AidlPercMstpSlowWrflDnon_i02", "AidlPercMstpSlowWrflDnon_i04", "AidlPercMstpSlowWrflDnon_i05", "AidlPercMstpSlowWrflDnon_i06", "AidlPercMstpSlowWrflDnon_i07", "AidlPercMstpSlowWrflDnon_i08", "AidlPercMstpSlowWrflDnon_i09", "AidlPercMstpSlowWrflDnon_i10", "AidlPercMstpSlowWrflDnon_i11", "AidlPercMstpSlowWrflDnon_i12", "AidlPercMstpSlowWrflDnon_i13", "AidlPercMstpSrasWrflDnon01", "AidlPercMstpSrasWrflDnon02", "AidlPercMstpSrasWrflDnon03", "AidlPercMstpSrasWrflDnon04", "AidlPercMstpSrasWrflDnon05", "AidlPercMstpSrasWrflDnon06", "AidlPercMstpSrasWrflDnon_i01", "AidlPercMstpSrasWrflDnon_i02", "AidlPercMstpSrasWrflDnon_i03", "AidlPercMstpSrasWrflDnon_i04", "AidlPercMstpSrasWrflDnon_i05", "AidlPercMstpSrasWrflDnon_i06", "AidlPercMstpSrasWrflDnon_i07", "AidlPercMstpSrasWrflDnon_i08", "AidlPercMstpSrasWrflDnon_i09", "AidlPercMstpSrasWrflDnon_i10", "AidlPercMstpSrasWrflDnon_i11", "AidlPercMstpSrasWrflDnon_i12", "AidlPercMstpSrasWrflDnon_i13" ] call BIS_fnc_selectRandom; if !(animationState _man == _Anim) then { hint "!= _Anim"; _man switchMove _Anim /**_man switchMove "AidlPercMstpSrasWrflDnon_i13"*/}; if (animationState _man == _Anim) then { hint format["Playing animation %1", _Anim]; waitUntil {!(animationState _man == _Anim)}; }; //hint format["Playing animation %1", _Anim]; sleep 0.2; }; I'm almost done.. Is there a way to find the behavior of a unit? I tried using " "CARELESS" = Behaviour _man ", but it wasn't working. Sorry for all the questions, still trying to grip on this Edit: Just saw your post muzzle, gonna try it now! Edited August 11, 2012 by ayser Share this post Link to post Share on other sites
Muzzleflash 111 Posted August 11, 2012 Just tested. Works fine, just be sure the unit is SAFE or CARELESS. Share this post Link to post Share on other sites