OnClientPlayerNetworkStatus

From Multi Theft Auto: Wiki

This event is triggered when the server network connection to a player is interrupted. See onPlayerNetworkStatus for detecting player to server interruptions.

Parameters

int status, int ticks
  • status: A number which is 0 if the interruption has begun, or 1 if the interruption is ending.
  • ticks: Number of ticks since the interruption started.

Source

The source of this event is the root element.

Example

This example shows a debug message when interruption starts and stops and also prevents the local player moving during the interruption.

frozen = false -- This variable stores whether or not the script is going to freeze them.
-- If they were already frozen then don't unfreeze them when the interruption ends to avoid conflicts with other scripts.
function handleInterrupt( status, ticks )
	if (status == 0) then
		outputDebugString( "(packets from server) interruption began " .. ticks .. " ticks ago" )
		if (not isElementFrozen(localPlayer)) then
			setElementFrozen(localPlayer, true) -- Freeze them to prevent them abusing the network interruption
			frozen = true
		end
	elseif (status == 1) then
		outputDebugString( "(packets from server) interruption began " .. ticks .. " ticks ago and has just ended" )
		if (frozen) then
			setElementFrozen(localPlayer, false) -- If we froze them, unfreeze them now.
			frozen = false
		end
	end
end
addEventHandler( "onClientPlayerNetworkStatus", root, handleInterrupt)

See Also

Other client events