Difference between revisions of "Dialog System"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
(Introduction)
(Attaching dialogs to npcs)
 
(8 intermediate revisions by the same user not shown)
Line 49: Line 49:
 
</syntaxhighlight >
 
</syntaxhighlight >
  
== Basic Mobile Dialog ==
+
== Attaching dialogs to npcs ==
Here is an example of a simple Greetings Dialog override.
+
 
 +
Every npc has a basic AI file. lets go ahead and create our new npc ai file. we will save this file in your mods scripts folder as ai_mynpcdialog.lua
 +
 
 +
ai_mynpcdialog.lua
 
<syntaxhighlight lang="Lua">
 
<syntaxhighlight lang="Lua">
function Dialog.OpenGreetingDialog(user)
+
-- require the dialog system and basic npc ai functions
    -- this is the npcs dialog text for this conversation
+
require 'base_ai_npc'
     text = "Hello Stranger, What brings you to my part of town?"
+
 
   
+
--- opens up the npc greetings dialog menu
    -- a table containing player response information
+
--@param user - (gameobject) the user interacting with this dialog
 +
function Dialog.OpenGreetingsDialog(user)
 +
     text = "Welcome traveler to Eldier Village, how can I be of assistance?"
 +
 
 
     response = {}
 
     response = {}
 +
 
     response[1] = {}
 
     response[1] = {}
     response[1].text = "Do you know the muffin Man?"
+
     response[1].text = "Can you tell me about chickens?"
     response[1].handle = "MuffinMan"
+
     response[1].handle = "AboutChickens"
  
     -- this displays the dialog information to the user
+
     NPCInteraction(text,this,user,"Responses",response)
    NPCInteractionLongButton(text,this,user,"Responses",response)
+
end  
end
 
</syntaxhighlight>
 
  
Now we need to create the next part of the dailog which is another function. These functions for each new dialog are in the following format. Lets see what it looks like and then we will make the function for when the player clicks the MuffinMan response.
+
--- opens up the npc aboutchickens dialog menu
 +
--@param user - (gameobject) the user interacting with this dialog
 +
function Dialog.OpenAboutChickensDialog(user)
 +
    text = "I like the taste of them hmm? They lay eggs, make clucking noises... saw one fly for darn near 13 seconds."
  
Here is the function Format for dialog responses below
+
    response = {}
function Dialog.Open[RESPONSE_HANDLE]Dialog(user)
 
  
Here is an example function for the MuffinMan response.
 
<syntaxhighlight lang="Lua">
 
function OpenMuffinManDialog(user)
 
    -- this is the npcs dialog text for this conversation
 
    text = "Oh the muffin man, he is a strange person I tell ya, but thats all I know"
 
   
 
    -- a table containing player response information
 
    response = {}
 
 
     response[1] = {}
 
     response[1] = {}
     response[1].text = "Very Interesting?"
+
     response[1].text = "Golly Gee Mister"
 
     response[1].handle = "Greetings"
 
     response[1].handle = "Greetings"
  
     -- this displays the dialog information to the user
+
     NPCInteraction(text,this,user,"Responses",response)
    NPCInteractionLongButton(text,this,user,"Responses",response)  
+
end  
end
+
</syntaxhighlight >
</syntaxhighlight>
+
 
 +
Now we need a NPC file to test our new dialog script. copy this template file and save it as mydialognpc.xml in your mods templates directory.
 +
 
 +
mydialognpc.xml
 +
<syntaxhighlight lang="Xml">
 +
<ObjectTemplate>
 +
<ClientId>1</ClientId>
 +
<Hue>176</Hue>
 +
<Name>Billy Bob</Name>
 +
<ObjectVariableComponent>
 +
<StringVariable Name="MobileTeamType">Villagers</StringVariable>
 +
<StringVariable Name="MobileKind">Humanoid</StringVariable>
 +
