Page 1 of 1

Coming into the world of LUA

Posted: Fri Jul 06, 2012 11:58 pm
by Durge
Hello everyone, I decided that I would like to help with the scripting part of the EMU this past night. Me and Jab had a long night, he helping me get the ropes of it a little, which I must say, helped SO MUCH, thank you Jab!!! Further, I have a test script that I would like someone to overview, tell me what I did wrong, or what can be improved, I used a script from the svn as a base and kind of just winged it and created my own. All positive criticism is welcome =)! This is my first script for EQ2 :D!

Code: Select all

--[[
	Testing Spawn Script
	By Durge
--]]

local quest1 = 1337 --Creates a local variable 'quest1' that uses the DB quest id of '1337'
local quest2 = 1338 --Same as above, just a different quest

function spawn(NPC) --When the npc is spawned
	ProvidesQuest(NPC, quest1) --This npc will provide the quest as declared in the local variable quest1
	ProvidesQuest(NPC, quest2) --Same as above, just adds quest2 to this npc as well
end --Ends the function

function respawn(NPC) --When the npc respawns
	spawn(NPC) --Spawn the npc again
end

function hailed(NPC, Player) --When the 'Player' hails the 'NPC'
	FaceTarget(NPC, Player) --Makes the 'NPC' face the 'Player'
	conversation = CreateConversation() --Starts a conversation called 'conversation'
	
	--[[
		This quest will have the player talk to the npc, recieve a contract
		to kill a mob and retrieve an item from them, then find the gem and kill the goblin for that
	--]]
	
	if HasCompletedQuest(Player, quest1) then --If quest1 has been completed, moves on to check quest2
		if HasCompletedQuest(Player, quest2) then --If quest2 is completed, then do
			Say(Player, "Thank you so much, I will remember this friend.") --Text to display once player has finished all quests
		elseif HasQuest(Player, quest2) then --Else if the player has quest2
			OnQuest2(NPC, Player, conversation) --Leads to the conversation that describes quest
		else --Else
			StartQuest2(NPC, Player, conversation) --Leads to the conversation to start the quest
		end --End the quest2 functions
	elseif HasQuest(Player, quest1) then --Else if the player has the first quest
		OnQuest1(NPC, Player, conversation) --Leads to the conversation that describes quest
	else --Else
		StartQuest1(NPC, Player, conversation) --Leads to conversation to start the first quest
	end
end

--[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
							Quest 1
--]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

function StartQuest1(NPC, Player, conversation) --Function to start the first quest
	FaceTarget(NPC, Player) --Faces the player
	
	AddConversationOption(conversation, "I'm listening, what is it you need me to find?", Dialog_1_1) --A dialog option for player
	AddConversationOption(conversation, "What are you talking about you old crone.") --A dialog option for player
	StartConversation(conversation, NPC, Player, "Welcome " .. GetName(Player) .. ", this is my humble abode, would you like to find a lost item for me?") --Starts the conversation with player
end

function Dialog_1_1(NPC, Player) --Function for the second dialog of quest
	FaceTarget(NPC, Player) --Faces the player
	conversation = CreateConversation() --Creates a new conversation for this dialog
	OfferQuest(NPC, Player, quest1) --Offers the quest to the player
	
	AddConversationOption(conversation, "Of course, just point me in the right direction", Dialog_1_2) --A dialog option for player
	AddConversationOption(conversation, "I'm sorry, I do not have the time to spare.", Dialog_2_1) --A dialog option for player
	StartConversation(conversation, NPC, Player, "Yes, a goblin seems to have snuck his way into my abode and stolen my precious amulet, I will reward you well if you recover this item.",) --Starts the conversation with player
end

function Dialog_1_2(NPC, Player) --Function for the the third part of dialog
	FaceTarget(NPC, Player) --Faces the player
	
	Say(Player, "Thank you " .. GetName(Player) .. " this was a family heirloom.") --Has the npc say something
end

function Dialog_2_1(NPC, Player) --Function for the first decline part of dialog
	FaceTarget(NPC, Player) --Faces the player
	
	Say(Player, "Think nothing of it, I'm sure you are a busy adventurer.") --Has the npc say something
end

function OnQuest1(NPC, Player, conversation) --If the player is already on this quest
	if GetQuestStep(Player, quest1) == 1 then --Checks to see what step the player is on
		Say(Player, "You still need to travel to the goblin's resting place.") --Hasn't found the goblin's resting area yet
	elseif GetQuestStep(Player, quest1) == 2 then --Checks to see what step the player is on
		Say(Player, "Where is my amulet? Have you killed the goblin yet?") --Hasn't killed the goblin yet
	else --Else
		AddConversationOption(conversation, "Here is your amulet, the goblin proved to be of little trouble.", Dialog_1_3) --A dialog option for player
		AddConversationOption(conversation, "That goblin proved to be much more difficult than you lead on.", Dialog_1_3) --A dialog option for player
		StartConversation(conversation, NPC, Player, "You have my amulet, yes?") --Starts the conversation with player
	end
end

function Dialog_1_3(NPC, Player) --Function for fourth part of dialog
	FaceTarget(NPC, Player) --Faces the player
	conversation = CreateConversation() --Creates a new conversation for this dialog
	SetStepComplete(Player, Quest1, 3) --Completes the first quest
	
	AddConversationOption(conversation, "What is it you had in mind?", Dialog_1_4) --A dialog option for player
	AddConversationOption(conversation, "Maybe another time.", Dialog_2_2) --A dialog option for player
	StartConversation(conversation, NPC, Player, "I am most grateful, however, if you are up to the task, I have something else that might interest you.") --Starts the conversation with player
end

function Dialog_2_2(NPC, Player) --Function for the second leaving dialog
	FaceTarget(NPC, Player) --Faces the player
	
	Say(Player, "Very well, have a good day.") --Has the npc say something
