OnElementStopSync: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (→‎Example: Spaces ftw)
(Improve example.)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server event}}
{{Server event}}
{{Warning|In 1.1.x, Destroying the source of this event could crash the server!|true}}


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 10: Line 9:
</syntaxhighlight>  
</syntaxhighlight>  


*'''oldSyncer''': [[player]] element representing the last player who was syncing the element
*'''oldSyncer''': a [[player]] element representing the last player who was syncing the [[element]].


==Source==
==Source==
Line 17: Line 16:
==Example==
==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.
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">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--create our testing vehicle onResourceStart
function onResourceStart()
addEventHandler ( "onResourceStart", getResourceRootElement( ),
local vehicleElement = createVehicle(434, 0, 0, 3) -- Create vehicle
function ( )
    vehicle = createVehicle ( 520, 0, 0, 0 )
end )


function syncStop ( oldSyncer )
addEventHandler("onElementStopSync", vehicleElement, onElementStopSync) -- Bind handler specifically to it
    -- check if the element that stopped being synced was our vehicle
end
    if source == vehicle then
addEventHandler("onResourceStart", resourceRoot, onResourceStart)
        --tell the player (oldSyncer) he stopped syncing the vehicle
 
        outputChatBox ( "The vehicle is not being synced by you anymore", oldSyncer )
function onElementStopSync(oldSyncer)
    end
outputChatBox("The vehicle is not being synced by you anymore.", oldSyncer) -- Tell player (oldSyncer) that he's not syncing vehicle
end
end
--add the event handler
addEventHandler( "onElementStopSync", getRootElement(), syncStop )
</syntaxhighlight>
</syntaxhighlight>
</section>


{{See also/Server event|Element events}}
{{See also/Server event|Element events}}

Latest revision as of 23:50, 6 January 2023

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

Parameters

player oldSyncer
  • oldSyncer: a 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.

function onResourceStart()
	local vehicleElement = createVehicle(434, 0, 0, 3) -- Create vehicle

	addEventHandler("onElementStopSync", vehicleElement, onElementStopSync) -- Bind handler specifically to it
end
addEventHandler("onResourceStart", resourceRoot, onResourceStart)

function onElementStopSync(oldSyncer)
	outputChatBox("The vehicle is not being synced by you anymore.", oldSyncer) -- Tell player (oldSyncer) that he's not syncing vehicle
end

See Also

Element events


Event functions