Page 1 of 1

Conversation with Enemy - ARPG Kit

Posted: Sun Feb 05, 2017 5:03 am
by warlockoo1
Hello,
So basically I am making Interactive RPG, so user a choice in every decisions. So I am making conversation with enemy boss. In fight if enemy health is less than 20, then it triggers a conversation where boss surrenders and player have to choose to kill or not kill him.
I added 2 scripts - "Conversation Trigger" and "Usable" to enemy boss and another script to enable conversation trigger component as I set Trigger to "On Enable".
So conversation starts but player still can attack it due to that enemy dies. So player fails to enter in conversation. I don't know if this is correct approach, please give some suggestions.

Heres the code which enables Conversation Trigger:

Code: Select all

private int getHealth; 

	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
		getHealth = gameObject.GetComponent<StatusC>().maxHealth - gameObject.GetComponent<StatusC>().health;

		if (getHealth >= 80) {
			gameObject.GetComponent<ConversationTrigger> ().enabled = true;
			var anim = GetComponent<Animator>();
			if (anim == null) return;
			anim.SetBool("run", false);
			gameObject.GetComponent<AIsetC> ().enabled = false;

		}
	}

Re: Conversation with Enemy - ARPG Kit

Posted: Sun Feb 05, 2017 10:00 am
by Tony Li
Hi,

Here's a boss example:

ARPG_BossExample_2017-02-05.unitypackage

I set it up similarly, but I used the script below (which is included in the example package).

I also added a Conversation Trigger set to OnUse on the boss:

Image

It runs a conversation that sets a Dialogue System variable based on the player's response:

Image

If the player chooses to let the boss live, the OnConversationEnd method turns off the boss's attack AI. The OnConversationStart and OnConversationEnd methods also pause the game during the conversation.

BossSurrenderMonitor.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class BossSurrenderMonitor : MonoBehaviour
{

    public float surrenderAtHealthPercent = 20;
    public string killDecisionVariable = "Kill Boss";

    private StatusC status;

    void Awake()
    {
        status = GetComponent<StatusC>();
    }

    void Update()
    {
        var healthPercent = 100 * ((float) status.health / (float) status.maxHealth);
        if (healthPercent < surrenderAtHealthPercent)
        {
            Debug.Log("Boss is under " + surrenderAtHealthPercent + "% health. Starting conversation.");
            enabled = false; // Stop monitoring health.
            var player = FindObjectOfType<PlayerInputControllerC>().transform;
            GetComponent<ConversationTrigger>().OnUse(player);
        }
    }

    void OnConversationStart(Transform actor)
    {
        Time.timeScale = 0;
    }

    void OnConversationEnd(Transform actor)
    {
        Time.timeScale = 1;
        if (DialogueLua.GetVariable(killDecisionVariable).AsBool == false)
        {
            GetComponent<AIsetC>().enabled = false;
        }
    }
}

Re: Conversation with Enemy - ARPG Kit

Posted: Sun Feb 05, 2017 10:52 am
by warlockoo1
Thank you, it worked, I just modified it to set boss to idle state. So it looks good :D

Code: Select all

	void Update(){
        	var healthPercent = 100 * ((float) status.health / (float) status.maxHealth);
        	if (healthPercent < surrenderAtHealthPercent){
            		Debug.Log("Boss is under " + surrenderAtHealthPercent + "% health. Starting conversation.");
            		enabled = false; // Stop monitoring health.
            		var player = FindObjectOfType<PlayerInputControllerC>().transform;
			var eAnim = gameObject.GetComponent<Animator> ();
			eAnim.SetBool ("run", false);
			eAnim.SetBool ("hurt", false);
			gameObject.GetComponent<AIsetC>().enabled = false;
            		gameObject.GetComponent<ConversationTrigger>().OnUse(player);
       	 	}
    	}