Skip to main content

NetPlayer

This is the client-side class for NetPlayer.

Class Instance Methods

Inherited methods from NetObject

NetObject:SetData(key: string, value: any): boolean

Sets generic data on the object on the client. Value must be a number, string, bool, vec2, vec3, vec4, or quat. Returns true if the data was set successfully, false otherwise (for unsupported types).

Parameters:

  • key: string - The key to store the data under
  • value: any - The value to store (must be a supported type)

Returns: boolean - true if the data was set successfully, false otherwise

Example:

local success = object:SetData("clientValue", 42)
if success then
print("Client data set successfully")
else
print("Failed to set client data")
end

NetObject:GetPosition(): vec3

Returns the position of the object.

Returns: vec3 - The position of the object

Example:

local position = object:GetPosition()
print("Object position: " .. tostring(position))

NetObject:GetRotation(): quat

Returns the rotation of the object.

Returns: quat - The rotation of the object

Example:

local rotation = object:GetRotation()
print("Object rotation: " .. tostring(rotation))

NetObject:GetEulerRotation(): vec3

Returns the Euler rotation of the object.

Returns: vec3 - Euler rotation

Example:

local eulerRotation = object:GetEulerRotation()
print("Object euler rotation: " .. tostring(eulerRotation))

NetObject:GetHealth(): number

Returns the current health of the object.

Returns: number - The current health of the object

Example:

local health = object:GetHealth()
print("Object health: " .. health)

NetObject:GetMaxHealth(): number

Returns the maximum health of the object.

Returns: number - The maximum health of the object

Example:

local maxHealth = object:GetMaxHealth()
print("Object max health: " .. maxHealth)

NetObject:GetVelocity(): vec3

Returns the velocity of the object.

Returns: vec3 - The velocity of the object

Example:

local velocity = object:GetVelocity()
print("Object velocity: " .. tostring(velocity))

NetObject:GetAngularVelocity(): vec3

Returns the angular velocity of the object.

Returns: vec3 - The angular velocity of the object

NetObject:GetNetId(): number

Returns the network ID of the object.

Returns: number - The network ID of the object

Example:

local netId = object:GetNetId()
print("Object network ID: " .. netId)

NetObject:GetData(key: string): any

Gets generic data from the object.

Parameters:

  • key: string - The key of the data to retrieve

Returns: any - The stored data value

Example:

local value = object:GetData("customValue")
print("Retrieved value: " .. tostring(value))

NetObject:AsPlayer(): NetPlayer | nil

Returns a NetPlayer instance if the object is a player, otherwise returns nil. This is a safe way to cast a NetObject to a NetPlayer.

Returns: NetPlayer instance if the object is a player, nil otherwise

Example:

-- Safe casting to NetPlayer
local netObject = someNetObject -- Assume this is a NetObject instance
local player = netObject:AsPlayer()

if player then
print("This is a player: " .. player:GetNick())
else
print("This is not a player")
end

NetObject:AsVehicle(): NetVehicle | nil

Returns a NetVehicle instance if the object is a vehicle, otherwise returns nil. This is a safe way to cast a NetObject to a NetVehicle.

Returns: NetVehicle instance if the object is a vehicle, nil otherwise

Example:

-- Safe casting to NetVehicle
local netObject = someNetObject -- Assume this is a NetObject instance
local vehicle = netObject:AsVehicle()

if vehicle then
print("This is a vehicle at position: " .. tostring(vehicle:GetPosition()))
else
print("This is not a vehicle")
end

NetObject:AsMountedGun(): NetMountedGun | nil

Returns a NetMountedGun instance if the object is a mounted gun, otherwise returns nil. This is a safe way to cast a NetObject to a NetMountedGun.

Returns: NetMountedGun instance if the object is a mounted gun, nil otherwise

Example:

-- Safe casting to NetMountedGun
local netObject = someNetObject -- Assume this is a NetObject instance
local mountedGun = netObject:AsMountedGun()

if mountedGun then
print("This is a mounted gun with health: " .. mountedGun:GetHealth())
else
print("This is not a mounted gun")
end

NetObject:AsRigidObject(): NetRigidObject | nil

