GetLocalPlayer: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
{{New feature/item|3.0110|1.1|| | {{New feature/item|3.0110|1.1|| | ||
You | You should use predefined variable '''localPlayer''' instead of typing getLocalPlayer() for better readability. | ||
}} | }} | ||
Line 21: | Line 21: | ||
-- the function is called, since the local player never changes) | -- the function is called, since the local player never changes) | ||
function outputLocalPlayerPosition ( ) | function outputLocalPlayerPosition() | ||
-- get the local player's position | -- get the local player's position | ||
local px, py, pz = getElementPosition ( | local px, py, pz = getElementPosition(localPlayer) | ||
-- output it to the console | -- output it to the console | ||
outputConsole ( "Your location: " .. px .. " " .. py .. " " .. pz ) | outputConsole("Your location: "..px.." "..py .." "..pz) | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 31: | Line 31: | ||
'''Example 2:''' This client side script makes the local player's camera flash red after being hit. | '''Example 2:''' This client side script makes the local player's camera flash red after being hit. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function flashRed ( ) | function flashRed() | ||
-- fade out the local player's camera to red during a second | -- fade out the local player's camera to red during a second | ||
fadeCamera( false, 1.0, 255, 0, 0 ) | 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 | -- 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 ) | setTimer(fadeCamera, 500, 1, true, 1.0) | ||
end | end | ||
-- we attach our 'flashRed' function to be a handler of "onClientPlayerDamage" when its source (that is, the hit player) is the local player | -- 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", getLocalPlayer ( ), flashRed ) | addEventHandler("onClientPlayerDamage", getLocalPlayer(), flashRed) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 16:17, 8 April 2024
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.
Syntax
player getLocalPlayer ( )
Returns
Returns the local player element.
Example
Example 1: This client side function outputs the player's current location to the console.
-- we get the local player (we do this outside of the function body so it isn't retrieved every time -- the function is called, since the local player never changes) function outputLocalPlayerPosition() -- get the local player's position local px, py, pz = getElementPosition(localPlayer) -- output it to the console outputConsole("Your location: "..px.." "..py .." "..pz) end
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) end -- 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", getLocalPlayer(), flashRed)
See Also
- getLocalPlayer
- getPlayerMapBoundingBox
- getPlayerMapOpacity
- isPlayerMapVisible
- resetBlurLevel
- isPlayerHudComponentVisible
- Shared
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState