Book Image

Learning Game AI Programming with Lua

By : David Young
Book Image

Learning Game AI Programming with Lua

By: David Young

Overview of this book

Table of Contents (16 chapters)
Learning Game AI Programming with Lua
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with AI Sandbox
Index

Auditory events


Auditory events are created from the sandbox itself and are sent to all agents. It's up to the agent to determine what to do with the information, such as disregarding the event based on the distance.

The BulletShot event

To send an event when bullets are shot, we can update the ShootBullet function to send out an event based on the bullet's shot position:

AgentCommunications.lua:

AgentCommunications.EventType.BulletShot = "BulletShot";

Soldier.lua:

local function SendShootEvent(sandbox, shootPosition)
    local event = { position = shootPosition };
    
    AgentCommunications_SendMessage(
        sandbox,
        AgentCommunications.EventType.BulletShot,
        event);
end

local function ShootBullet(sandbox, position, rotation)

    ...    

    SendShootEvent(sandbox, position);
end

The BulletImpact event

An event similar to the BulletShot event can be sent out when a bullet impacts a location:

AgentCommunications.lua:

AgentCommunications.EventType.BulletImpact = "BulletImpact...