Unit

Associated namespace: sm.unit

A userdata object representing a unit in the game.

Values:

Functions:

Operations:

OperationDescription
Unit == UnitChecks if two instances of Unit refer to the same Unit.

character Character

Get:

Server only

Returns the character associated with a unit.


eyeHeight number

Set:

Server only

Sets the eye height for a unit


id integer

Get:

Server only

Returns the id of a unit.


publicData table

Get:

Server only

Returns (server) public data from a unit.

Set:

Server only

Sets (server) public data on a unit.


visionFrustum table

Set:

Server only

Sets the vision frustum for a unit

* self.unit.visionFrustum = {
*	 { 3.0, math.rad( 80.0 ),  math.rad( 80.0 ) },
*	 { 20.0, math.rad( 40.0 ), math.rad( 35.0 ) },
*	 { 40.0, math.rad( 20.0 ), math.rad( 20.0 ) }
* }

createState(unit, stateName)

Server only

Creates a Ai State from a name (See AiState)

Parameters:

TypeNameDescription
UnitunitThe unit.
stringstateNameName of predefined ai state.

Returns:

TypeDescription
AiState The ai state.

destroy(unit)

Server only

Destroy a unit

Parameters:

TypeNameDescription
UnitunitThe unit.

getCharacter(unit)

Server only

Returns the character associated with a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.

Returns:

TypeDescription
CharacterThe associated character.

getCurrentFacingDirection(unit)

Server only

Gets the current facing direction of a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.

Returns:

TypeDescription
Vec3The units facing direction.

getCurrentMovementDirection(unit)

Server only

Gets the current movement direction of a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.

Returns:

TypeDescription
Vec3The units movement direction.

getId(unit)

Server only

Returns the id of a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.

Returns:

TypeDescription
integerThe unit's id.

getPublicData(unit)

Server only

Returns (server) public data from a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.

Returns:

TypeDescription
tableThe public data.

sendCharacterEvent(unit, event)

Server only

Sends a event to the associated character of the unit.

Parameters:

TypeNameDescription
UnitunitThe unit.
stringeventThe event name.

setFacingDirection(unit, direction)

Server only

Sets the facing direction for a unit

Parameters:

TypeNameDescription
UnitunitThe unit.
Vec3directionThe desired facing direction.

setHearingData(unit, noiseScale)

Server only

Notifies a unit that it heard a sound

Parameters:

TypeNameDescription
UnitunitThe unit.
numbernoiseScaleThe noise amount.

setMovementDirection(unit, direction)

Server only

Sets the movement direction for a unit

Parameters:

TypeNameDescription
UnitunitThe unit.
Vec3directionThe desired movement direction.

setMovementType(unit, moveTypeName)

Server only

Sets the movment type for a unit

moveType can be "stand", "walk", "sprint" or "crouch"

Parameters:

TypeNameDescription
UnitunitThe unit.
stringmoveTypeNameThe movement type to set

setPublicData(unit, data)

Server only

Sets (server) public data on a unit.

Parameters:

TypeNameDescription
UnitunitThe unit.
tabledataThe public data.

setWantsJump(unit, wantJump)

Server only

Set a unit to jump

Parameters:

TypeNameDescription
UnitunitThe unit.
booleanwantJumpTrue if the unit should jump

setWhiskerData(unit, whiskerCount, maxAngle, startLength, endLength)

Server only

Sets the whisker data for obstacle avoidance

Parameters:

TypeNameDescription
UnitunitThe unit.
integerwhiskerCountThe whiskerCount.
numbermaxAngleThe maxAngle.
numberstartLengthThe startLength.
numberendLengthThe endLength.