Animation-LuaCallouts
The new callouts are defined in the Spring.UnitScript table.
Types for arguments are only shown where they're ambiguous. For a number of (common) arguments, the types are:
- unitID: number
- piece: number
- axis: number (1 = x axis, 2 = y axis, 3 = z axis)
- destination: number (world coors or radians)
- speed: number (world coors or radians per second)
- accel/decel: number (radians per second per frame)
- heading/pitch: number (radians)
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.
Threads
Spring.UnitScript.StartThread ( unitID, function fun, ... ) -> nil
Starts a new (animation) thread, which will execute the function 'fun'. All arguments except the function to run are passed as-is as arguments to 'fun' (this includes the unitID.) COB-Threads has a decent description on COB threads, which are mimicked here in Lua using coroutines.
Spring.UnitScript.SetSignalMask ( unitID, number mask ) -> nil
Spring.UnitScript.Signal ( unitID, number 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.
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, number milliseconds ) -> nil
Waits a number of milliseconds before returning.
Effects
Spring.UnitScript.EmitSfx ( unitID, piece, number id ) -> nil
Emits a particle from the given piece. The id may be one of: TODO
Spring.UnitScript.Explode ( unitID, piece, number 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.GetLongestReloadTime ( unitID ) -> number reloadTime
Returns max(reload time) of all the unit's weapons in milliseconds. This utility function exists to aid in porting BOS scripts, which have a SetMaxReloadTime call-in that is called immediately after Create.