GetLocalPlayer: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Improved first example, added new one) |
||
Line 11: | Line 11: | ||
==Example== | ==Example== | ||
This clientside function outputs the player's current location to the console. | '''Example 1:''' This clientside function outputs the player's current location to the console. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function outputLocalPlayerPosition () | ||
--we get the player | --we get the local player | ||
local | local localPlayer = getLocalPlayer () | ||
--we get the player's position | --we get the local player's position | ||
local px, py, pz = | local px, py, pz = getElementPosition ( localPlayer ) | ||
--we output it to the console | --we output it to the console | ||
outputConsole ( "Your location: "..px.." "..py.." "..pz ) | outputConsole ( "Your location: "..px.." "..py.." "..pz ) | ||
end | end | ||
</syntaxhighlight> | |||
'''Example 2:''' This clientside script makes the local player's camera flash red after being hit. | |||
<syntaxhighlight lang="lua"> | |||
function flashRed () | |||
--we fade the local player's camera red during a second | |||
fadeCamera( false, 1.0, 255, 0, 0 ) | |||
--we set a 1000 ms (1 sec) timer to fade it back out | |||
setTimer( fadeCamera, 1000, 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 ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Client_player_functions}} | {{Client_player_functions}} |
Revision as of 12:05, 2 August 2007
This function gets the player element of the client running the current script.
Syntax
player getLocalPlayer ()
Returns
Returns a player element.
Example
Example 1: This clientside function outputs the player's current location to the console.
function outputLocalPlayerPosition () --we get the local player local localPlayer = getLocalPlayer () --we get the local player's position local px, py, pz = getElementPosition ( localPlayer ) --we output it to the console outputConsole ( "Your location: "..px.." "..py.." "..pz ) end
Example 2: This clientside script makes the local player's camera flash red after being hit.
function flashRed () --we fade the local player's camera red during a second fadeCamera( false, 1.0, 255, 0, 0 ) --we set a 1000 ms (1 sec) timer to fade it back out setTimer( fadeCamera, 1000, 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