Game Development Reference
In-Depth Information
We can create an external function that will allow agents to register callbacks per event
type. The callback we'll pass to this function will receive the userData table, event
type, and event whenever a corresponding event is received:
AgentCommunications.lua :
function AgentCommunications_AddEventCallback(
userData, eventType, callback)
local agentId = userData.agent:GetId();
if (agentCallbacks[agentId] == nil) then
agentCallbacks[agentId] = {};
agentUserData[agentId] = userData;
Sandbox.AddEventCallback(
userData.agent:GetSandbox(),
userData.agent,
AgentCommunications_HandleEvent);
end
agentCallbacks[agentId][eventType] = callback;
end
Two helper functions will be used to wrap the sandbox's AddEvent functionality. One
variation will send the event without any modification and the other function will flag the
message as a teamOnly message:
AgentCommunications.lua :
function AgentCommunications_SendMessage(
sandbox, messageType, message)
Sandbox.AddEvent(sandbox, messageType, message);
end
function AgentCommunications_SendTeamMessage(
sandbox, agent, messageType, message)
Search WWH ::




Custom Search