NetObjectBase
Base class for all networked entities.
Class Instance Methods
Class Methods
NetObjectBase:GetPosition(): vec3
Returns the position of the object.
NetObjectBase:GetRotation(): vec3
Returns the rotation of the object.
NetObjectBase:GetHealth(): number
Returns the current health of the object.
NetObjectBase:GetMaxHealth(): number
Returns the maximum health of the object.
NetObjectBase:GetVelocity(): vec3
Returns the velocity of the object.
NetObjectBase:GetNetId(): number
Returns the network ID of the object.
NetObjectBase:SetData(key: string, value: any): boolean
Sets generic data on the object. 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).
NetObjectBase:GetData(key: string): any
Gets generic data from the object.
NetObjectBase:AsPlayer(): NetPlayer | nil
Returns NetPlayer instance if the object is a player, nil otherwise.
NetObjectBase:AsVehicle(): NetVehicle | nil
Returns NetVehicle instance if the object is a vehicle, nil otherwise.
NetObjectBase:GetType(): NetObjectType
Returns the network object type. Use NetObjectType enum to compare types.
Type Checking and Casting Methods
NetObjectBase:AsPlayer(): NetPlayer | nil
Returns a NetPlayer instance if the object is a player, otherwise returns nil. This is a safe way to cast a NetObjectBase 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 NetObjectBase instance
local player = netObject:AsPlayer()
if player then
print("This is a player: " .. player:GetNick())
else
print("This is not a player")
end
NetObjectBase:AsVehicle(): NetVehicle | nil
Returns a NetVehicle instance if the object is a vehicle, otherwise returns nil. This is a safe way to cast a NetObjectBase 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 NetObjectBase 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
NetObjectBase: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 NetObjectBase 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
Related Enums
NetObjectType
- Enum for different network object types