LuaEvents.InvokeLocalNetwork(LuaBehaviour script, string key, EventTarget target, MLPlayer[] players, [optionalArguments] args)
Invoke a local (script+gameObject specific) event over the network.
Parameters:
Name | Type | Description |
---|---|---|
script | LuaBehaviour | The local script object. |
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 LuaBehaviour
local script;
---@type string
local key;
---@type EventTarget
local target;
---@type MLPlayer
local players;
---@type [optionalArguments]
local args;
LuaEvents:InvokeLocalNetwork(script, key, target, players, args)
Example
do
-- get reference to the script
local EventRouter = LUA.script;
local eventName = "MyLocalEventName";
-- The event function
local function MyEvent(value)
Debug.Log(value);
end
function EventRouter.Start()
-- register event
LuaEvents.AddLocal(EventRouter, eventName, MyEvent);
end
-- invoke event for master only
function EventRouter.SendToMaster(value)
LuaEvents.InvokeLocalNetwork(EventRouter, eventName, EventTarget.Master, nil, value)
end
-- invoke event for the owner of this game object
function EventRouter.SendToOwner(value)
LuaEvents.InvokeLocalNetwork(EventRouter, eventName, EventTarget.Player, {EventRouter.gameObject.Owner}, value);
end
-- invoke event for the owner and master
function EventRouter.SendToOwnerAndMaster(value)
LuaEvents.InvokeLocalNetwork(EventRouter, eventName, EventTarget.Player, {EventRouter.gameObject.Owner, Room.GetMasterPlayer()}, value);
end
-- invoke event for owner and local client
function EventRouter.SendToOwnerAndLocal(value)
LuaEvents.InvokeLocalNetwork(EventRouter, eventName, EventTarget.Player, {EventRouter.gameObject.Owner, Room.GetLocalPlayer()}, value);
end
-- invoke event for all
function EventRouter.SendToAll(value)
LuaEvents.InvokeLocalNetwork(EventRouter, eventName, EventTarget.All, nil, value);
end
end