PlayAkoya Posted August 10, 2015 Posted August 10, 2015 Hi, unfortunately my MTA request was refused and I still have not found a solution here hope someone can help me ? https://bugs.multitheftauto.com/view.php?id=8992 Here's a test: function getServerIp() callRemote("http://box.houkouonchi.jp/ip.php", function(value) value = tostring(value) end) return value end function getServerPutWithIP() outputChatBox("The server ip is: "..getServerIp().."", root, 200, 200, 0) end setTimer(getServerPutWithIP, 30000, -1) I always get an error message = nil It's not working Please Please help me ..
t3wz Posted August 11, 2015 Posted August 11, 2015 ehh serverIP = false fetchRemote ( "http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print ( "error "..e.." when getting serverip !" ) end end ) function getServerIP ( ) return serverIP; end obs: setTimer need a number higher than -1 in the third parameter also make sure you're using this code in server side.
PlayAkoya Posted August 11, 2015 Author Posted August 11, 2015 Thx, it works well. There are still a problem, when I use the command frequently then the port will always be added? And that's not good. serverIP = false fetchRemote("http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print("error "..e.." when getting serverip !" ) end end) function getServerIP () serverIP = tostring(""..serverIP..":"..getServerPort().."") serverIP = string.gsub(serverIP, "%s+", "") return serverIP; end function getServerPutWithIP() outputChatBox("The server ip is: "..getServerIP().."", root, 200, 200, 0) end addCommandHandler("serverip", getServerPutWithIP)
anumaz Posted August 11, 2015 Posted August 11, 2015 The port is duplicated because "serverIP" is set as IP:PORT, and everytime you call that function with /serverip, you still ask for the port again. You can avoid it by adding two variables instead of one. serverIP = false fetchRemote("http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print("error "..e.." when getting serverip !" ) end end) function getServerIP () serverIP = string.gsub(serverIP, "%s+", "") local formattedString = serverIP..":"..getServerPort() return formattedString; end function getServerPutWithIP() outputChatBox("The server ip is: "..getServerIP().."", root, 200, 200, 0) end addCommandHandler("serverip", getServerPutWithIP)
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