Jump to content
Sign in to follow this  
V3ct0r

Для завершения квеста должно пройти X часов

Recommended Posts

[Скрипт] Для завершения квеста должно пройти X часов 

 

Привет!

 

В этой теме я выложу пример скрипта, который позволит проверять следующее условие завершения квеста: после взятия игроком данного квеста, должно пройти некоторое время.

 

Данный вопрос обсуждался ранее в англоязычном разделе нашего форума:

 

 

Пример использования

 

MisResultCondition(MissionTimeExpired, <ID_квеста>, <время_в_секундах>)

 

 

Установка

 

Добавьте следующий код в файл 'variable.lua':

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

	quest_table_guard = true
	quest_table = { }

end

 

В файл '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

 

И, наконец, зарегистрируйте новую функцию в файле 'MissionSdk.lua' (функция 'ConditionsTest'):

. . .

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
	
. . .

 

Примечания:

1) При перезапуске GameServer.exe данные о времени взятия квестов персонажами будет потеряно. Если это критично для Вашего применения, то Вам необходимо придумать механизм сохранения таблицы 'quest_table' в файл или базу данных;

2) NPC, которые выдают и принимают квест с условием по времени, должны находится в пределах одного и того же экземпляра GameServer.


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...