Returns a NetRigidObject instance if the object is a rigid object, otherwise returns nil. This is a safe way to cast a NetObject to a NetRigidObject.

Returns: NetRigidObject instance if the object is a rigid object, nil otherwise

Example:

-- Safe casting to NetRigidObject
local netObject = someNetObject -- Assume this is a NetObject instance
local rigidObject = netObject:AsRigidObject()

if rigidObject then
print("This is a rigid object with velocity: " .. tostring(rigidObject:GetVelocity()))
else
print("This is not a rigid object")
end

NetObject:AsNPC(): NetNPC | nil

Returns a NetNPC instance if the object is an NPC, otherwise returns nil. This is a safe way to cast a NetObject to a NetNPC.

Returns: NetNPC instance if the object is an NPC, nil otherwise

Example:

-- Safe casting to NetNPC
local netObject = someNetObject -- Assume this is a NetObject instance
local npc = netObject:AsNPC()

if npc then
print("This is an NPC with ID: " .. npc:GetId())
else
print("This is not an NPC")
end

NetObject:AsTether(): NetTether | nil

Returns a NetTether instance if the object is a tether, otherwise returns nil. This is a safe way to cast a NetObject to a NetTether.

Returns: NetTether instance if the object is a tether, nil otherwise

Example:

-- Safe casting to NetTether
local netObject = someNetObject -- Assume this is a NetObject instance
local tether = netObject:AsTether()

if tether then
print("This is a tether")
else
print("This is not a tether")
end

NetObject:GetType(): NetObjectType

Returns the network object type. Use the NetObjectType enum to compare types.

Returns: The type of the network object as a NetObjectType enum value

Example:

-- Check object type
local netObject = someNetObject -- Assume this is a NetObject instance
local objectType = netObject:GetType()

if objectType == NetObjectType.Player then
print("This is a player object")
elseif objectType == NetObjectType.Vehicle then
print("This is a vehicle object")
end

NetPlayer:GetNick(): string

Returns the player's nickname.

Returns: string - The player's nickname

Example:

local nickname = player:GetNick()
print("Player nickname: " .. nickname)

NetPlayer:GetClient(): PlayerClient

Returns the PlayerClient instance.

Returns: PlayerClient - The PlayerClient instance for this player

Example:

local client = player:GetClient()
print("Player client: " .. client:GetNick())

NetPlayer:GetVehicle(): NetVehicle | nil

Returns the NetVehicle that the player is currently in. Returns nil if the player is not in a vehicle.

Returns: NetVehicle | nil - The vehicle the player is currently in, or nil if not in a vehicle

Example:

local vehicle = player:GetVehicle()
if vehicle then
print("Player is in vehicle ID: " .. vehicle:GetId())
else
print("Player is not in a vehicle")
end

NetPlayer:GetSkin(): string

Returns the skin name of the player.

Returns: string - The skin name of the player

Example:

local skinName = player:GetSkin()
print("Player skin: " .. skinName)

NetPlayer:GetWeaponName(slot: WeaponSlot): string

Returns the name of the weapon in the specified weapon slot.

Parameters:

  • slot: WeaponSlot - The weapon slot to check

Returns: string - The name of the weapon in the specified slot

Example:

local weaponName = player:GetWeaponName(WeaponSlot.Primary)
print("Primary weapon: " .. weaponName)

NetPlayer:GetAimPosition(): vec3

Returns the player's current aim position, based on the weapon they have equipped. For example, if the player does not have a weapon, this position will only reach out as far as the grappling hook goes (about 80m).

Returns: vec3 - The position the player is aiming at

Example:

local aimPos = player:GetAimPosition()
print("Player is aiming at: " .. tostring(aimPos))

NetPlayer:GoRagdoll(): void

Forces the Character into the ragdoll state.

Example:

-- Force player into ragdoll
player:GoRagdoll()

NetPlayer:IsRagdolling(): boolean

Returns true if the Character is currently ragdolling, false otherwise.

Returns: boolean - true if the character is ragdolling, false otherwise

Example:

if player:IsRagdolling() then
print("Player is ragdolling")
end

NetPlayer:IsGettingUpFromRagdoll(): boolean

Returns true if the Character is currently getting up from ragdoll, false otherwise.

