IsElementSyncer

From Multi Theft Auto: Wiki
Revision as of 10:28, 31 December 2014 by AlexTMjugador (talk | contribs) (Added OOP syntax introduced in r6987 with a note to avoid confusions)
Jump to navigation Jump to search

This function checks whether an element is synced by the local player or not. Accepted elements are peds and vehicles.

Syntax

bool isElementSyncer ( element theElement )

{{New feature/item|3.0141|1.4.0|6987|{{OOP|.syncer variable is defined to the result of isElememtSyncer (either true or false). Don't confuse it with [[getElementSyncer]'s (which is a server only function).|element:isSyncer|syncer}}}}

Required Arguments

Returns

Returns true if the passed element is synced by the local player, false otherwise.

Example

Click to collapse [-]
Client

This example draws a string above peds synced by local player in 50m proximity

function renderSyncedElements ()
    -- Retrieve ped elements streamed in
    for k,el in ipairs (getElementsByType('ped', root, true)) do
        repeat
            if (not isElementSyncer(el)) then
                -- Skip if local player isn't syncer
                break
            end
            
            local pedX, pedY, pedZ = getElementPosition (el)
            local sX, sY, sD = getScreenFromWorldPosition (pedX, pedY, pedZ + 1.2)
            if (not sX) or (sD > 50) then
                -- Not on screen or too far away
                break
            end
            
            dxDrawText ('Syncer', sX, sY, 0, 0, tocolor(255,255,255,255), 20 / sD, 'arial')
        until true
    end
end
addEventHandler ('onClientRender', root, renderSyncedElements)

See Also