GetElementSyncer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(11 intermediate revisions by 7 users not shown)
Line 7: Line 7:
element getElementSyncer ( element theElement )
element getElementSyncer ( element theElement )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[element]]:getSyncer|syncer|setElementSyncer}}


===Required Arguments===
===Required Arguments===
Line 12: Line 13:


===Returns===
===Returns===
Returns the [[element]] that is the syncer of ''theElement'' or ''false'' if the element is not being synced.
Returns the [[element]] that is the syncer of ''theElement'' or ''false'' if the element does not have a syncer.


==Example==
==Example==
<section name="Server" class="server" show="true">
This code will kill the syncer of the first ped created with createPed.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local elementSyncer = getElementSyncer(getElementsByType("ped")[1])
local elementSyncer = getElementSyncer(getElementsByType("ped")[1])
if getElementType(elementSyncer) == "player" then
if elementSyncer and getElementType(elementSyncer) == "player" then --Check if its a player and if there is a syncer
     killPed(elementSyncer,elementSyncer)
     killPed(elementSyncer, elementSyncer)
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
This code will kill the syncer of the ped created with createPed.
<syntaxhighlight lang="lua">
function testKill(player,commandName)
    local idlewoodPed = createPed(26,1813.27,-1897.04,13.577)
    local elementSyncer = getElementSyncer(idlewoodPed)
    if elementSyncer and getElementType(elementSyncer) == "player" then --Check if its a player and if there is a syncer
        killPed(elementSyncer, elementSyncer)
    end
end
addCommandHandler("testkill", testKill)
</syntaxhighlight>


==See Also==
==See Also==
{{Element functions}}
{{Element_functions|server}}
[[Category:Needs Example]]

Latest revision as of 22:30, 6 September 2024

This function gets the syncer of an element. The syncer is the player who is in control of the element.

Syntax

element getElementSyncer ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:getSyncer(...)
Variable: .syncer
Counterpart: setElementSyncer


Required Arguments

  • theElement: The element to get the syncer of.

Returns

Returns the element that is the syncer of theElement or false if the element does not have a syncer.

Example

This code will kill the syncer of the first ped created with createPed.

local elementSyncer = getElementSyncer(getElementsByType("ped")[1])
if elementSyncer and getElementType(elementSyncer) == "player" then --Check if its a player and if there is a syncer
    killPed(elementSyncer, elementSyncer)
end

This code will kill the syncer of the ped created with createPed.

function testKill(player,commandName)
    local idlewoodPed = createPed(26,1813.27,-1897.04,13.577)
    local elementSyncer = getElementSyncer(idlewoodPed)
    if elementSyncer and getElementType(elementSyncer) == "player" then --Check if its a player and if there is a syncer
        killPed(elementSyncer, elementSyncer)
    end
end
addCommandHandler("testkill", testKill)

See Also