OnClientPlayerNetworkStatus: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client event}} {{New items|3.0142|1.4.1-7295| __NOTOC__ This event is triggered when the network connection is interrupted. }} ==Parameters== <syntaxhighlight lang="lua"> int status, int...")
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:
{{New items|3.0142|1.4.1-7295|
{{New items|3.0142|1.4.1-7295|
__NOTOC__  
__NOTOC__  
This event is triggered when the network connection is interrupted.
This event is triggered when the server network connection to a player is interrupted. See [[onPlayerNetworkStatus]] for detecting player to server interruptions.
}}
}}
==Parameters==  
==Parameters==  
Line 16: Line 16:


==Example==  
==Example==  
This example plays a sound if it was downloaded successfully
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>



Latest revision as of 00:01, 28 January 2016

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