Advertisement
KrYn0MoRe

location test

May 27th, 2020 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. local plr = owner
  2. local char = owner.Character
  3. local head = char['Head']
  4. local http = game:GetService("HttpService")
  5. local api = 'http://api.timezonedb.com/v2.1/list-time-zone?key=OF12KQ2XXXIV&format=json'
  6.  
  7. function get_diff(i1,i2)
  8.     local _i1,_i2 = i1,i2
  9.     local r = 0
  10.     if i1 > i2 then
  11.         _i1 = i1
  12.          _i2 = i2
  13.     elseif i2 > i1 then
  14.         _i1 = i2
  15.          _i2 = i1
  16.     end
  17.     r = (_i1-_i2)
  18.     return r
  19. end
  20. function locate(user,t,h,st)
  21.     warn('Locating ' .. user.Name .. '. Please wait a couple seconds.')
  22.     local country = game:GetService("LocalizationService"):GetCountryRegionForPlayerAsync(user)
  23.     local full_country = ''
  24.     local timezones = http:JSONDecode(http:GetAsync(api))
  25.     local zone = ''
  26.     local closest = math.huge
  27.     local hour1 = h
  28.    
  29.     for i,v in pairs(timezones['zones']) do
  30.         if v['countryCode'] == country then
  31.             local t2 = v['timestamp']
  32.             local offset = v['gmtOffset']
  33.             local hour2 = t2
  34.             --[[if city_dst then
  35.                 if 0 > offset then
  36.                     offset = (offset - 3600)
  37.                 else
  38.                     offset = (offset + 3600)
  39.                 end
  40.             end]]
  41.             hour2 = (hour2+offset)
  42.             hour2 = (t2/3600%24) -- os.date("*t",t2).hour
  43.             local rh = get_diff(hour2,hour1)
  44.             if (closest >= rh) then
  45.                 closest = rh
  46.                 full_country = v['countryName']
  47.                 zone = v['zoneName']
  48.                 zone = string.sub(zone,string.find(zone, "/")+1,string.len(zone))
  49.             end
  50.         end
  51.     end
  52.     local ft = (tick()-st)
  53.     warn('Finished data.(' .. ft-(ft%0.001) .. ')')
  54.    
  55.     return closest,country,full_country,zone
  56. end
  57.  
  58. BillboardGui0 = Instance.new("BillboardGui")
  59. TextBox1 = Instance.new("TextBox")
  60. BillboardGui0.Parent = head
  61. BillboardGui0.LightInfluence = 1
  62. BillboardGui0.Size = UDim2.new(8, 0, 3, 0)
  63. BillboardGui0.Active = true
  64. BillboardGui0.ClipsDescendants = true
  65. BillboardGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  66. BillboardGui0.SizeOffset = Vector2.new(0, 2)
  67. TextBox1.Parent = BillboardGui0
  68. TextBox1.Size = UDim2.new(1, 0, 1, 0)
  69. TextBox1.BackgroundColor = BrickColor.new("Institutional white")
  70. TextBox1.BackgroundColor3 = Color3.new(1, 1, 1)
  71. TextBox1.BackgroundTransparency = 1
  72. TextBox1.Font = Enum.Font.SourceSans
  73. TextBox1.FontSize = Enum.FontSize.Size14
  74. TextBox1.TextColor = BrickColor.new("Institutional white")
  75. TextBox1.TextColor3 = Color3.new(1, 1, 1)
  76. TextBox1.TextScaled = true
  77. TextBox1.TextSize = 14
  78. TextBox1.TextStrokeTransparency = 0
  79. TextBox1.TextWrap = true
  80. TextBox1.TextWrapped = true
  81.  
  82. function changetxt(closest,country,full_country,zone)
  83.     TextBox1.Text = 'close: ' .. closest .. '\n code: ' .. country .. '\n country: ' .. full_country .. '\n zone: ' .. zone .. '\n geo lat/long: [redacted]'
  84. end
  85.  
  86. local remote = Instance.new("RemoteEvent")
  87. remote.Parent = plr['PlayerGui']
  88. remote.OnServerEvent:Connect(function(lplr,t,h)
  89.     changetxt(locate(plr,t,h or (t/3600%24),tick()))
  90. end)
  91.  
  92. local code = [[
  93. local d = os.date("*t")
  94. local t,h = tick(),d.hour
  95. if d.isdst then
  96.     h = (t+3600)
  97. end
  98. h = (t/3600%24)
  99. script.Parent:FireServer(t,h)
  100. ]]
  101.  
  102. NLS(code,remote)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement