SendToTrackingClients||doc136359

September 20, 2022

Format

PackageHandlers:SendToTrackingClients(entity, packetName, packet)

Describe

The server sends protocols to all clients within the synchronization range of an entity. Each entity has a certain synchronization range. When the player and the entity exceed this range, the server will no longer synchronize the entity data to the player client. This process is to save performance and data. When the server no longer synchronizes the entity data to the player client, the player client will destroy the entity from the client until the player enters the synchronization range again. Sendtrackingclients will only send protocols to player clients that are within the synchronization range of parameter entities.

parameter

Variable name Type Describe
entity Entity Target entity. The protocol will only be sent to clients within the synchronization scope of this entity
packetName string Protocol name, corresponding to the receiving function
packet table<variant> The parameter carried by the protocol is an empty table by default

Parameter type in packet can only beBasic type

Code example

The server sends the "testpackage" protocol with two parameters

-- carry parameters
local packet = {
     a = 1,
     b = 2
}

-- send protocol
-- entity an NPC entity or a player entity
PackageHandlers:SendToTrackingClients(entity, "TestPackage", packet)

Client receives "testpackage" protocol

-- receive protocol
-- player : client player entity
-- packet : The parameters that the server carries when sending the protocol
PackageHandlers:Receive("TestPackage", function(player, packet)
     print("client receive package", player)
     print(packet.a, packet.b)
end)