OnElementStopSync: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Fixed FabioGNR's changes and fixed example)
Line 2: Line 2:
{{Server event}}
{{Server event}}
{{Warning|In 1.1.x, Destroying the source of this event could crash the server!|true}}
{{Warning|In 1.1.x, Destroying the source of this event could crash the server!|true}}
{{Needs Example}}


This event is triggered when an element is no longer synced by a player.
This event is triggered when an element is no longer synced by a player.
Line 16: Line 15:
The [[event system#Event source|source]] of this event is the [[element]] which is no longer synced by a player.
The [[event system#Event source|source]] of this event is the [[element]] which is no longer synced by a player.


==Example==
This script creates a vehicle in the center of the map and outputs a message to its old syncer if he is not syncing the vehicle anymore.
<section name="Example" class="server" show="true">
<section name="Example" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
veh = createVehicle(520, 0,0,4) --  create our testing vehicle
--create our testing vehicle onResourceStart
addEventHandler ( "onResourceStart", getResourceRootElement( ),
function ( )
vehicle = createVehicle ( 520, 0, 0, 0 )
end )


function syncStop()
function syncStop ( oldSyncer )
if source == veh then -- check if the element that stopped getting synced was our vehicle
-- check if the element that stopped being synced was our vehicle
outputChatBox("You stopped syncing the vehicle!!",oldSyncer) -- tell the player he stopped syncing the vehicle ( veh )
if source == vehicle then
--tell the player (oldSyncer) he stopped syncing the vehicle
outputChatBox ( "The vehicle is not being synced by you anymore", oldSyncer )
end
end
end
end
--add the event handler
 
addEventHandler( "onElementStopSync", getRootElement(), syncStop )  
addEventHandler("onElementStopSync",getRootElement(),syncStop) --  onElementStopSync, the function syncStop gets called
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
{{See also/Server event|Element events}}
{{See also/Server event|Element events}}

Revision as of 23:06, 28 March 2012

Dialog-warning.png Warning: In 1.1.x, Destroying the source of this event could crash the server!

This event is triggered when an element is no longer synced by a player.

Parameters

player oldSyncer
  • oldSyncer: player element representing the last player who was syncing the element

Source

The source of this event is the element which is no longer synced by a player.

Example

This script creates a vehicle in the center of the map and outputs a message to its old syncer if he is not syncing the vehicle anymore.

Click to collapse [-]
Example
--create our testing vehicle onResourceStart
addEventHandler ( "onResourceStart", getResourceRootElement( ),
function ( )
	vehicle = createVehicle ( 520, 0, 0, 0 )
end )

function syncStop ( oldSyncer )
	-- check if the element that stopped being synced was our vehicle
	if source == vehicle then
		--tell the player (oldSyncer) he stopped syncing the vehicle
		outputChatBox ( "The vehicle is not being synced by you anymore", oldSyncer )
	end
end
--add the event handler
addEventHandler( "onElementStopSync", getRootElement(), syncStop ) 

See Also

Element events


Event functions