LuaEvents.InvokeNetwork(string key, EventTarget target, MLPlayer[] players, [optionalArguments] args)
Invoke an event over the network.
Parameters:
Name | Type | Description |
---|---|---|
key | string | The name of the event. |
target | EventTarget | The event invocation target. |
players | MLPlayer[] | Set of players. Can be nil |
args | [optionalArguments] | Optional arguments to be passed to the invocation function. All must be able to serialized. |
Usage
---@type string
local key;
---@type EventTarget
local target;
---@type MLPlayer
local players;
---@type [optionalArguments]
local args;
LuaEvents:InvokeNetwork(key, target, players, args)
Example
do
-- get reference to the script
local EventRouter = LUA.script;
local eventName = "MyEventName";
-- The event function
local function MyEvent(value)
Debug.Log(value);
end
function EventRouter.Start()
-- register event
LuaEvents.Add(eventName, MyEvent);
end
-- invoke event for master only
function EventRouter.SendToMaster(value)
LuaEvents.InvokeNetwork(eventName, EventTarget.Master, nil, value)
end
-- invoke event for the owner of this game object
function EventRouter.SendToOwner(value)
LuaEvents.InvokeNetwork(eventName, EventTarget.Player, {EventRouter.gameObject.Owner}, value);
end
-- invoke event for the owner and master
function EventRouter.SendToOwnerAndMaster(value)
LuaEvents.InvokeNetwork(eventName, EventTarget.Player, {EventRouter.gameObject.Owner, Room.GetMasterPlayer()}, value);
end
-- invoke event for owner and local client
function EventRouter.SendToOwnerAndLocal(value)
LuaEvents.InvokeNetwork(eventName, EventTarget.Player, {EventRouter.gameObject.Owner, Room.GetLocalPlayer()}, value);
end
-- invoke event for all
function EventRouter.SendToAll(value)
LuaEvents.InvokeNetwork(eventName, EventTarget.All, nil, value);
end
end