Desaster Posted December 11, 2013 Posted December 11, 2013 as the title says how I can get the GMT time of a player ?
codeluaeveryday Posted December 12, 2013 Posted December 12, 2013 I've done some research for you, and I found that the best way to achieve this would to use a public API. I was thinking of using it with a Unix timestamp of the local computers time to find a near accurate timezone, or we could use an ip address, or we could use both to get a more accurate GMT result. I have found the best API for this job, I have used them before with old projects. You will need to register an account and recieve your API key first: 1) Getting an API key from IPInfoDBA) Goto http://ipinfodb.com/register.php B) Fill in the details on the register page and click register. C) You will need to go to your email to confirm your account. D) When you log-in you will now see your API Key at the bottom of the grey box, keep that somewhere, we will need it shortly. EXAMPLE: API Key aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa addEventHandler('onPlayerJoin', root, function() -- Trigger GMT request local theIP = getPlayerIP(source) local theKey = 'MYKEYHERE' local apiURL = 'http://api.ipinfodb.com/v3/ip-city/?key='..theKey..'&ip='..theIP..'&format=json' fetchRemote(apiURL, gmtData, "", false, source) end ) function gmtData(data, response, player) local data = '['..data..']' local theData = fromJSON(data) if theData then setElementData(player, 'timezone', theData['timeZone']) else outputDebugString('Error parsing data') end end ^^ Tested and works, make sure you put your API key in it. To read it just use getElementData.
Desaster Posted December 12, 2013 Author Posted December 12, 2013 hmmm work / and don't work I get a false result result: -
codeluaeveryday Posted December 12, 2013 Posted December 12, 2013 Have you put the key in? it works for me. local theKey = 'MYKEYHERE' edit MYKEYHERE with the key from that site I sent.
Desaster Posted December 13, 2013 Author Posted December 13, 2013 I already did but I just get that result
codeluaeveryday Posted December 15, 2013 Posted December 15, 2013 send me a PM of the script you've written down, make sure this is server sided.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now