Multiple conditions in one function how to accomplish?

Hello,

I have a problem, I am at a point where a NPC has multiple quest, can accept said quest, but how can I write a function that can do multiple conditions.
Obviously, if they have accepted the quest already I return end.

	local isAccepted = QuestConfig.GetQuestAccepted(npc, id, StateManager.GetData())
	if isAccepted then return end

But what I want also is if they have completed a quest I also want them to be able to turn it in.
My only solution is to create the same exact function for CompleteQuest. To me this seems extremely inefficient. I want one function that does the same thing essentially, but both need two way different conditions. The reason I return end is to protect someone from accepting the quest again. The condition for my other function checks if the progress is 100% if it isn’t then return end. I cannot allow these two functions to pass with out that condition or else unwanted behavior. Does anyone know how to achieve this? Here is my other condition:

local progress = QuestConfig.GetQuestProgress(npc, config.Id, StateManager.GetData())
if progress < 100 then return end

Is this what you’re trying to accomplish?

if isAccepted and progress == 100 and claimed then
	--they already claimed the quest rewards
elseif isAccepted and progress == 100 then
	--they're claiming the quest rewards
elseif isAccepted then
	--they haven't finished the quest
else
	--they haven't been given the quest
end

Or perhaps what you’re asking for is a way for the NPC to manage multiple pending quests at once? For example if an NPC has 4 quests and the player has finished one, first reward them that quest(when they speak to it), then give them the option to get another one? Like some sort of action priority system? Or perhaps an NPC that gives multiple options to the user(for example claim quest one, start quest three)?

1 Like

You could use an Enum for the quest states.
Instead of multiple elseif statements.

local EnumQuestState = {
    RequirementNotMet = 0,
    CanAccept = 1, -- the quest can start
    AcceptedAndPending = 2, -- accepted and pending
    CanFinish = 3, -- can be finished by talking to the npc or someother event
    Finished = 4, -- the quest has finished and rewards claimed
}
1 Like

Didn’t even know this was possible, thank you. Wow this is why we use dev forums.

Yes this is it, I can’t give two solutions but you accomplish the same thing as enum state. I appreciate everyones response as some reason my brain just didn’t know you could do this still new to coding.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.