GetServerIp: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 8: Line 8:
string getServerIp ( [ bool includePort = false ] )
string getServerIp ( [ bool includePort = false ] )
</syntaxhighlight>
</syntaxhighlight>
===Optional Arguments===
*'''includePort:''' If set to ''true'', the string will include the port of the server at the end of the string, after a colon (:) character.
===Returns===
A string containing the remote address of the server the client is currently connected to.


==Example==  
==Example==  

Latest revision as of 20:07, 8 January 2025

ADDED/UPDATED IN VERSION 1.6.0 r22890:
This function returns the IP of the server the client is currently connected to.
[[{{{image}}}|link=|]] Note: On server-side there is the getServerIpFromMasterServer function, which might return the server IP under certain conditions.
You should consider using a third-party service via fetchServerIp (not an MTA function) if the previous function is unreliable for you.

Syntax

string getServerIp ( [ bool includePort = false ] )

Optional Arguments

  • includePort: If set to true, the string will include the port of the server at the end of the string, after a colon (:) character.

Returns

A string containing the remote address of the server the client is currently connected to.

Example

This example creates a console command that outputs the server's IP to the chatbox.

function outputServerIp()
    outputChatBox("You are currently connected to ".. getServerIp(true))
end

addCommandHandler("serverIp", outputServerIp)

See Also