end

--[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
						Quest 2
--]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

function StartQuest2(NPC, Player, conversation) --Function to start the second quest
	FaceTarget(NPC, Player) --Faces the player
	
	AddConversationOption(conversation, "Where do you think the goblin may have lost it?", Dialog_1_3) --A dialog option for player
	AddConversationOption(conversation, "This is a mighty expensive amulet you seem to have.", Dialog_2_3) --A dialog option for player
	StartConversation(conversation, NPC, Player, "Back for more are we? Very well, in the process of stealing my amulet, the goblin seemed to have lost my gem, can you find it") --Starts the conversation with player
end

function Dialog_2_3(NPC, Player) --Function for the first leaving dialog of quest 2
	FaceTarget(NPC, Player) --Faces the player
	
	Say(Player, "Yes it is, it has been with my family for years, and it will stay that way.") --Has the npc say something
end

function Dialog_1_3(NPC, Player) --Function for the first dialog part of quest 2
	FaceTarget(NPC, Player) --Faces the player
	conversation = CreateConversation() --Creates a new conversation for this dialog
	OfferQuest(NPC, Player, quest2) --Offers the second quest to the player
	
	AddConversationOption(conversation, "Here we go again...", Dialog_1_4) --A dialog option for player
	StartConversation(conversation, NPC, Player, "I think he may have lost it somewhere around his, camp, maybe another goblin picked it up.") --Starts the conversation with player
end

function Dialog_1_4(NPC, Player) --Function for the third dialog part of quest 2
	FaceTarget(NPC, Player) --Faces the player
	
	Say(Player, "I am glad that you are so intrigued by my task.") --Has the npc say something
end

function OnQuest2(NPC, Player, conversation) --If the player is already on the quest
	if GetQuestStep(Player, quest2) == 1 then --Checks to see what step the player is on
		Say(Player, "Have you found the goblin?") --Hasn't found the second goblin yet
	elseif GetQuestStep(Player, quest2) == 2 then --Checks to see what step the player is on
		Say(Player, "I suppose the goblin just handed it over now, did he?") --Hasn't killed the second goblin yet
	else
		AddConversationOption(conversation, "It was my pleasure, I am glad to see you happy once again.", Dialog_1_5) --A dialog option for player
		AddConversationOption(conversation, "That goblin was downright nasty, I hope it was worth it", Dialog_1_5) --A dialog option for player
		StartConversation(conversation, NPC, Player, "I am overjoyed! It is wonderful that my amulet can finally be fully restored.") --Starts the conversation with player
	end
end

function Dialog_1_5(NPC, Player)
	FaceTarget(NPC, Player) --Faces the player
	SetStepComplete(Player, quest2, 3) --Completes the second quest
	
	Say(Player, "I thank you deeply for your time, and are forever indebted to you.") --Has the npc say something
end

Re: Coming into the world of LUA

Posted: Sat Jul 07, 2012 12:22 am
by John Adams
Always good to have a new scripter on board. I don't have time to read the entire script, but the best thing you can do is download our complete DB and Scripts releases and make modifications to those scripts using valid quests, items, spawns and other data. Shooting in the dark won't get you anywhere if you cannot test your script.

Also, not sure if this tool is complete, but Scatman wrote a Quest Creator tool.

https://svn.eq2emulator.net/svn/eq2tool ... stCreator/

Give that a try, too.

Re: Coming into the world of LUA

Posted: Sat Jul 07, 2012 4:59 pm
by Jabantiz
I read over this script and while it has a couple errors it is not bad for a first script, please note that what I point out is from reading the script, didn't actually try to set it up and run it.

The main thing I see is in the AddConversationOption, it is all right until the last parameter

Code: Select all

AddConversationOption(conversation, "I'm listening, what is it you need me to find?", Dialog_1_1)
The last parameter is a string so Dialog_1_1 should actually be "Dialog_1_1", it looks like quotes were left out on all of them.

Code: Select all

Say(Player, "Think nothing of it, I'm sure you are a busy adventurer.")
The first parameter of Say() is actually the spawn that is going to say the text so you probably want it to be NPC and not Player

The rest is just minor errors like this

Code: Select all

StartConversation(conversation, NPC, Player, "Yes, a goblin seems to have snuck his way into my abode and stolen my precious amulet, I will reward you well if you recover this item.",)
You have an extra ',' at the end.

Re: Coming into the world of LUA

Posted: Sat Jul 07, 2012 5:02 pm
by Durge
Ah I see what you're saying, ok thanks, this will help a ton =).

Re: Coming into the world of LUA

Posted: Fri Jul 13, 2012 12:32 pm
by John Adams

Re: Coming into the world of LUA

Posted: Fri Jul 13, 2012 1:27 pm
by Jabantiz
John Adams wrote:Is this Wiki article out of date?

http://eq2emulator.net/wiki/index.php/A ... ntentQuest
Quickly glancing over that wiki article I noticed it has you insert stuff into the DB, then later it uses RegisterQuest(), now I may be wrong as I have never written a quest script but I thought RegisterQuest() only needed to be used when there is no info in the DB for it. None of the quest scripts I have (from content svn) use that function, but I know in the lua function sticky it says required. It looks like the forums and wiki conflict with the provided quests scripts, or am I missing something simple as usual?

Re: Coming into the world of LUA

Posted: Fri Jul 13, 2012 3:42 pm
by John Adams
Nope, you are correct. RegisterQuest() I believe is indeed obsolete, as are adding all the Rewards-related calls to the script. Those are now stored in the quest_details table, and I believe some of the RegisterQuest() params now go into table `quests`. I'll see if I can remember how this works, and update that Wiki.

No wonder this is so hard ;)