Game Development Reference
In-Depth Information
Tapping into agent events
Without modifying the existing event system, we can create simple event handlers to store,
process, and prune any number of events the agents are already sending. As events are pro-
cessed differently for the influence map, we store local copies of each event and manage
the lifetime of events separately from how agents process them:
SoldierTactics.lua :
local function HandleBulletImpactEvent(sandbox, eventType,
event)
table.insert(
bulletImpacts, { position = event.position, ttl =
1500 });
end
local function HandleBulletShotEvent(sandbox, eventType,
event)
table.insert(
bulletShots, { position = event.position, ttl = 1500
});
end
local function HandleDeadFriendlySightedEvent(
sandbox, eventType, event)
deadFriendlies[event.agent:GetId()] = event;
end
local function HandleEnemySightedEvents(sandbox, eventType,
event)
seenEnemies[event.agent:GetId()] = event;
end
local function HandleEvent(sandbox, sandbox, eventType,
event)
if (eventHandlers[eventType]) then
eventHandlers[eventType](sandbox, eventType, event);
Search WWH ::




Custom Search