MADD NØG Posted March 25, 2022 Share Posted March 25, 2022 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 Link to comment
Scyrix Posted March 26, 2022 Share Posted March 26, 2022 function getServerIP() return getServerConfigSetting("serverip") end serverip = getServerIP() print(serverip) Link to comment
Moderators IIYAMA Posted March 26, 2022 Moderators Share Posted March 26, 2022 21 hours ago, Neto Silva said: Does anyone know of a way to resolve this? For the resource servertimesync, I am using this method to solve that problem. 1. I am using the function getServerTime to get the time, if available. local timeNow = exports.servertimesync:getServerTime() 2. If it not available, then I am also listening to the event "onServerTimeInitialized", which is triggered when the data is available. addEventHandler( "onServerTimeInitialized", root, function() end ) 1 Link to comment
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