No categories assigned

ContentDesigner:Creating Conversations

ContentDesigner:SpawnScripts - Creating Conversations

Return to: ContentDesigner:SpawnScripts | Tutorials | Portal | Forum | Project Manager | Bug Tracker


The Creating Conversations guide will be broken up into many different sections. The hope is to keep it from being overwhelming when learning to add different parts of conversations to your NPC.


Getting A NPC To Talk

A NPC is not much fun when you first create one. All they do is sand there motionless, and speechless. In order to solve that, a conversation dialog needs to be created. This guide will be using the spawn script of Verex N'Za in Darklight Wood. If you would like you can log on to the emulator and go through the dialog to see how it looks, and if you are a developer you can go to the web db editor under the Verex N'Za spawn section to find the full script. For those who have a local server this is located in worldserver\SpawnScripts\Darklight where you installed you server at. For this guide we want to build the dialog from scratch so we can get a better grasp on building spawn scripts.

First thing to do is create VerexNZa.lua file. If you are using the EQ2LuaEditor then one can be created by going to file->New->Spawn Script. If you are using a text editor like notepad++ then be sure when you save your file you put .lua at the end for the file extention. If you need a template to start off with you can get it at Spawn Script Template at the bottom of that page.

Fill Out The script header

--[[
Script Name : SpawnScripts/DarklightWood/VerexNZa.lua
Script Purpose : Verex N'Za (340030)
Script Author : Cynnar
Script Date : 2015.07.01
Script Notes :
--]]

Above is an example of what your script header should look like. These are most helpful when a spawn script needs to be edited at a later time, and are required if submitting for use with the emulator.

Function Spawn

function spawn(NPC)
    SetPlayerProximityFunction(NPC, 10, "InRange")
end

If you notice when you get close to Verex he will motion you over to him and will say something to you as he does. In order to do this it all starts in the spawn function. When a NPC is first created the function spawn is called, and as can be seen in the code above SetPlayerProximityFunction using parameters (NPC, 10, "InRange") will be executed. The SetPlayerProximityFunction allows us to have the NPC say or do something when a player gets within a certain range. We want Verex to call us over when we get close so we have to input the correct parameters for SetPlayerProximityFunction. This is (NPC, 10, "InRange"). The first parameter is NPC and is used to refer to Verex, Next parameter is 10 and is how close to Verex we have to be before he will call us over. Last parameter is "InRange" and is a call to another function called InRange. We will need to create this function so when InRange is called there will be instructions on what needs to be done. But before that we have to add the respawn function.

Function respawn

function respawn(NPC)
    spawn(NPC)
end

The respawn function is needed so if/when a NPC is killed, and it is time for them to respawn, then it will call this function and execute the spawn(NPC) function. This is all that is needed in this function.

Function InRange

function InRange(NPC, Spawn)
    PlayFlavor(NPC, "", "You there, come here at once! We haven't a second to spare!", "beckon", 0, 0, Spawn)
end

Now on to creating the InRange function. The PlayFlavor function inside is what we want Verex to do when a player gets within 10 uints from him. The PlayFlavor function allows you play a voiceover, text, and an emote at the same time. A basic PlayFlavor lua function looks like this.

 PlayFlavor(NPC, "", "", "", 0, 0, Spawn)

A quick breakdown of the parameters. NPC points to Verex. The first "" can be filled in with a mp3_filename. The second "" can be filled in with the text that appears in the chat window. The third "" can be filled in with an emote. The first 0 is where you put the first mp3 key if the mp3 file needs a key to be played. The second 0 is where you put the second mp3 key if the mp3 file needs a key to be played. Spawn in this case points to the player.

From the InRange function above we see that PlayFlavor will have the NPC Verex send text to the chat window saying "You there, come here at once! We haven't a second to spare!", and will do the beckon emote to the player.

Function hailed

function hailed(NPC, Spawn)
    FaceTarget(NPC, Spawn)
    conversation = CreateConversation()

    PlayFlavor(NPC, "voiceover/english/voice_emotes/greetings/greetings_3_1048.mp3", "", "", 0, 0, Spawn)
    AddConversationOption(conversation, "How am I to do that?", "Chat_0_1")
    AddConversationOption(conversation, "Wait, where is this place?", "Chat_1_1")
    StartConversation(conversation, NPC, Spawn, "Excellent, you've finally arrived. So, you're one of Cristanos' chosen ones, hmm? The Queen must see some great potential in you, " .. GetName(Spawn) .. ". Let's not waste any more time and see what you're made of.")
end

This is where we are going to start out conversation. So when Verex is hailed it will begin the dialog. Going through the hailed function we want Verex to face the player after they hail. We use the FaceTarget function for this. First we need to create a conversation. To do this we need to use CreateConversation() and assign it to a local variable and call it conversation. This how we get the conversation = CreateConversation() part of the code. Now we can add options for the player to choose from by using the AddConversationOption, and finally send this conversation to the player to be displayed with StartConversation().

Notice that we are using PlayFlavor again but this time we have a mp3 file. There is no text or emote in this PlayFlavor function so these are just the open and close quotes "" for each one. Also this mp3 file does not need any mp3 keys so they are set to 0.

The AddConversationOption functions are the players chat options. The top most AddConversationOption function is the top most chat option. The script will execute down the line so the second AddConversationOption function will be the second chat option, and so on until reaching the StartConverstation function. There are a minimum of two parameters for a AddConversationOption. The first one is conversation, our variable we set earlier. The second is "How am I to do that?", and is the choice the player will see for responding to the NPC. The third is "Chat_0_1". This is needed if the NPC has a response to what the player chooses, and is a function that has to be created further down the script. If the NPC has no response then "Chat_0_1" can be removed and the line would look something like this AddConversationOption(conversation, "I don't think I am ready yet.").

The StartConverstation function will start the conversation. This is what the NPC will be saying, and everything below this function will not be included in the conversation. There are four parameters for this function. Again we need our variable, conversation, that was set earlier. Next is NPC and this points to Verex. After that Spawn is who will be receiving the conversation. After that is the text of what the NPC is going to say. Last is to finish the function by closing it with end.

Notice that this has a special addition to the NPC text " .. GetName(Spawn) .. ". What this does is get the name of the player and will display that players name in the conversation. When using GetName like this you have to break the text with a quote " before and after.

Adding Chat_0_1 function

function Chat_0_1(NPC, Spawn)
    FaceTarget(NPC, Spawn)
    conversation = CreateConversation()

    AddConversationOption(conversation, "What is it you would have me do?", "Chat_0_2")
    StartConversation(conversation, NPC, Spawn, "Hate's Envy has fallen under attack by an army of Sablevein elementals! We need your help in stopping them before they burn down the entire town!")
end

As you can see this function looks a lot like the hailed function. The main changes are that function hailed was changed to function Chat_0_1, is not using PlayFlavor, only has one AddConversationOption, now has Chat_0_2 instead of Chat_0_1, what the NPC is suppose to say, and the players chat option. As you can see to create the function for Chat_0_2 would be the same as creating the Chat_0_1 function. Just a quick note. Chat_0_1, Chat_0_2 doesn't have to be exactly those. For instance if you have multiple quest you could call them QuestChat_1_1_1 if you would like. Just as long as whatever you choose to call it in the AddConversationOption is what you use in the function. Otherwise the conversation is broken.


On to Creating Conversations
Back to SpawnScripts