Skip to main content

NetPlayer

This is the server-side class for NetPlayer.

Class Instance Methods

Inherited methods from NetObject

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

Sets generic data on the object. Value must be a number, string, bool, vec2, vec3, vec4, or quat. If broadcast is true, the data will be synchronized to all clients. 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)
  • broadcast: bool - Whether to synchronize the data to all clients

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

Example:

-- Set data and broadcast to all clients
local success = object:SetData("serverValue", 100, true)
if success then
print("Data set and broadcast successfully")
else
print("Failed to set data")
end

-- Set data only on server
local success = object:SetData("localValue", 50, false)

NetObject:SetHealth(health: number): void

Sets the health of the network object. This change is synchronized to all players.

Parameters:

  • health: number - The new health value for the object

Example:

-- Set object health to 100
object:SetHealth(100)

NetObject:SetMaxHealth(value: int): void

Sets the maximum health of the network object. This change is synchronized to all players.

Parameters:

  • value: int - The new maximum health value for the object

Example:

-- Set object max health to 200
object:SetMaxHealth(200)

NetObject:SetPosition(position: vec3): void

Sets the position of the network object. This change is synchronized to all players.

Parameters:

  • position: vec3 - The new position for the object

Example:

-- Teleport object to a new position
object:SetPosition(vec3(100, 50, 200))

NetObject:SetRotation(rotation: quat): void

Sets the rotation of the network object. This change is synchronized to all players.

Parameters:

  • rotation: quat - The new rotation for the object

Example:

-- Rotate object to face north
object:SetRotation(quat(0, 0, 1, 0))

NetObject:SetVelocity(velocity: vec3): void

Sets the velocity of the network object. This change is synchronized to all players.

Parameters:

  • velocity: vec3 - The new velocity for the object

Example:

-- Launch object forward at high speed
object:SetVelocity(vec3(100, 0, 0))

NetObject:SetAngularVelocity(velocity: vec3): void

Sets the angular velocity (rotation speed around each axis) of the network object. This change is synchronized to all players. Note: This method works only for anything but NetPlayer.

Parameters:

  • velocity: vec3 - The new angular velocity for the object (in radians per second)

Example:

-- Make object spin around Y axis
object:SetAngularVelocity(vec3(0, 5, 0))

-- Stop rotation
object:SetAngularVelocity(vec3(0, 0, 0))

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:Respawn(position: vec3, health: number, maxHealth: number): void

Respawns the player at the given position with the given health and max health.

Parameters:

  • position: vec3 - The position to respawn the player at
  • health: number - The health to set for the respawned player
  • maxHealth: number - The maximum health to set for the respawned player

Example:

player:Respawn(vec3(0, 0, 0), 100, 100)

NetPlayer:GiveWeapon(name: string, ammo: number, slot: WeaponSlot): void

Gives a weapon to the player with specified ammo count. View the full list of weapons here.

Parameters:

  • name: string - The name of the weapon to give
  • ammo: number - The amount of ammo to give with the weapon
  • slot: WeaponSlot - The weapon slot to place the weapon in

Example:

player:GiveWeapon("SMG", 120, WeaponSlot.Primary)

NetPlayer:RemoveWeapon(slot: WeaponSlot): void

Removes a weapon from the specified weapon slot.

Parameters:

  • slot: WeaponSlot - The weapon slot to remove the weapon from

Example:

player:RemoveWeapon(WeaponSlot.Primary)

NetPlayer:SetWeaponAmmo(slot: WeaponSlot, mode: WeaponMode, ammo: number): void

Sets the ammo for a weapon in a specific slot and module (mode).

Parameters:

  • slot: WeaponSlot - The weapon slot to target. See WeaponSlot.
  • mode: WeaponMode - The weapon mode/module to target. See WeaponMode.
  • ammo: number - The ammo amount to set.

Example:

player:SetWeaponAmmo(WeaponSlot.Primary, WeaponMode.Primary, 90)

NetPlayer:SetInventoryAmmo(type: AmmoType, ammo: number): void

Sets the inventory ammo for the specified ammo type.

Parameters:

  • type: AmmoType - The ammo type to set. See AmmoType.
  • ammo: number - The ammo amount to set.

Example:

player:SetInventoryAmmo(AmmoType.SMG, 300)

NetPlayer:Teleport(position: vec3): void

Teleports the player to a specific position.

Parameters:

  • position: vec3 - The position to teleport the player to

Example:

player:Teleport(vec3(100, 50, 200))

NetPlayer:WarpIntoVehicle(vehicle: NetVehicle, seat: VehicleSeat): void

Warps the player into a vehicle at a specific seat.

Parameters:

  • vehicle: NetVehicle - The vehicle to warp the player into
  • seat: VehicleSeat - The seat to place the player in

Example:

player:WarpIntoVehicle(someVehicle, VehicleSeat.Driver)

NetPlayer:SetSkin(name: string): void

Sets the skin of the player. See the Skins List for a list of available skins.

Parameters:

  • name: string - The name of the skin to set

Example:

player:SetSkin("Mira")