Jump to content
Sign in to follow this  
V3ct0r

Quest requires 'X' hours after the start

Recommended Posts

[Script] Quest requires 'X' hours after the start

 

Hello!

 

In this thread I am posting an example of script that will allow you to check the condition when the player completes the quest: 'X' time has to pass after starting the quest to complete it.

 

 

Usage

MisResultCondition(MissionTimeExpired, <quest_id>, <time_in_seconds_to_wait>)

 

Installation

 

Add the following code to the file 'vairable.lua':

-- Table with the time of taking quests by characters
if (quest_table_guard == nil) then

	quest_table_guard = true
	quest_table = { }

end

 

Add to the file 'functions.lua':

-- Quest added event
AddMission__Original = AddMission
AddMission = function(role, id, param)
	
	-- Call original AddMission function
	local ret = AddMission__Original(role, id, param)
	
	-- Check the result
	if ( ret == LUA_TRUE ) then
	
		-- Add the quest to the table
		quest_table[id] = quest_table[id] or {}
		
		-- Remember the time when the character took the quest
		quest_table[id][ GetRoleID(role) ] = os.time()
	
	end

	-- Return original result
	return ret

end

-- Check that some time expired since character taken the quest
function MissionTimeExpired(role, id, t)

	-- Check that quest exists in the table
	if ( quest_table[id] == nil ) then
		
		-- Quest not found
		return LUA_TRUE
		
	end
	
	-- Get character ID
	local cha_id = GetRoleID(role)
	
	-- Check that the character has the quest
	if ( quest_table[id][cha_id] == nil ) then
	
		-- Character doesn't have the quest ?!
		return LUA_TRUE
	
	end
	
	-- Calculte time delta
	local delta = ( os.time() - quest_table[id][cha_id] )
	
	-- Check that t seconds expired since quest started
	if ( delta >= t ) then
		
		-- Remove character from table
		quest_table[id][cha_id] = nil
		
		-- Condition is completed
		return LUA_TRUE
	
	end
		
	-- Condition is not completed
	return LUA_FALSE
	
end

 

And finally register the new function in the file 'MissionSdk.lua' ('ConditionsTest' function):

. . .

elseif conditions[i].func == MissionTimeExpired then
	local ret = MissionTimeExpired( character, conditions[i].p1, conditions[i].p2 )
	if ret ~= LUA_TRUE then
		PRINT( "ConditionsTest: MissionTimeExpired = false" )
		return LUA_FALSE
	end
	
. . .

 

That's all! 

 

Note:

1) All data about the time of taking quests by characters will be lost when the server is restarted. You need to come up with a mechanism for saving the table 'quest_table' to a file or database if this is critical for your application;

2) NPCs that give and accept a quest with this condition must be within the same GameServer instance.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...