Emerald AI Integration

Goodrich

New member
I don't think EAI has the ability of handling more than one player without custom code. I believe it's possible to modify it, but it would take some time.
um also do you think if i assign a player2 tag on one of the opsive character and some how call that with EAI do you think it will damage that player with a player2 tag? i tried this method with playermaker and opsive and uscript opisve and the resualt was perfect, also to note i was not using EAI with playermaker nor uscript.
 

magique

Active member
um also do you think if i assign a player2 tag on one of the opsive character and some how call that with EAI do you think it will damage that player with a player2 tag? i tried this method with playermaker and opsive and uscript opisve and the resualt was perfect, also to note i was not using EAI with playermaker nor uscript.
Now that I think about it, I don't see why this shouldn't work right now. The SendPlayerDamage function sends the damage to the specific transform that the AI is targeting. If you allow the AI to target both player1 and player2 tags then it should be able to distinguish which player it is attacking and send the damage to the correct player.
 

Goodrich

New member
yes that i was thinking to but as you can see, im not a coder, im more of visual scripter. what script should i edit in EAI to call player2 tag, the way i did it in uscript i had one script with 2 set of nodes for my ai if player1 or player2 was in the zombiedamagezone which was a trigger event node that i use.
 

magique

Active member
yes that i was thinking to but as you can see, im not a coder, im more of visual scripter. what script should i edit in EAI to call player2 tag, the way i did it in uscript i had one script with 2 set of nodes for my ai if player1 or player2 was in the zombiedamagezone which was a trigger event node that i use.
You have to edit the AI in the inspector. There should be a Detection section where you can set tags and layers that the AI will detect for attack purposes. Just make sure both tags are included.
 

Goodrich

New member
Now that I think about it, I don't see why this shouldn't work right now. The SendPlayerDamage function sends the damage to the specific transform that the AI is targeting. If you allow the AI to target both player1 and player2 tags then it should be able to distinguish which player it is attacking and send the damage to the correct player.
do you think i should copy "The SendPlayerDamage function" and change it to check player2tag
You have to edit the AI in the inspector. There should be a Detection section where you can set tags and layers that the AI will detect for attack purposes. Just make sure both tags are included.
oh that easy, theres no code to change, now i think of it i should've test that
 

Goodrich

New member
Hello, i get three error when copying the code into my blank OpsiveBridge script:

Error1: Assets\TLOUS\OpsiveBridge.cs(23,34): error CS1002: ; expected
Error2: Assets\TLOUS\OpsiveBridge.cs(23,34): error CS1513: } expected