<DoubleVariable Name="BaseHealth">300</DoubleVariable>
 +
<DoubleVariable Name="Armor">87</DoubleVariable>
 +
<DoubleVariable Name="Attack">44</DoubleVariable>
 +
<BoolVariable Name="NoDisrobe">True</BoolVariable>
 +
<BoolVariable Name="ImportantNPC">True</BoolVariable>
 +
<BoolVariable Name="noloot">True</BoolVariable>
 +
<BoolVariable Name="GuardProtect">True</BoolVariable>
 +
</ObjectVariableComponent>
 +
<ScriptEngineComponent>
 +
<LuaModule Name="ai_mynpcdialog">
 +
<Initializer>
 +
{
 +
    Stats = { Str=40, Agi=30, Int=21, Wis=10, Wil=10 },
 +
    Skills = { Brawling=100 },
 +
    EquipTable =
 +
                                    {
 +
        BodyPartHead = TemplateDefines.MaleHeads,
 +
        BodyPartHair = TemplateDefines.MaleHairVillage,
 +
        BodyPartFacialHair= TemplateDefines.MaleFacialHair,
 +
        Chest= {"merchant_clothing_chest"},
 +
        Legs= {"merchant_clothing_legs"},
 +
        Backpack= {"backpack",},
 +
    }
 +
}
 +
</Initializer>
 +
</LuaModule>
 +
</ScriptEngineComponent>
 +
<MobileComponent>
 +
<BaseRunSpeed>1</BaseRunSpeed>
 +
<MobileType>Friendly</MobileType>
 +
</MobileComponent>
 +
</ObjectTemplate>
 +
</syntaxhighlight >
  
This open muffinman dialog function will send the player back to the "Greetings" dialog. The response[?].handle is the name of the dialog, so in this second function we are sending the player back to the greeting.
+
== Testing your new dialog and npc ==
[[Category:Systems]]
+
*Load up your standalone or cluster server
 +
*when you log in to your God character type in /create mydialognpc and target the ground.
 +
*when you double click the npc to interact you will see your new dialog window if everything went okay.

Latest revision as of 20:07, 26 May 2021

Introduction

The dialog system for Legnds of Aria comes in various shapes. We have dialogs for npc conversations, progress bars and all things in between. In this section you will learn the structure and basics to creating your very own npc conversations for your players to enjoy. The general npc dialog system is a series of function calls where inside each of these functions is the information for the given dialog screen currently showing. Every page of the npc conversation has a npc dialog text area, and the player response area. The magic of the npc dialog system starts off with the NPCInteractionLongButton function lets look at the parts below.

--- opens up the npc dialog menu
--@param text - (string) a string containing the current message the npc is talking about
--@param npc - (gameobject) the npc currently interacting with the player
--@param player - (gameobject) the player currently interacting with this npc
--@param eventId - (string)a string identifying the event response of the dialog
--@param response - (table)a table containing response array table 
function NPCInteractionLongButton(text,npc,player,eventId,response)
end

When you first interact with a npc or use the talk context menu, the npc ai script will fire up the Dialog.OpenGreetingsDialog function. This function lives inside the base_ai_npc.lua script file. Notice how the function is camel case OpenGreetingsDialog. The way dialogs are setup is by player response and response handles. All dialog functions must be named Open + Handle Name + Dialog, you will see why looking below at a basic greetings override.

--- opens up the npc greetings dialog menu
--@param user - (gameobject) the user interacting with this dialog
function Dialog.OpenGreetingsDialog(user)
    text = "Welcome traveler to Eldier Village, how can I be of assistance?"

    response = {}

    response[1] = {}
    response[1].text = "Can you tell me about chickens?"
    response[1].handle = "AboutChickens"

    NPCInteraction(text,this,user,"Responses",response)
end

The above example will load up and work, but we do not have a AboutChickens function made. As discussed earlier the function name is Open + AboutChickens + Dialog so lets make this function and populate it with a response. Also lets loop back to the greetings message after the player gets to this dialog response page.

