Unit
A userdata object representing a unit in the game.
Values:
-
character[ Character ]Get: (Server-Only) Returns the character associated with a unit.
-
Set: (Server-Only) Sets the eye height for a unit
-
Get: (Server-Only) Returns the id of a unit.
-
Get: (Server-Only) Returns (server) public data from a unit.Set: (Server-Only) Sets (server) public data on a unit.
-
-
Set: (Server-Only) Sets the vision frustum for a unit
Value: Table of tables of 3 numbers, detectionRange, hFov and vFovlua * 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 ) } * }
-
Operations:
| Operation | Returns | Description |
|---|---|---|
Unit == Unit |
boolean | Checks if two instances of Unit refer to the same Unit. |
Server + Client
getContainer
unit:getContainer( index )
Returns the container stored in the given index inside the unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
index (optional) |
integer | The index of the container (default: 0). |
Returns:
| Type | Description |
|---|---|
| Container | The container. |
Server-only
addContainer
unit:addContainer( index, size, stackSize )
Creates and stores a container in the given index inside the unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
index |
integer | The index of the container [0-15]. |
size |
integer | The number of slots in the container. |
stackSize (optional) |
integer | The stack size. Defaults to maximum possible stack size(65535). |
Returns:
| Type | Description |
|---|---|
| Container | The created container. |
createState
unit:createState( stateName )
Creates a Ai State from a name (See AiState)
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
stateName |
string | Name of predefined ai state. |
Returns:
| Type | Description |
|---|---|
| AiState | The ai state. |
destroy
unit:destroy( )
Destroy a unit
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
getCharacter
unit:getCharacter( )
Returns the character associated with a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
Returns:
| Type | Description |
|---|---|
| Character | The associated character. |
getCurrentFacingDirection
unit:getCurrentFacingDirection( )
Gets the current facing direction of a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The units facing direction. |
getCurrentMovementDirection
unit:getCurrentMovementDirection( )
Gets the current movement direction of a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The units movement direction. |
getId
unit:getId( )
Returns the id of a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
Returns:
| Type | Description |
|---|---|
| integer | The unit's id. |
getPublicData
unit:getPublicData( )
Returns (server) public data from a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
Returns:
| Type | Description |
|---|---|
| table | The public data. |
removeContainer
unit:removeContainer( index )
Removes the container stored in the given index inside the unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
index |
integer | The index of the container. |
sendCharacterEvent
unit:sendCharacterEvent( event )
Sends a event to the associated character of the unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
event |
string | The event name. |
setFacingDirection
unit:setFacingDirection( direction )
Sets the facing direction for a unit
Parameters:
setHearingData
unit:setHearingData( noiseScale )
Notifies a unit that it heard a sound
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
noiseScale |
number | The noise amount. |
setMovementDirection
unit:setMovementDirection( direction )
Sets the movement direction for a unit
Parameters:
setMovementType
unit:setMovementType( moveTypeName )
Sets the movment type for a unit
moveType can be "stand", "walk", "sprint" or "crouch"
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
moveTypeName |
string | The movement type to set |
setPublicData
unit:setPublicData( data )
Sets (server) public data on a unit.
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
data |
table | The public data. |
setWantsCrouch
unit:setWantsCrouch( wantCrouch )
Set a unit to crouch
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
wantCrouch |
boolean | True if the unit should crouch |
setWantsJump
unit:setWantsJump( wantJump )
Set a unit to jump
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
wantJump |
boolean | True if the unit should jump |
setWhiskerData
unit:setWhiskerData( whiskerCount, maxAngle, startLength, endLength )
Sets the whisker data for obstacle avoidance
Parameters:
| Name | Type | Description |
|---|---|---|
unit |
Unit | The unit. |
whiskerCount |
integer | The whiskerCount. |
maxAngle |
number | The maxAngle. |
startLength |
number | The startLength. |
endLength |
number | The endLength. |