OnClientElementStreamIn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:


==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[element]] that streamed in
The [[event system#Event source|source]] of this event is the [[element]] that streamed in.


==Example==  
==Example==  
This example shows you how to tell player that a marker was streamed in and the distance between player and the marker.
This example shows you how to tell player that a marker was streamed in and the distance between player and the marker.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( "onClientElementStreamIn", getRootElement( ),
addEventHandler( "onClientElementStreamIn", root,
     function ( )
     function ( )
         if getElementType( source ) == "marker" then
         if getElementType( source ) == "marker" then
             local myPosTab = { getElementPosition( getLocalPlayer( ) ) };
             local myPosTab = { getElementPosition( localPlayer ) };
             local markerPosTab = { getElementPosition( source ) };
             local markerPosTab = { getElementPosition( source ) };
             local distance = getDistanceBetweenPoints3D( unpack( myPosTab ), unpack( markerPosTab ) );
             local distance = getDistanceBetweenPoints3D( unpack( myPosTab ), unpack( markerPosTab ) );
Line 20: Line 20:
);
);
</syntaxhighlight>
</syntaxhighlight>
==Issues==
{{Issues|
{{Issue|7724|onClientElementStreamIn triggers twice when entering a vehicle}}
}}
==See Also==
==See Also==
===Client element events===
===Client element events===

Revision as of 14:50, 19 July 2020

This event is triggered whenever a physical element is streamed in. This is triggered for all elements that are streamable, such as players, peds, vehicles, objects and markers. When this event is triggered, that element is guaranteed to be physically created as a GTA object.

Source

The source of this event is the element that streamed in.

Example

This example shows you how to tell player that a marker was streamed in and the distance between player and the marker.

addEventHandler( "onClientElementStreamIn", root,
    function ( )
        if getElementType( source ) == "marker" then
            local myPosTab = { getElementPosition( localPlayer ) };
            local markerPosTab = { getElementPosition( source ) };
            local distance = getDistanceBetweenPoints3D( unpack( myPosTab ), unpack( markerPosTab ) );
            outputChatBox( "A marker has just streamed in. Distance to the marker: " .. tostring( distance ) .."." );
        end
    end
);

See Also

Client element events


Client event functions