Eviles 179 Report post Posted September 4, 2019 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! 1 Quote Share this post Link to post Share on other sites
afonya 2 Report post Posted September 5, 2019 (edited) 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 September 5, 2019 by afonya 1 Quote Share this post Link to post Share on other sites
Angelix 374 Report post Posted September 6, 2019 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: 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. 1 Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted September 10, 2019 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 . Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted September 10, 2019 (edited) 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: 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 September 10, 2019 by Satan solutioned 1 Quote Share this post Link to post Share on other sites
boris cardona 0 Report post Posted April 5, 2020 Podrías pasarlo? Eh estado buscando el npc de información de portales. Quote Share this post Link to post Share on other sites