Page 1 of 1

New Quest functions?

Posted: Fri Jul 02, 2010 6:02 pm
by rock5
Id like to add my quest function to the in-game-functions. I wasn't too satisfied with the way it worked originally but recently (about a patch or 2 back), I discovered a new command that gives you the status of the quests. I've since rewrote it and am quite happy with it.

Code: Select all

-- questname = name of quest
-- returns 'true' if quest complete 'false' if not and nil if not accepted
function igf_questStatus(_questname)
	local lowername=string.gsub(string.lower(_questname),"'","")
	local c = 1
	local getname = GetQuestRequest(c,-2)
	while getname ~= nil do
		getname=string.gsub(getname,"'","")
		if string.find(string.lower(getname), lowername) then -- Quest exists
			for i = 1, GetQuestRequest(c,-1) do -- for each goal
				__,getstatus = GetQuestRequest(c,i)
				if getstatus == 0 then -- check if not complete
					return false
				end
			end
			return true
        end
		c = c + 1
		getname = GetQuestRequest(c,-2)
	end
	return
end
I'd then add some functions to function.lua that would simplify using it, like so.

Code: Select all

function isQuestComplete(_questname)
	-- Do I need to turn in my quest?
	if (bot.IgfAddon == false) then
		error(language[1004], 0)	-- Ingamefunctions addon (igf) is not installed
	end
	
	local queststate = RoMScript("igf_questStatus(\"".._questname.."\")")
	if queststate == true then
		return true
	else
		return false
	end
end

function isQuestAccepted(_questname)
	-- Do I need to go an get the quest?
	if (bot.IgfAddon == false) then
		error(language[1004], 0)	-- Ingamefunctions addon (igf) is not installed
	end
	
	local queststate = RoMScript("igf_questStatus(\"".._questname.."\")")
	if (queststate == true) or (queststate == false) then
		return true
	else
		return false
	end
end

function getQuestStatus(_questname)
	-- Used when you need to make 3 way decision, get quest, complete quest or gather quest items.
	if (bot.IgfAddon == false) then
		error(language[1004], 0)	-- Ingamefunctions addon (igf) is not installed
	end
	
	return RoMScript("igf_questStatus(\"".._questname.."\")")
end
Any objections?

Re: New Quest functions?

Posted: Tue Jul 06, 2010 1:35 am
by Administrator
I don't see any problems with it. If it works, go ahead and include it. It certainly looks cleaner than the original code.

Re: New Quest functions?

Posted: Tue Jul 06, 2010 5:24 am
by rock5
Administrator wrote:I don't see any problems with it. If it works, go ahead and include it. It certainly looks cleaner than the original code.
You didn't mention the returned variables. I'm not really happy the in-game function returning true, false or nil to mean Complete, Accepted but not Complete and Not Accepted respectively. Seems cumbersome to explain and understand.

I thought maybe I should return 0, 1 or 2 instead. Then define some static variables;
COMPLETE = 2
NOT_COMPLETE = 1
NOT_ACCEPTED = 0

So in users script they can do something like this;

Code: Select all

if getQuestStatus(questname) == COMPLETE then
Would that be better?

Re: New Quest functions?

Posted: Tue Jul 06, 2010 6:51 pm
by Administrator
A string value being returned might be the best option. Then you can just check against "complete", "incomplete", or "not accepted" instead of defining those variables. As this isn't a very time critical or expensive function, it's fine to make use of strings here.

Re: New Quest functions?

Posted: Tue Jul 06, 2010 11:39 pm
by rock5
Administrator wrote:A string value being returned might be the best option. Then you can just check against "complete", "incomplete", or "not accepted" instead of defining those variables. As this isn't a very time critical or expensive function, it's fine to make use of strings here.
Bit late, I've already committed it. Do you want me to change it?

Re: New Quest functions?

Posted: Wed Jul 07, 2010 2:17 am
by Administrator
It's up to you. I think the strings would be easier to use. Integers aren't so bad, though. If it's not too much trouble, I'd say change it.

Re: New Quest functions?

Posted: Wed Jul 07, 2010 3:13 am
by rock5
Administrator wrote:It's up to you. I think the strings would be easier to use. Integers aren't so bad, though. If it's not too much trouble, I'd say change it.
ok I'll add it in the next commit. I doubt anyone has started using it yet.