GetLocalPlayer: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This function gets the player element of the client running the current script. | This function gets the player element of the client running the current script. | ||
{{New feature/item|3.0110|1.1|| | |||
You can use the predefined variable '''localPlayer''' instead of typing getLocalPlayer() | |||
}} | |||
==Syntax== | ==Syntax== | ||
Line 16: | Line 20: | ||
-- we get the local player (we do this outside of the function body so it isn't retrieved every time | -- 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) | -- 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 ( getLocalPlayer ( ) ) | ||
-- output it to the console | -- output it to the console | ||
outputConsole ( "Your location: " .. px .. " " .. py .. " " .. pz ) | outputConsole ( "Your location: " .. px .. " " .. py .. " " .. pz ) | ||
Line 40: | Line 43: | ||
==See Also== | ==See Also== | ||
{{Client_player_functions}} | {{Client_player_functions}} | ||
[[ru:getLocalPlayer]] |
Revision as of 16:26, 18 September 2014
This function gets the player element of the client running the current script.
You can use the predefined variable localPlayer instead of typing getLocalPlayer()
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 ( getLocalPlayer ( ) ) -- 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
- forcePlayerMap
- getLocalPlayer
- getPlayerBlurLevel
- getPlayerFromName
- getPlayerMapBoundingBox
- getPlayerMapOpacity
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerTeam
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerHudComponentVisible
- isPlayerMapForced
- isPlayerMapVisible
- isPlayerNametagShowing
- isVoiceEnabled
- resetBlurLevel
- setPlayerBlurLevel
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney