Jump to content

Recommended Posts

I've been using a script from an old thread for A2OA that I dug up to make a unit play a looping animation.

Using the method of adding the script in-mission (see post 4 of linked thread), it works perfectly. Only problem is is that after making the unit play a different animation (to transition into normal idling) the unit immediately begins looping the animation again.

I've tried using deleteVehicle on the object holding the script (a box I've placed outside the map) in various orders in relation to the script being called, but to no avail.

I therefore want to know how I can achieve this, is there a command to de-spawn the script?

Share this post


Link to post
Share on other sites

Change this:

animLoop = {_unit = _this select 0; _anim = _this select 1; while{alive _unit}do{_unit playMove _anim; waitUntil{animationState _unit != _anim}}}

To:

canDoAnimLoop = true; animLoop = {_unit = _this select 0; _anim = _this select 1; while{alive _unit && canDoAnimLoop}do{_unit playMove _anim; waitUntil{animationState _unit != _anim}}}

And in a trigger, or whenever you want to make the unit to stop:

canDoAnimLoop = false;
  • Like 1

Share this post


Link to post
Share on other sites

The reason why using deleteVehicle on the box does not delete the script is because the script is not really "attached" to that box and does not require the box to exist to run.  I think that might be how Papyrus works (in Skyrim editor) but Papyrus also has weird quirks where variables are not automatically freed when a script is finished and you have to manually delete them before the script ends.  In ArmA, all scripts are run in one of two places.  They either run in a scheduled or unscheduled environment.  How and where the script is run from determines which environment it runs in and what parameters are passed to it.  Once the script or code starts running, it is off on its own in scriptland doing its thing.

 

For code put in the init field of an object, it is simply run as part of the initialization code for the object when the object is created in game, and the reference to the object is passed to the magic variable "this" which you can think of as a parameter being passed to the code that you ran from the init field.  Basically, by putting code in the "init" field of an object, you aren't really attaching or linking a script to that object so much as you are telling the game to run that script when that object is initialized.  For convenience, it makes sense to do this if you want to quickly reference that object in the script as well, because of the useful "this" variable.  But after that, you can think of the script as "existing" on its own, somewhere out in space.  ESPECIALLY if you use spawn or execVM in the init field of the object.  When you do that, you are telling the game to create a new script and add it to the scheduler, and passing parameters to it.  This script could be anything, and the parameters could be anything, and it could be spawned or execVM'ed from any objects initialization field or a trigger or the mission initialization, whatever.

 

 

 

If you want to kill a script that is running in a scheduled environment (such as a script that is created with the "spawn" command) you may use the "terminate" command.

 

Spawn (and execVM) returns a script handle.  For example:

myScriptHandle = [scriptParameters] spawn {"my code"};

or with execVM:

myScriptHandle = [scriptParameters] execVM "MyScript.sqf";

If this script is designed to loop endlessly, but you wish to be able to stop it at some point in the future, you can do this to shut it down:

terminate myScriptHandle;

Alternatively, you could design the script to check some condition each time it loops, and exit the loop if the condition is met.  

 

Terminate is useful if the only thing you are trying to do is end the script at some time in the future.  However, terminating the script this way is not wholly useful if you want to terminate the script based on some property of the script itself, such as how many times to loop has run or how long the script has been running.  It is better to accomplish this within the loop inside the script itself.

  • Like 3

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

×