Unit
Associated namespace: sm.unit
A userdata object representing a unit in the game.
Values:
Functions:
- createState
- destroy
- getCharacter
- getCurrentFacingDirection
- getCurrentMovementDirection
- getId
- getPublicData
- sendCharacterEvent
- setFacingDirection
- setHearingData
- setMovementDirection
- setMovementType
- setPublicData
- setWantsJump
- setWhiskerData
Operations:
Operation | Description |
---|---|
Unit == Unit | Checks 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:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
string | stateName | Name of predefined ai state. |
Returns:
Type | Description |
---|---|
AiState The ai state. |
destroy(unit)
Server only
Destroy a unit
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
getCharacter(unit)
Server only
Returns the character associated with a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Returns:
Type | Description |
---|---|
Character | The associated character. |
getCurrentFacingDirection(unit)
Server only
Gets the current facing direction of a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Returns:
Type | Description |
---|---|
Vec3 | The units facing direction. |
getCurrentMovementDirection(unit)
Server only
Gets the current movement direction of a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Returns:
Type | Description |
---|---|
Vec3 | The units movement direction. |
getId(unit)
Server only
Returns the id of a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Returns:
Type | Description |
---|---|
integer | The unit's id. |
getPublicData(unit)
Server only
Returns (server) public data from a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Returns:
Type | Description |
---|---|
table | The public data. |
sendCharacterEvent(unit, event)
Server only
Sends a event to the associated character of the unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
string | event | The event name. |
setFacingDirection(unit, direction)
Server only
Sets the facing direction for a unit
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Vec3 | direction | The desired facing direction. |
setHearingData(unit, noiseScale)
Server only
Notifies a unit that it heard a sound
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
number | noiseScale | The noise amount. |
setMovementDirection(unit, direction)
Server only
Sets the movement direction for a unit
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
Vec3 | direction | The desired movement direction. |
setMovementType(unit, moveTypeName)
Server only
Sets the movment type for a unit
moveType can be "stand", "walk", "sprint" or "crouch"
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
string | moveTypeName | The movement type to set |
setPublicData(unit, data)
Server only
Sets (server) public data on a unit.
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
table | data | The public data. |
setWantsJump(unit, wantJump)
Server only
Set a unit to jump
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
boolean | wantJump | True if the unit should jump |
setWhiskerData(unit, whiskerCount, maxAngle, startLength, endLength)
Server only
Sets the whisker data for obstacle avoidance
Parameters:
Type | Name | Description |
---|---|---|
Unit | unit | The unit. |
integer | whiskerCount | The whiskerCount. |
number | maxAngle | The maxAngle. |
number | startLength | The startLength. |
number | endLength | The endLength. |