From Multi Theft Auto: Wiki
(Redirected from LocalPlayer)
Jump to navigation Jump to search

This function gets the player element of the client running the current script.

You should use predefined variable localPlayer instead of typing getLocalPlayer() for better readability.


player getLocalPlayer ( )


Returns the local player element.


Example 1: This client side function outputs the player's current location to the console.

function outputLocalPlayerPosition()
	-- get the local player's position
	local px, py, pz = getElementPosition(localPlayer)
	-- output it to the console
	outputConsole("Your location: "..px.." " .." "..pz)

Example 2: This client side script makes the local player's camera flash red after being hit.

function flashRed()
	-- fade out the local player's camera to red during a second
	fadeCamera(false, 1.0, 255, 0, 0)
	-- set a 500 ms (0.5 sec) timer to fade it back in before it has completely faded out
	setTimer(fadeCamera, 500, 1, true, 1.0)
-- we attach our 'flashRed' function to be a handler of "onClientPlayerDamage" when its source (that is, the hit player) is the local player
addEventHandler("onClientPlayerDamage", localPlayer, flashRed)

See Also