Returns: boolean - true if the character is getting up from ragdoll, false otherwise

Example:

if player:IsGettingUpFromRagdoll() then
print("Player is getting up from ragdoll")
end

NetPlayer:UsingParachute(): boolean

Returns true if the Character is using a parachute, false otherwise.

Returns: boolean - true if the character is using a parachute, false otherwise

Example:

if player:UsingParachute() then
print("Player is using parachute")
end

NetPlayer:UsingWingsuit(): boolean

Returns true if the Character is using a wingsuit, false otherwise.

Returns: boolean - true if the character is using a wingsuit, false otherwise

Example:

if player:UsingWingsuit() then
print("Player is using wingsuit")
end

NetPlayer:GetPlayer(): Player

Returns the Player associated with this Character.

Returns: Player - The Player instance associated with this character

Example:

local player = netPlayer:GetPlayer()
print("Associated player: " .. player:GetNick())

NetPlayer:GetBonePosition(bone: Bone): vec3

Gets the world position of a specific bone on a character.

Parameters:

  • bone: Bone - The bone to get the position of

Returns: vec3 - The world position of the specified bone

Example:

local headPos = player:GetBonePosition(Bone.Head)
print("Player head position: " .. tostring(headPos))

NetPlayer:GetVehicle(): NetVehicle | nil

Returns the NetVehicle instance that the character is currently in. Returns nil if the character is not in a vehicle.

Returns: NetVehicle | nil - The vehicle the character is in, or nil if not in a vehicle

Example:

local vehicle = player:GetVehicle()
if vehicle then
print("Player is in vehicle: " .. vehicle:GetId())
else
print("Player is not in a vehicle")
end

NetPlayer:GetInventory(): table

Returns the character's inventory as a table containing weapon information.

Returns: table - The character's inventory data

Example:

