GetNetworkStats

From Multi Theft Auto: Wiki
Revision as of 14:14, 12 August 2011 by Arran Fortuna (talk | contribs) (Client examples)
Jump to navigation Jump to search

This function returns network status information.

Available in 1.1 and onwards

Syntax

Click to collapse [-]
Client
table getNetworkStats ( )
Click to collapse [-]
Server
table getNetworkStats ( [ element thePlayer = nil ] )

Optional Arguments

  • thePlayer: The player you want to retrieve network stats from.

Returns

Returns a table, the indexes in the table are the following:

  • "bytesReceived"
  • "bytesSent"
  • "packetsReceived"
  • "packetsSent"
  • "packetlossTotal"
  • "packetlossLastSecond"
  • "messagesInSendBuffer"
  • "messagesInResendBuffer"
  • "isLimitedByCongestionControl"
  • "isLimitedByOutgoingBandwidthLimit"
  • "encryptionStatus"

Example

Click to collapse [-]
Client

This example outputs the local players network status information to their console when using the /netstatus command

function netStatus()
	for index, value in pairs(getNetworkStats()) do
		outputConsole(index..": "..value)
	end
	outputChatBox("Network status output to console", 0, 255, 0)
end
addCommandHandler("netstatus", netStatus)

This example outputs a warning to local player if packet loss occured in the last second

function packetLossCheck()
	local loss = getNetworkStats()["packetlossLastSecond"]
	if (loss > 0) then
		outputChatBox("Packet loss detected when communicating with server, gameplay may be affected", 255, 0, 0)
	end
end
setTimer(packetLossCheck, 1000, 0)

See Also