Emerald AI 3.x Support

Table of Contents

This page describes how to set up the Dialogue System with Emerald AI 3.x by Black Horizon Studios. (Emerald AI 3.x is required.)

Emerald AI copyright © Black Horizon Studios.

Emerald AI Setup

This package works with Emerald AI 3.1. If you are using Emerald AI 3.0 or older, add the scripting define symbol EMERALD_AI_3_0_OR_OLDER in menu item Edit > Project Settings > Player > Other Settings.

  1. Import the packages in these folders:
    • Plugins ► Pixel Crushers ► Common ► Third Party Support ► Emerald AI Support and
    • Plugins ► Pixel Crushers ► Dialogue System ► Third Party Support ► Emerald AI Support
  2. This will unpack files into these folders:
    • Pixel Crushers ► Common ► Third Party Support ► Emerald AI Support and
    • Pixel Crushers ► Dialogue System ► Third Party Support ► Emerald AI Support.
  3. To your own scene, add the Dialogue Manager prefab from the Prefabs folder.
  4. Add an Emerald AI Lua component to the Dialogue Manager.
  5. To remember AIs' states and positions, add Emerald AI Saver components to them.
  6. Use the Lua functions documented below.

Emerald AI Lua Functions

You can use the Lua functions below in your dialogue entry Scripts and Conditions (or anywhere you use Lua). Note the exact number and type of parameters required for each function.

In the '...' Lua wizard dropdowns, these functions are available in Custom > Emerald.

Lua Function Description
GetEmeraldAIHealth("subject/faction") Returns the current health of an AI. First tries to match a GameObject, then a faction name.
DamageEmeraldAI("faction", amount, "targetType") Damages all AI of the specified faction. Damage comes from the type specified by targetType (Player, AI, or NonAITarget).
EmeraldAIEmote("faction", soundID, animationID) Plays a sound effect ID and/or animation ID. Pass -1 as the ID if you don't want to play either one.
EmeraldAIFollow("faction", "target", "followAs") Makes all AI of the specified faction follow a target (name of a GameObject) as either Companion or Pet.
EmeraldAIStay("faction") Makes all AI of the specified faction stop following.
SetEmeraldPlayerRelation("faction", "relation") Sets the AI's relation to the player to "Enemy", "Neutral", or "Friendly".
SetEmeraldFactionRelation("faction", "targetFaction", "relation") Sets the AI's relation to targetFaction to "Enemy", "Neutral", or "Friendly".
SetEmeraldBehavior("faction", "behavior") Sets the behavior (Aggressive, Cautious, Companion, Passive, or Pet) of all AI of the specified faction.
SetEmeraldConfidence("faction", "confidence") Sets the confidence (Coward, Brave, or Foolhardy) of all AI of the specified faction.
SetEmeraldDestination("faction", "destination") Sets the destination (name of a GameObject) of all AI of the specified faction.
SetEmeraldItem("faction", itemID, enable) Sets an item enabled or disabled. To disable all items, pass -1 for itemID and false for enable.
SetEmeraldWander("faction", "wander") Sets the wander type (Destination, Dynamic, Stationary, Waypoints) of all AI of the specified faction.
SetEmeraldWeapon("faction", "type", enable) Enables or disables the weapon of all AI of the specified faction. For "type", you must specify "Melee" or "Ranged".

Examples:

DamageEmeraldAI("Undead", 50, "Player")
SetEmeraldBehavior("Undead", "Aggressive")
SetEmeraldWeapon("Undead", "Melee", true)
SetEmeraldDestination("Spider", "Web")
SetEmeraldFactionRelation("NPC", "Undead", "Enemy")
EmeraldAIFollow("Dog", "Master", "Pet")
EmeraldAIStay("Dog")

Note:

For Emerald AI 2.4+, EmeraldAIAttacksPlayer() has been replaced by SetEmeraldPlayerRelation().

Controlling Individual AI

If you want to control an individual AI instead of an entire faction, specify "go=Name" for the faction, where Name is the AI's GameObject name. For example, to tell the Emerald AI character Porthos to follow the Player as a Companion:

EmeraldAIFollow("go=Porthos", "Player", "Companion")

<< Third Party Integration