Here is the code for (Opsive 2.2):
C#:
using UnityEngine;
using EmeraldAI;
using Opsive.Shared.Events;
namespace Magique
{
    public class OpsiveBridge : MonoBehaviour
    {
        private EmeraldAISystem _emeraldAI;
        private void Awake()
        {
            _emeraldAI = GetComponent<EmeraldAISystem>();
            EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
        private void OnObjectImpact(float amount, Vector3 position, Vector3 forceDirection,
       GameObject attacker, object attackerObject, Collider hitCollider)
        {
            if (_emeraldAI != null)
            {
                _emeraldAI.Damage((int)amount, EmeraldAISystem.TargetType.Player,
               attacker.transform);
                //Debug.Log(name + " impacted by " + attacker + " on collider " +
                hitCollider + ".");
            }
        }
        public void OnDestroy()
        {
            EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
    }
}

And a error for (Before Opsive 2.2):
Error3:Assets\TLOUS\OpsiveBridge.cs(12,13): error CS0103: The name 'EventHandler' does not exist in the current context


Here is the Code for (Before Opsive 2.2)

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Events;
using EmeraldAI;
namespace Magique
{
    public class OpsiveBridge : MonoBehaviour
    {
        private EmeraldAISystem _emeraldAI;
        private void Awake()
        {
            _emeraldAI = GetComponent<EmeraldAISystem>();
            EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
        private void OnObjectImpact(float amount, Vector3 point, Vector3 normal, GameObject
       originator, Collider collider)
        {
            if (_emeraldAI != null)
            {
                _emeraldAI.Damage((int)amount, EmeraldAISystem.TargetType.Player,
               originator.transform);
                //Debug.Log(this.name + " took " + amount + " damaged at location " + point + "
                //with normal " + normal + " from object " + originator);
            }
        }
    }
}

I just created a C# script and copy and paste the code in, then these error appear. 1 error for (Before Opsive 2.2) and 2 errors for (Opsive 2.2)
 

magique

Active member
Hello, i get three error when copying the code into my blank OpsiveBridge script:

Error1: Assets\TLOUS\OpsiveBridge.cs(23,34): error CS1002: ; expected
Error2: Assets\TLOUS\OpsiveBridge.cs(23,34): error CS1513: } expected

Here is the code for (Opsive 2.2):
C#:
using UnityEngine;
using EmeraldAI;
using Opsive.Shared.Events;
namespace Magique
{
    public class OpsiveBridge : MonoBehaviour
    {
        private EmeraldAISystem _emeraldAI;
        private void Awake()
        {
            _emeraldAI = GetComponent<EmeraldAISystem>();
            EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
        private void OnObjectImpact(float amount, Vector3 position, Vector3 forceDirection,
       GameObject attacker, object attackerObject, Collider hitCollider)
        {
            if (_emeraldAI != null)
            {
                _emeraldAI.Damage((int)amount, EmeraldAISystem.TargetType.Player,
               attacker.transform);
                //Debug.Log(name + " impacted by " + attacker + " on collider " +
                hitCollider + ".");
            }
        }
        public void OnDestroy()
        {
            EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
    }
}

And a error for (Before Opsive 2.2):
Error3:Assets\TLOUS\OpsiveBridge.cs(12,13): error CS0103: The name 'EventHandler' does not exist in the current context


Here is the Code for (Before Opsive 2.2)

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Events;
using EmeraldAI;
namespace Magique
{
    public class OpsiveBridge : MonoBehaviour
    {
        private EmeraldAISystem _emeraldAI;
        private void Awake()
        {
            _emeraldAI = GetComponent<EmeraldAISystem>();
            EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject,
           Collider>(gameObject, "OnObjectImpact", OnObjectImpact);
        }
        private void OnObjectImpact(float amount, Vector3 point, Vector3 normal, GameObject
       originator, Collider collider)
        {
            if (_emeraldAI != null)
            {
                _emeraldAI.Damage((int)amount, EmeraldAISystem.TargetType.Player,
               originator.transform);
                //Debug.Log(this.name + " took " + amount + " damaged at location " + point + "
                //with normal " + normal + " from object " + originator);
            }
        }
    }
}

I just created a C# script and copy and paste the code in, then these error appear. 1 error for (Before Opsive 2.2) and 2 errors for (Opsive 2.2)
It's just because the code doesn't paste correctly and the commented out debug line gets broken up into multiple lines. Use the attached script, which should work.
 

Attachments

