Managing events
As the sandbox broadcasts events to every sandbox object that registers a callback function, we'll create an agent communication system that provides commonly used functionalities such as event type registration and event filtering.
Assigning agent teams
So far, our agents fend for themselves in a free-for-all style; now, we'll assign teams to utilize team-based communication as well as the beginnings of cooperative strategy. By changing the initialization of the agent, we can assign the agent to either team1
or team2
and assign a different character model accordingly:
IndirectSoldierAgent.lua
:
function Agent_Initialize(agent) Soldier_InitializeAgent(agent); agent:SetTeam("team" .. (agent:GetId() % 2 + 1)); soldierUserData = {}; if (agent:GetTeam() == "team1") then soldierUserData.soldier = Soldier_CreateSoldier(agent); else soldierUserData.soldier = Soldier_CreateLightSoldier(agent); end ... end
Even with a...