Jump to content
Eviles

Retrieving Portal Information

Recommended Posts

Hello Guys 😃!

 

I'm trying to create a function which will display portal information such as: open every x, portal duration, map information, but i get stuck on returning if a portal/map is opened or not.
Actually i'm using Split() to retrieve data from an array similiar to ctrl.lua SetMapEntryTime. Any idea on what i should do to checking if portal/map opened or not and opening intervals if possible?

 

eg on what i'm doing:

 

    -- Array for timing configuration.
	EntryMaps.Conf['garner2']	= {"2006/10/18/11/0", "0/1/0", "0/0/30", "0/0/45"}

	-- Sample of Split, to return values from array.
	local Table				    = EntryMaps.Conf[mapName][1]
    local Value				    = Split(''..Table..'', '/')

 

Some preview of the NPC using the scripts:

 

https://gyazo.com/def32c0f24f78ce13906f5c5b6fcd166

 

Thanks!

  • Like 1

lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites

I'm assuming split returns a list of table values? if so, you need to compare the opening time to the current server time. I'm unsure what would be the best and some real quality code, but pseudo code would be as follows: 

Spoiler

function IsPortalOpen(open_hour, close_minute)

	local time = os.date("*t")
	local current_hour, current_minute, current_second = time.hour, time.min, time.sec
	local last_min = close_minute - 1
	local res = false
	
	local i = {3, 5, 7, 9 , 11, 13, 15, 17, 19, 21, 23}
	local j = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24}
	
	if open_hour % 2 ~= 0 then
		if open_hour == 1 then
			if current_minute <= last_min and current_second <= 59 then
				res = true
			end 
		else
			for x, v in pairs(i) do
				if x == open_hour then
					if current_hour % open_hour == 0 then
						if current_minute <= last_min and current_second <= 59 then
							res = true
						end 	
					end
				end
			end
		end
	else
		for i, v in pairs(j) do
			if i == open_hour then
				if current_hour % open_hour == 0 then
					if current_minute <= last_min and current_second <= 59 then
						res = true
					end 	
				end
			end
		end	
	end
	return res
end

//EntryMaps.Conf['garner2']	= {"2006/10/18/11/0", "0/1/0", "0/0/30", "0/0/45"}
// Current time: 13:27
// print(IsPortalOpen(1, 30)) --returns true

//EntryMaps.Conf['darkswamp']	= {"2006/10/18/11/0", "0/8/0", "0/0/50", "0/0/55"}
// Current time: 16:42
// print(IsPortalOpen(8, 50)) --returns true
//
// Current time: 20:42
// print(IsPortalOpen(8, 50)) --returns false

 

 

Edited by afonya
  • Like 1

Share this post


Link to post
Share on other sites

It can be achieved with "string.format" and "os.time()".

This is how to read the starting date:

	local oYear, oMonth, oDay, oHour, oMin = Table.Time:match('(%d+)/(%d+)/(%d+)/(%d+)/(%d+)')

Then onto reading opening interval, portal duration and map duration:

	local iDay, iHour, iMin, pDay, pHour, pMin, mDay, mHour, mMin = Table.Time:match('"(%d+)/(%d+)/(%d+)", "(%d+)/(%d+)/(%d+)", "(%d+)/(%d+)/(%d+)"')

"Table" refers to this:

MapTimerNPC.Table['abandonedcity'] = {ID = 88, Map = 0, PosX = 0, PosY = 0, Time = '"2005/8/30/0/0", "0/3/0", "0/1/0", "0/2/0"'}

I have achieved this:

Capture.PNG.61a8b46119b1e14d21de8336b35af0bb.PNG

 

You have to turn the dates into seconds, get the current date and the seconds passed since start date (referring to "2005/8/30/0/0"). From there you also need start comparing times which is not that hard having the 2 functions I mentioned at the start.

  • Like 1

Share this post


Link to post
Share on other sites
On 9/5/2019 at 1:11 PM, afonya said:

I'm assuming split returns a list of table values? if so, you need to compare the opening time to the current server time. I'm unsure what would be the best and some real quality code, but pseudo code would be as follows: 

  Reveal hidden contents


function IsPortalOpen(open_hour, close_minute)

	local time = os.date("*t")
	local current_hour, current_minute, current_second = time.hour, time.min, time.sec
	local last_min = close_minute - 1
	local res = false
	
	local i = {3, 5, 7, 9 , 11, 13, 15, 17, 19, 21, 23}
	local j = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24}
	
	if open_hour % 2 ~= 0 then
		if open_hour == 1 then
			if current_minute <= last_min and current_second <= 59 then
				res = true
			end 
		else
			for x, v in pairs(i) do
				if x == open_hour then
					if current_hour % open_hour == 0 then
						if current_minute <= last_min and current_second <= 59 then
							res = true
						end 	
					end
				end
			end
		end
	else
		for i, v in pairs(j) do
			if i == open_hour then
				if current_hour % open_hour == 0 then
					if current_minute <= last_min and current_second <= 59 then
						res = true
					end 	
				end
			end
		end	
	end
	return res
end

//EntryMaps.Conf['garner2']	= {"2006/10/18/11/0", "0/1/0", "0/0/30", "0/0/45"}
// Current time: 13:27
// print(IsPortalOpen(1, 30)) --returns true

//EntryMaps.Conf['darkswamp']	= {"2006/10/18/11/0", "0/8/0", "0/0/50", "0/0/55"}
// Current time: 16:42
// print(IsPortalOpen(8, 50)) --returns true
//
// Current time: 20:42
// print(IsPortalOpen(8, 50)) --returns false

 

 

Thanks, that sure gave me more insight into what I needed 😃.


lelouch_signature_by_vahntheknight-d4uafwj.png

Share this post


Link to post
Share on other sites
On 9/6/2019 at 1:13 AM, Angelix said:

It can be achieved with "string.format" and "os.time()".

This is how to read the starting date:


	local oYear, oMonth, oDay, oHour, oMin = Table.Time:match('(%d+)/(%d+)/(%d+)/(%d+)/(%d+)')

Then onto reading opening interval, portal duration and map duration:


	local iDay, iHour, iMin, pDay, pHour, pMin, mDay, mHour, mMin = Table.Time:match('"(%d+)/(%d+)/(%d+)", "(%d+)/(%d+)/(%d+)", "(%d+)/(%d+)/(%d+)"')

"Table" refers to this:


MapTimerNPC.Table['abandonedcity'] = {ID = 88, Map = 0, PosX = 0, PosY = 0, Time = '"2005/8/30/0/0", "0/3/0", "0/1/0", "0/2/0"'}

I have achieved this:

Capture.PNG.61a8b46119b1e14d21de8336b35af0bb.PNG

 

You have to turn the dates into seconds, get the current date and the seconds passed since start date (referring to "2005/8/30/0/0"). From there you also need start comparing times which is not that hard having the 2 functions I mentioned at the start.

Thanks all who help me, scripts are arealdy considered finished. That what i've achieved arealdy 😁:

 

https://gyazo.com/1e3d05833ef6214bf8836ab56c7883bd

Edited by Satan
solutioned
  • Like 1

lelouch_signature_by_vahntheknight-d4uafwj.png

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.


×
×
  • Create New...