--- opens up the npc aboutchickens dialog menu
--@param user - (gameobject) the user interacting with this dialog
function Dialog.OpenAboutChickensDialog(user)
    text = "I like the taste of them hmm? They lay eggs, make clucking noises... saw one fly for darn near 13 seconds."

    response = {}

    response[1] = {}
    response[1].text = "Golly Gee Mister"
    response[1].handle = "Greetings"

    NPCInteraction(text,this,user,"Responses",response)
end

Attaching dialogs to npcs

Every npc has a basic AI file. lets go ahead and create our new npc ai file. we will save this file in your mods scripts folder as ai_mynpcdialog.lua

ai_mynpcdialog.lua

-- require the dialog system and basic npc ai functions
require 'base_ai_npc'

--- opens up the npc greetings dialog menu
--@param user - (gameobject) the user interacting with this dialog
function Dialog.OpenGreetingsDialog(user)
    text = "Welcome traveler to Eldier Village, how can I be of assistance?"

    response = {}

    response[1] = {}
    response[1].text = "Can you tell me about chickens?"
    response[1].handle = "AboutChickens"

    NPCInteraction(text,this,user,"Responses",response)
end 

--- opens up the npc aboutchickens dialog menu
--@param user - (gameobject) the user interacting with this dialog
function Dialog.OpenAboutChickensDialog(user)
    text = "I like the taste of them hmm? They lay eggs, make clucking noises... saw one fly for darn near 13 seconds."

    response = {}

    response[1] = {}
    response[1].text = "Golly Gee Mister"
    response[1].handle = "Greetings"

    NPCInteraction(text,this,user,"Responses",response)
end

Now we need a NPC file to test our new dialog script. copy this template file and save it as mydialognpc.xml in your mods templates directory.

mydialognpc.xml

<ObjectTemplate>
	<ClientId>1</ClientId>
	<Hue>176</Hue>
	<Name>Billy Bob</Name>
	<ObjectVariableComponent>
		<StringVariable Name="MobileTeamType">Villagers</StringVariable>
		<StringVariable Name="MobileKind">Humanoid</StringVariable>
		<DoubleVariable Name="BaseHealth">300</DoubleVariable>
		<DoubleVariable Name="Armor">87</DoubleVariable>
		<DoubleVariable Name="Attack">44</DoubleVariable>
		<BoolVariable Name="NoDisrobe">True</BoolVariable>
		<BoolVariable Name="ImportantNPC">True</BoolVariable>
		<BoolVariable Name="noloot">True</BoolVariable>
		<BoolVariable Name="GuardProtect">True</BoolVariable>
	</ObjectVariableComponent>
	<ScriptEngineComponent>
		<LuaModule Name="ai_mynpcdialog">
			<Initializer>
				{ 
				    Stats = { Str=40, Agi=30, Int=21, Wis=10, Wil=10 },
				    Skills = { Brawling=100 },	
				    EquipTable = 
                                    {
				        BodyPartHead = TemplateDefines.MaleHeads,
				        BodyPartHair = TemplateDefines.MaleHairVillage,
				        BodyPartFacialHair= TemplateDefines.MaleFacialHair,
				        Chest= {"merchant_clothing_chest"},
				        Legs= {"merchant_clothing_legs"},
				        Backpack= {"backpack",},
				    }
				}
			</Initializer>
		</LuaModule>
	</ScriptEngineComponent>
	<MobileComponent>
		<BaseRunSpeed>1</BaseRunSpeed>
		<MobileType>Friendly</MobileType>
	</MobileComponent>
</ObjectTemplate>

Testing your new dialog and npc

  • Load up your standalone or cluster server
  • when you log in to your God character type in /create mydialognpc and target the ground.
  • when you double click the npc to interact you will see your new dialog window if everything went okay.