I'm having problems trying to use getServerIp() and it returns the default 127.0.0.1, because the function it's requesting is apparently starting before fetchRemote gets the IP, I tested it in a separate resource and it works fine, but I wanted to use everything in just one resource.
Example like this return the default
SERVER_IP = "127.0.0.1"
function getServerIp()
return SERVER_IP
end
fetchRemote("http://checkip.dyndns.com/",
function (response)
if response ~= "ERROR" then
SERVER_IP = response:match("<body>Current IP Address: (.-)</body>") or "127.0.0.1"
end
end)
function ipTesting()
if connection then
--local serverIp = getServerConfigSetting("serverip") // I don't understand why it doesn't return the real IP when the ip in mtaserver is set to auto (it would be less stressful getServerConfigSetting("serverip") to return the IP of the server even though it is set to auto)
local serverIp = getServerIp()
if serverIp then
print(serverIp) --[[ Result 127.0.0.1 ]]--
end
end
When I add a SetTimer to wait for fetchRemote to return the value I get the server IP without any problems
Does anyone know of a way to resolve this? I specifically need to receive the IP when starting the resource and I was only able to do it through an external resource, I wanted to do everything in just one file, help me