OnClientPlayerNetworkStatus: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 16: Line 16:


==Example==  
==Example==  
This example shows a debug message when interruption starts and stops.
This example shows a debug message when interruption starts and stops and also prevents the local player moving during the interruption.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( "onClientPlayerNetworkStatus", root,
frozen = false -- This variable stores whether or not the script is going to freeze them.
  function( status, ticks )
-- If they were already frozen then don't unfreeze them when the interruption ends to avoid conflicts with other scripts.
    if status == 0 then
function handleInterrupt( status, ticks )
      outputDebugString( "(packets from server) interruption began " .. ticks .. " ticks ago" )
if (status == 0) then
    elseif status == 1 then
outputDebugString( "(packets from server) interruption began " .. ticks .. " ticks ago" )
      outputDebugString( "(packets from server) interruption began " .. ticks .. " ticks ago and has just ended" )
if (not isElementFrozen(localPlayer)) then
    end
setElementFrozen(localPlayer, true) -- Freeze them to prevent them abusing the network interruption
  end
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)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 22:49, 22 June 2015

This event is triggered when the network connection is interrupted.

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