Exposing Lua entities to the network
Now that we know how to handle network communication in C++, let's have a look at how we can expose Lua entities to the network.
Net.Expose
In order to define RMIs and server properties, we'll need to call Net.Expose
from within the global scope of your .lua
script:
Net.Expose({ Class = MyEntity, ClientMethods = { ClRevive = { RELIABLE_ORDERED, POST_ATTACH, ENTITYID, }, }, ServerMethods = { SvRequestRevive = { RELIABLE_UNORDERED, POST_ATTACH, ENTITYID, }, }, ServerProperties = { }, });
The previous function will define the ClRevive
and SvRequestRevive
RMIs, which can be called by using three subtables that are automatically created for your entity:
allClients
otherClients
server
Function implementation
The remote functions are defined within either the Client
or Server
subtables of your entity script, so that the networking system can quickly find them while avoiding name conflicts.
For example, see the following...