  • OpsiveBridge.cs
    1.1 KB · Views: 18

Goodrich

New member
It's just because the code doesn't paste correctly and the commented out debug line gets broken up into multiple lines. Use the attached script, which should work.
thank you, no error reported in this script, but now how would i get your code from the rest of the integration instruction (Opsive_V2.2_EmeraldAI_Intgration.pdf) into the C# script without copying and pasting it (which im afraid to do now). the scripts im talking about are these:

EmeraldAIEventsManager script

EmeraldAIDetection script

EmeraldAIPlayerDamage script

also after creating my ai with EAI, the EmeraldAIPlayerDamage script component does not appear in the inspector tab,(Attach as a component) do i just attach EmeraldAIPlayerDamage script my self or EAI suppose do that by it self. im still new to EAI.
 

magique

Active member
thank you, no error reported in this script, but now how would i get your code from the rest of the integration instruction (Opsive_V2.2_EmeraldAI_Intgration.pdf) into the C# script without copying and pasting it (which im afraid to do now). the scripts im talking about are these:

EmeraldAIEventsManager script

EmeraldAIDetection script

EmeraldAIPlayerDamage script

also after creating my ai with EAI, the EmeraldAIPlayerDamage script component does not appear in the inspector tab,(Attach as a component) do i just attach EmeraldAIPlayerDamage script my self or EAI suppose do that by it self. im still new to EAI.
Pasting the other script code shouldn't be a problem. As far as the damage script, you don't need to do anything yourself. It is all done for you.
 

Goodrich

New member
Thank you for helping me so far, i'm on my last script to fully integrating Opsive and EAI but i ran into problem on EmeraldAIPlayerDamage script part of the last setup, Im getting 4 error after filling out the script.


Error1: Assets\Emerald AI\Scripts\Components\EmeraldAIProjectile.cs(546,70): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error2: Assets\Emerald AI\Scripts\Components\EmeraldAIProjectile.cs(551,70): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error3: Assets\Emerald AI\Scripts\System\EmeraldAISystem.cs(2136,85): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error4: Assets\Emerald AI\Scripts\System\EmeraldAISystem.cs(2142,85): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Here is the code for EmeraldAIPlayerDamage script:

C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EmeraldAI.Example;


namespace EmeraldAI
{
    //This script will automatically be added to player targets. You can customize the DamagePlayerStandard function
    //or create your own. Ensure that it will called within the SendPlayerDamage function. This allows users to customize
    //how player damage is received and applied without having to modify any main system scripts. The EmeraldComponent can
    //be used for added functionality such as only allowing blocking if the received AI is using the Melee Weapon Type.
    public class EmeraldAIPlayerDamage : MonoBehaviour
    {
        public List<string> ActiveEffects = new List<string>();


        public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent)
        {
            DamageOpsivePlayer(DamageAmount, Target);
        }


        void DamagePlayerStandard(int DamageAmount)
        {
            if (GetComponent<EmeraldAIPlayerHealth>() != null)
            {
                EmeraldAIPlayerHealth PlayerHealth = GetComponent<EmeraldAIPlayerHealth>();
                PlayerHealth.DamagePlayer(DamageAmount);
            }
        }


        void DamageOpsivePlayer(int DamageAmount, Transform target)
        {
            var tpcHealth =
           GetComponentInParent<Opsive.UltimateCharacterController.Traits.Health>();
            if (tpcHealth)
            {
                tpcHealth.Damage(DamageAmount);
                if (tpcHealth.HealthValue <= 0)
                {
                    EmeraldAISystem emeraldAI = target.GetComponent<EmeraldAISystem>();
                    EmeraldAIEventsManager emeraldAIEvents =
                   target.GetComponent<EmeraldAIEventsManager>();
                    if (emeraldAIEvents != null && emeraldAI != null &&
                    emeraldAI.CurrentTarget == this.gameObject.transform)
                    {
                        emeraldAI.ClearTarget();
                    }
                }
            }
        }


    }
}
 

magique

Active member
Thank you for helping me so far, i'm on my last script to fully integrating Opsive and EAI but i ran into problem on EmeraldAIPlayerDamage script part of the last setup, Im getting 4 error after filling out the script.


Error1: Assets\Emerald AI\Scripts\Components\EmeraldAIProjectile.cs(546,70): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error2: Assets\Emerald AI\Scripts\Components\EmeraldAIProjectile.cs(551,70): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error3: Assets\Emerald AI\Scripts\System\EmeraldAISystem.cs(2136,85): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Error4: Assets\Emerald AI\Scripts\System\EmeraldAISystem.cs(2142,85): error CS1501: No overload for method 'SendPlayerDamage' takes 4 arguments

Here is the code for EmeraldAIPlayerDamage script:

C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EmeraldAI.Example;


namespace EmeraldAI
{
    //This script will automatically be added to player targets. You can customize the DamagePlayerStandard function
    //or create your own. Ensure that it will called within the SendPlayerDamage function. This allows users to customize
    //how player damage is received and applied without having to modify any main system scripts. The EmeraldComponent can
    //be used for added functionality such as only allowing blocking if the received AI is using the Melee Weapon Type.
    public class EmeraldAIPlayerDamage : MonoBehaviour
    {
        public List<string> ActiveEffects = new List<string>();


