import { Component, CodeBlockEvents, Player, PropTypes } from 'horizon/core';
import { Npc } from 'horizon/npc';
class ConvoTest extends Component<typeof ConvoTest>{
static propsDefinition = {
trigger: { type: PropTypes.Entity, }
};
preStart() {
if (!this.props.trigger) return;
this.connectCodeBlockEvent(this.props.trigger, CodeBlockEvents.OnPlayerEnterTrigger, (player: Player) => this.OnPlayerEnterTrigger(player));
this.connectCodeBlockEvent(this.props.trigger, CodeBlockEvents.OnPlayerExitTrigger, (player: Player) => this.OnPlayerExitTrigger(player));
}
start() { }
OnPlayerEnterTrigger(player: Player) {
console.log("OnPlayerEnterTrigger")
const npc = this.entity.as(Npc);
console.log("isConversationEnabled: " + npc.isConversationEnabled())
npc.conversation.stopSpeaking()
if (npc) npc.conversation.registerParticipant(player);
}
OnPlayerExitTrigger(player: Player) {
const npc = this.entity.as(Npc);
if (npc) npc.conversation.unregisterParticipant(player);
}
}
Component.register(ConvoTest);
Without looking at your code I cannot tell where your going wrong but there are a few things to consider. You need to cast the NPC entity as an NPC and then register players to the conversation. I was unable to get it to work but having them listen to a player. Try this, I am adding a player to the convo when they enter a trigger. This script is attached to the NPC.