Animation-LuaScripting

From Spring
Revision as of 13:58, 22 August 2009 by Tobi (talk | contribs) (call-outs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The new callouts are defined in the Spring.UnitScript table.

Call-outs

Animation

Spring.UnitScript.SetPieceVisibility ( unitID, piece, boolean visible ) -> nil
Spring.UnitScript.Show ( unitID, piece ) -> nil
Spring.UnitScript.Hide ( unitID, piece ) -> nil

These may be used to show/hide pieces of the unit's model.


Spring.UnitScript.Move ( unitID, piece, axis, destination[, speed] ) -> nil

Move piece along axis to the destination position. If speed is given, the piece isn't moved immediately, but will move there at the desired speed. The X axis is mirrored compared to BOS/COB scripts, to match the direction of the X axis in Spring world space.


Spring.UnitScript.Turn ( unitID, piece, axis, destination[, speed] ) -> nil

Turn piece around axis to the destination angle. If speed is given, the piece isn't rotated immediately, but will turn at the desired angular velocity. Angles are in radians.


Spring.UnitScript.Spin ( unitID, piece, axis, speed[, accel] ) -> nil

Makes piece spin around axis at the desired angular velocity. If accel is given, the piece does not start at this velocity at once, but will accelerate to it. Both negative and positive angular velocities are supported. Accel should always be positive, even if speed is negative.


Spring.UnitScript.StopSpin ( unitID, piece, axis[, decel] ) -> nil

Stops a piece from spinning around the given axis. If decel is given, the piece does not stop at once, but will decelerate to it. Decel should always be positive. This function is similar to Spin(unitID, piece, axis, 0, decel), however, StopSpin also frees up the animation record.


Spring.UnitScript.IsMoving ( unitID, piece, axis ) -> boolean
Spring.UnitScript.IsTurning ( unitID, piece, axis ) -> boolean
Spring.UnitScript.IsSpinning ( unitID, piece, axis ) -> boolean

Returns true iff the piece is moving along the axis, or turning/spinning around the axis.


Spring.UnitScript.WaitForMove ( unitID, piece, axis ) -> nil
Spring.UnitScript.WaitForTurn ( unitID, piece, axis ) -> nil

Waits until the piece has stopped moving along / turning around the axis. If the piece is not animating, this functions return at once. You can not wait for a spin, because a spin does never finish.


Spring.UnitScript.Sleep ( unitID, milliseconds ) -> nil

Waits a number of milliseconds before returning.


Spring.UnitScript.StartThread ( unitID, function fun, ... ) -> nil

Starts a new (animation) thread, which will execute the function 'fun'. All arguments after the function are passed as-is as arguments to 'fun'. A thread is just a Lua thread, ie. a coroutine, so please refer to the Lua documentation about coroutines for exact semantics.


Effects

Spring.UnitScript.EmitSfx ( unitID, piece, id ) -> nil

Emits a particle from the given piece. The id may be one of: TODO


Spring.UnitScript.Explode ( unitID, piece, flags ) -> nil

Explodes a piece, optionally creating a particle which flies off. Typically used inside Killed. Explode does not hide the piece by itself; if using it outside Killed you may want to Hide the piece immediately after. The flags may be a combination of: TODO


Other

Spring.UnitScript.AttachUnit ( unitID, piece, passengerID ) -> nil
Spring.UnitScript.DetachUnit ( unitID, passengerID ) -> nil

Attaches or detaches another unit (a passenger, as this is designed for transports) to this unit. For AttachUnit, piece specifies the attachment point.


Spring.UnitScript.GetUnitValue ( ... ) -> number | number, number
Spring.UnitScript.SetUnitValue ( ... ) -> nil

This may be used instead of COB's get and set codes. It is recommended however, to use dedicated Lua functions (e.g. Spring.GetUnitHealth(unitID) instead of GetUnitValue(unitID, 4)): these functions should be considered a relic of the past.

Note that these are identical to Spring.GetUnitCOBValue and Spring.SetUnitCOBValue (see also Lua_SyncedCtrl#Lua_to_COB for the signature of those functions.)


Spring.UnitScript.SetSignalMask ( unitID, mask ) -> nil
Spring.UnitScript.Signal ( unitID, signal ) -> nil

These two support functions offer a powerful way to kill running threads. SetSignalMask assigns a mask to the currently running thread (any new threads started by this one will inherit the signal mask). Signal immediately stops all threads of this unit for which the bitwise and of mask and signal is not zero.