Jump to content
Sign in to follow this  
NabSlayer

Quest require x hours online

Recommended Posts

Hello PkoDev :)

I would know if is possible make quest which will require from Player to stay x hours online, and how make it?

Have a nice Day! :D

Edited by NabSlayer

Share this post


Link to post
Share on other sites

I'm not sure at all, and I can't check it but I think the online time was stored somewhere on the database. (I'm guessing this 'cause I remember seeing some sites that display the online time for every character on your account).

Try to search inside DBs.

In case you find it stored somewhere, you should use LuaSql extension and play with it.

 

That may be not so helpful, but it is only a hint.

Share this post


Link to post
Share on other sites
SQL = {}
SQL.Host = "hostname"
SQL.User = "username"
SQL.Pass = "password"
function GetOnlineTime(role)
	local PlayerID = GetCharID(role)
	local String = "SELECT total_live_time FROM AccountServer.dbo.account_login WHERE id IN (SELECT act_id FROM GameDB.dbo.character WHERE cha_id = "..PlayerID..")"
	local Connect, ConnectID = LuaSQL("connect", SQL.Host, SQL.User, SQL.Pass)
	if Connect == 1 then
		local Success, Query = LuaSQL("query", ConnectID, String)
		if Success == 1 then
			local Data = LuaSQL("fetch", ConnectID, Query)
			Data = tonumber(Data["total_live_time"])
			LuaSQL("freehandle", ConnectID, Query)
			LuaSQL("close", ConnectID)
			return Data
		end
	end
end

function HasOnlineTime(role,value)
	local OnlineTime = GetOnlineTime(role)
	if OnlineTime >= value then
		return LUA_TRUE
	end
	return LUA_FALSE
end

--MissionSdk.lua (ConditionsTest)
			elseif conditions[i].func == HasOnlineTime then
				local ret = HasOnlineTime( character, conditions[i].p1 )
				if ret ~= LUA_TRUE then
					return LUA_FALSE
				end

--Quest Scripts
MisResultCondition(HasOnlineTime,3600)

P.S: required LuaSQL 

 

  • Like 5

Share this post


Link to post
Share on other sites

Cool, that's what I ment.

If you want players to stay X time since they took the quest, you need to store the total_live_time (at the moment they begin the quest) into a file trough serialize, and then check:

current total_live_time - stored total_live_time = time elapsed since you took the quest.

if time elapsed == mission requirement then give reward.

 

Edited by iZae

Share this post


Link to post
Share on other sites

Hello @ilusionbr!

 

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

 

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

 

 

Now you can use the expired time condition in quest scripts:

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

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 12/25/2021 at 9:03 PM, ilusionbr said:

Hello @V3ct0r , Thanks for you help! It worked!

Great! 

 

Note that 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. Also, NPCs that give and accept a quest with this condition must be within the same GameServer instance.


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