NetNPC
NetNPC
shares the same base methods as NetObject
and adds only an identifier accessor.
Inherited methods from NetObject
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
NetNPC:GetId(): string
Returns the unique identifier of the NPC.
Returns: string - The unique identifier of the NPC
Example:
local id = npc:GetId()
print("NPC ID: " .. id)