The title speaks for itself. The aim is to have the NPC greet the player with a message, instead of simply presenting the list of topics. This will help give dialogues some fluff.
Prerequisite
Add a greeting
property to your NPC. The greeting can be either a string or a function.
createItem("Mark", NPC(false), {
loc: "lounge",
properName: true,
//greeting: "Hello"
greeting: () => {msg("Hello"); msg("What can I do for you?")}
});
Updated npc.talkto
res.talkto = function() {
if (!game.player.canTalk(this)) {
return false;
}
if (settings.noTalkTo !== false) {
metamsg(settings.noTalkTo);
return false;
}
const topics = this.getTopics(this);
if (topics.length === 0) return failedmsg(lang.no_topics, {char:game.player, item:this});
// If the greeting property is present, we print or run the greeting before the topics
if (this.greeting) { printOrRun(game.player, this, "greeting") }
topics.push(lang.never_mind);
if (settings.dropdownForConv) {
showDropDown(lang.speak_to_menu_title(this), topics, function(result) {
if (result !== lang.never_mind) {
result.runscript();
}
});
}
else {
showMenu(lang.speak_to_menu_title(this), topics, function(result) {
if (result !== lang.never_mind) {
result.runscript();
}
});
}
return world.SUCCESS_NO_TURNSCRIPTS;
};