local inventory = player:GetInventory()
print("Player has " .. #inventory .. " items in inventory")

NetPlayer:SetGhostMode(enabled: bool): void

Enables or disables ghost mode. When ghost mode is enabled, all collisions will be disabled for the character, allowing them to pass through entities, objects, and terrain.

Parameters:

  • enabled: bool - Whether to enable or disable ghost mode

Example:

-- Enable ghost mode
player:SetGhostMode(true)

-- Disable ghost mode
player:SetGhostMode(false)

NetPlayer:IsCloaked(): boolean

Returns true if the character is currently cloaked, false otherwise.

Returns: boolean - true if the character is cloaked, false otherwise

Example:

if player:IsCloaked() then
print("Player is cloaked")
else
print("Player is not cloaked")
end

NetPlayer:SetCloaked(enabled: bool): void

Enables or disables cloaked mode. When cloaked mode is enabled, the character will become mostly invisible with a shine on them.

Parameters:

  • enabled: bool - Whether to enable or disable cloaked mode

Example:

-- Enable cloaked mode
player:SetCloaked(true)

-- Disable cloaked mode
player:SetCloaked(false)

NetPlayer:SetOpacity(opacity: number): void

Sets the opacity of the character. Takes a value from 0-1 where 0 means invisible and 1 means fully opaque.

Parameters:

  • opacity: number - The opacity value (0-1)

Example:

-- Make player semi-transparent
player:SetOpacity(0.5)

-- Make player fully visible
player:SetOpacity(1.0)

-- Make player invisible
player:SetOpacity(0.0)

NetPlayer:GetGrappleTargetObject(): NetObject | nil

Returns the object that the player is targeting with their grappling hook, or nil if there is none.

Returns: NetObject | nil - The object being targeted with the grappling hook, or nil if none

Example:

local target = player:GetGrappleTargetObject()
if target then
print("Player is grappling towards: " .. target:GetType())
else
print("Player is not grappling towards anything")
end

NetPlayer:GetAABB(): AABB

Returns the axis-aligned bounding box (AABB) of the player in world space.

Returns: AABB - The world space bounding box of the player

Example:

local aabb = player:GetAABB()
print("Player AABB: " .. tostring(aabb))

NetPlayer:GetLocalAABB(): AABB

Returns the axis-aligned bounding box (AABB) of the player in local space.

Returns: AABB - The local space bounding box of the player

Example:

local localAABB = player:GetLocalAABB()
print("Player local AABB: " .. tostring(localAABB))

NetPlayer:IsHeadUnderwater(): bool

Returns true if the player's head is currently underwater, false otherwise.

Returns: bool - true if the player's head is underwater, false otherwise

Example:

if player:IsHeadUnderwater() then
print("Player's head is underwater")
end

NetPlayer:IsSwimming(): bool

Returns true if the player is currently swimming, false otherwise.

Returns: bool - true if the player is swimming, false otherwise

Example:

if player:IsSwimming() then
print("Player is swimming")
end

NetPlayer:GetOxygen(): float

Returns the player's current oxygen level. The default maximum oxygen is 60.

Returns: float - The current oxygen level

Example:

local oxygen = player:GetOxygen()
print("Player oxygen level: " .. oxygen)

NetPlayer:GetMaxOxygen(): float

Returns the player's maximum oxygen level.

Returns: float - The maximum oxygen level

Example:

local maxOxygen = player:GetMaxOxygen()
print("Player max oxygen: " .. maxOxygen)

NetPlayer:GetOxygenRecoveryRate(): float

Returns the player's oxygen recovery rate.

Returns: float - The oxygen recovery rate

Example:

local recoveryRate = player:GetOxygenRecoveryRate()
print("Oxygen recovery rate: " .. recoveryRate)

NetPlayer:SetOxygen(value: float): void

Sets the player's current oxygen level.

Parameters:

  • value: float - The oxygen level to set

Example:

player:SetOxygen(30.0)

NetPlayer:SetMaxOxygen(value: float): void

Sets the player's maximum oxygen level.

Parameters:

  • value: float - The maximum oxygen level to set

Example:

player:SetMaxOxygen(120.0)

NetPlayer:SetOxygenRecoveryRate(value: float): void

Sets the player's oxygen recovery rate.

Parameters:

  • value: float - The oxygen recovery rate to set

Example:

player:SetOxygenRecoveryRate(2.0)

NetPlayer:GetWetFactor(): float

Returns the player's wet factor (how wet the player is).

Returns: float - The wet factor (0.0 to 1.0)

Example:

local wetFactor = player:GetWetFactor()
print("Player wet factor: " .. wetFactor)

NetPlayer:GetSnowFactor(): float

Returns the player's snow factor (how much snow is on the player).

Returns: float - The snow factor (0.0 to 1.0)

Example:

local snowFactor = player:GetSnowFactor()
print("Player snow factor: " .. snowFactor)

NetPlayer:SetWetFactor(value: float): void

Sets the player's wet factor.

Parameters:

  • value: float - The wet factor to set (0.0 to 1.0)

Example:

player:SetWetFactor(0.5)

NetPlayer:SetSnowFactor(value: float): void

Sets the player's snow factor.

Parameters:

  • value: float - The snow factor to set (0.0 to 1.0)

Example:

player:SetSnowFactor(0.3)

NetPlayer:PlayAttachedEffect(effect: CharacterAttachedEffect, restartIfPlaying: bool): void

Plays a character attached effect on the player.

Parameters:

  • effect: CharacterAttachedEffect - The effect to play
  • restartIfPlaying: bool - Whether to restart the effect if it's already playing

Example:

player:PlayAttachedEffect(CharacterAttachedEffect.Fire, true)

NetPlayer:IsReloading(): bool

Returns true if the player is currently reloading their weapon, false otherwise.

Returns: bool - true if the player is reloading, false otherwise

Example:

if player:IsReloading() then
print("Player is reloading")
end

NetPlayer:IsFiring(): bool

Returns true if the player is currently firing their weapon, false otherwise.

Returns: bool - true if the player is firing, false otherwise

Example:

if player:IsFiring() then
print("Player is firing")
end

NetPlayer:HasFiredWeaponRecently(threshold: float): bool

Checks if the player has fired their current weapon within the last specified threshold seconds.

Parameters:

  • threshold: float - The time threshold in seconds

Returns: bool - true if the weapon has been fired recently, false otherwise

Example:

if player:HasFiredWeaponRecently(5.0) then
print("Player fired weapon within the last 5 seconds")
end