Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)