FIY9AL Posted April 10, 2020 Posted April 10, 2020 Hello evreyone, i have this code and it should be outputChatBox on player join his country name but i tried to get it work but nothing show on chatbox here is the code: addEventHandler("onPlayerJoin", root, function() function displayPlayerCity(resp, errno, source) if errno == 0 then data = fromJSON("[".. resp .. "]") status = data["status"] or "fail" if status == "success" then if isElement(source) then outputChatBox(getPlayerName(source).." has joined the game ("..data["city"]..", "..data["country"]..")", root, 255, 100, 100) end else if isElement(source) then outputChatBox(getPlayerName(source).." has joined the game.", root, 255, 100, 100) end outputDebugString("JOINQUIT: Cannot retrieve network details") end else outputDebugString("JOINQUIT: Error @fetchRemote, ERRNO: "..errno) end end fetchRemote("http://ip-api.com/json/" .. getPlayerIP(source), displayPlayerCity, "", false, source) end ) Any idea ?
Infinity-War Posted April 10, 2020 Posted April 10, 2020 you can't , because your ip adderss is private ..
iwalidza Posted April 10, 2020 Posted April 10, 2020 if you have admin panel you can use that is best idea exports.admin:getPlayerCountry(source)
Other Languages Moderators androksi Posted April 10, 2020 Other Languages Moderators Posted April 10, 2020 addEventHandler("onPlayerJoin", root, function() local ipAddress = getPlayerIP(source) fetchRemote("http://ip-api.com/json/" .. ipAddress, callback, "", false, source) end ) function callback(data, error, player) if error == 0 then local json = fromJSON("[" .. data .. "]") if json then local country = json.country or "???" local region = json.region or "???" outputChatBox("* " .. getPlayerName(player) .. " joined the server. [" .. country .. " - " .. region .. "]", root, 255, 255, 0) end else outputChatBox("* " .. getPlayerName(player) .. " joined the server. [??? - ???]", root, 255, 255, 0) end end You need to give ACL rights to the resource. If it didn't help, try using my code above.
FIY9AL Posted April 14, 2020 Author Posted April 14, 2020 On 10/04/2020 at 17:59, andreisrww said: addEventHandler("onPlayerJoin", root, function() local ipAddress = getPlayerIP(source) fetchRemote("http://ip-api.com/json/" .. ipAddress, callback, "", false, source) end ) function callback(data, error, player) if error == 0 then local json = fromJSON("[" .. data .. "]") if json then local country = json.country or "???" local region = json.region or "???" outputChatBox("* " .. getPlayerName(player) .. " joined the server. [" .. country .. " - " .. region .. "]", root, 255, 255, 0) end else outputChatBox("* " .. getPlayerName(player) .. " joined the server. [??? - ???]", root, 255, 255, 0) end end You need to give ACL rights to the resource. If it didn't help, try using my code above. Thank you its worked after i added it to admin acl and used your code
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