        public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent)
        {
            DamageOpsivePlayer(DamageAmount, Target);
        }


        void DamagePlayerStandard(int DamageAmount)
        {
            if (GetComponent<EmeraldAIPlayerHealth>() != null)
            {
                EmeraldAIPlayerHealth PlayerHealth = GetComponent<EmeraldAIPlayerHealth>();
                PlayerHealth.DamagePlayer(DamageAmount);
            }
        }


        void DamageOpsivePlayer(int DamageAmount, Transform target)
        {
            var tpcHealth =
           GetComponentInParent<Opsive.UltimateCharacterController.Traits.Health>();
            if (tpcHealth)
            {
                tpcHealth.Damage(DamageAmount);
                if (tpcHealth.HealthValue <= 0)
                {
                    EmeraldAISystem emeraldAI = target.GetComponent<EmeraldAISystem>();
                    EmeraldAIEventsManager emeraldAIEvents =
                   target.GetComponent<EmeraldAIEventsManager>();
                    if (emeraldAIEvents != null && emeraldAI != null &&
                    emeraldAI.CurrentTarget == this.gameObject.transform)
                    {
                        emeraldAI.ClearTarget();
                    }
                }
            }
        }


    }
}
In new EmeraldAI versions, the SendPlayerDamage function looks like this:

public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent, bool CriticalHit = false)

It looks like your EmeraldAIPlayerDamage script is out of date because your other EAI scripts are trying to call a 4 argument function and your code above shows only 3 arguments like older versions of EAI.
 

Goodrich

New member
is it "bool CriticalHit = false)", before i paste the code from the instruction the "SendPlayerDamage function" look exactly like this:
public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent, bool CriticalHit = false)
 

magique

Active member
is it "bool CriticalHit = false)", before i paste the code from the instruction the "SendPlayerDamage function" look exactly like this:
public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent, bool CriticalHit = false)
I think that additional parameter was added after I wrote the instructions. I will update them when I have time.
 

Goodrich

New member
last night i fix the script and no error where reported, but i get this error when my ai is attack me:

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <fb001e01371b4adca20013e0ac763896>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <fb001e01371b4adca20013e0ac763896>:0)
EmeraldAI.EmeraldAISystem.GetDamageAmount () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:2545)
EmeraldAI.EmeraldAISystem.SendEmeraldDamage () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:2106)

i get this error when my ai is attacking me
 

Goodrich

New member
last night i fix the script and no error where reported, but i get this error when my ai is attack me:

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <fb001e01371b4adca20013e0ac763896>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <fb001e01371b4adca20013e0ac763896>:0)
EmeraldAI.EmeraldAISystem.GetDamageAmount () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:2545)
EmeraldAI.EmeraldAISystem.SendEmeraldDamage () (at Assets/Emerald AI/Scripts/System/EmeraldAISystem.cs:2106)

i get this error when my ai is attacking me
never mind, i forgot to add a melee attack for the ai
 

Goodrich

New member
i got the ai to correctly damage player 1 and player 2. player 2 tag is still call player, while player 2 layers is set to character2, and the ui correctly updates for each player when my infected ai attack one of the player, thank you for helping me get this far, now my 2 player Last of Us game will be complete with EAI.
 

Goodrich

New member
one more question, even though both of my players can kill the ai, how can i set up damage amount for the ai, because my ai gets killed after getting shot 2 times, is there a way to increase the ai health or decrease the amount of damage receive for the ai, or do i decrease the pistol damage with opsive
 

magique

Active member
one more question, even though both of my players can kill the ai, how can i set up damage amount for the ai, because my ai gets killed after getting shot 2 times, is there a way to increase the ai health or decrease the amount of damage receive for the ai, or do i decrease the pistol damage with opsive
Go to Emerald AI System in the inspector and click AI's Settings and Stats. You should see the Health amount there.
 
Top