[0.8.8][NK] Network Events

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Seed
edited December 2015 in Modding Tutorials

Network Events

The Network Event system works with objects/mods, each time an event is raised it is sent to players that the object/mod is relevant to/all players that can see the object (except when 3rd parameter contains a list of players to send the event to), each event has to be registered on both sending and receiving Class.

Each event defines it's argument-type pairs and only those will be sent.

While the naming of events doesn't affects their functionality, we have a common way of naming events:
Client Events - ClientEvent_* or Client_*
Server Events - ServerEvent_* or Server_*
Shared Events - SharedEvent_* or Shared_*
This makes it easy to identify events when looking through code.

Maximum length of event name is 32 character!

Example event (Client event):
text = "string", -- define argument text of type string
position = "vec3", -- define argument position of type vec3
boolean = "bool", -- define argument boolean of type bool
number = "float" -- define argument number of type float


Client event call (on GameObjectClass):
self:RaiseClientEvent("ClientEvent_MyNewEvent", { text = "string", position = vec3.new(1, 2, 3), boolean = true, number = 2.5 })
Server event call (on GameObjectClass):
self:RaiseServerEvent("ServerEvent_MyNewEvent", { text = "string", position = vec3.new(1, 2, 3), boolean = true, number = 2.5 })
Event (ClientEvent) function example:
function MyObject:ClientEvent_MyNewEvent(args)
-- args.text
-- args.position
-- args.boolean
-- args.number
My Blog
  yt.png  t.png  
Sign In or Register to comment.