GetElementSyncer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__
{{Server function}}
This function gets the syncer of an element. The syncer is the player who is in control of the element.
==Syntax==
<syntaxhighlight lang="lua">
element getElementSyncer ( element theElement )
</syntaxhighlight>
===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 is not being synced.
==Example==
==Example==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This code will kill the syncer of the first ped created with createPed
==Example 1==
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
     killPed(elementSyncer,elementSyncer)
     killPed(elementSyncer,elementSyncer)
end
end
</syntaxhighlight>
==Example 2==
This code will kill the syncer of the ped created with createPed.
<syntaxhighlight lang="lua">
function test(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
        killPed(elementSyncer,elementSyncer)
    end
end
addCommandHandler("test",test,false)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
==See Also==
{{Element functions}}
[[Category:Needs Example]]

Revision as of 11:36, 23 April 2009

Example

Click to collapse [-]
Server

Example 1

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
    killPed(elementSyncer,elementSyncer)
end

Example 2

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

function test(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
        killPed(elementSyncer,elementSyncer)
    end
end
addCommandHandler("test",test,false)