GetPlayerTarget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Visual improvement) |
||
(11 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | |||
This function is used to get the | {{Deprecated|getPedTarget}} | ||
This function is used to get the element a [[player]] is currently targeting. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
element getPlayerTarget ( player thePlayer ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''thePlayer:''' The [[player]] whose target you want to retrieve. | ||
===Returns=== | ===Returns=== | ||
Returns the [[ | Returns the [[element]] that's being targeted, or ''false'' if there isn't one. | ||
This is only effective on physical GTA elements, namely: | |||
* Players | |||
* Vehicles | |||
* Objects | |||
==Example== | ==Example== | ||
This example blows up any vehicle a | This example blows up any vehicle a player targets (aims at). | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function playerTargetCheck ( player ) -- | function playerTargetCheck ( ) | ||
local target | |||
for i, thePlayer in ipairs ( getElementsByType("player") ) do -- iterate over all players | |||
target = getPlayerTarget ( thePlayer ) -- get the target of the current player | |||
if ( target ) then -- if there was a target | |||
if ( getElementType ( target ) == "vehicle" ) then -- and the target is a vehicle | |||
blowVehicle ( target ) -- blow it up | |||
end | |||
end | |||
end | end | ||
end | end | ||
setTimer ( playerTargetCheck, 1000, 0 ) -- call the check function every second | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''Note: A more efficient way to do this would be to use the [[onPlayerTarget]] event.'' | |||
==See Also== | ==See Also== | ||
{{Player functions}} | {{Player functions}} |
Latest revision as of 11:02, 26 June 2014
This function is deprecated. This means that its use is discouraged and that it might not exist in future versions. | |
Please use getPedTarget instead. |
This function is used to get the element a player is currently targeting.
Syntax
element getPlayerTarget ( player thePlayer )
Required Arguments
- thePlayer: The player whose target you want to retrieve.
Returns
Returns the element that's being targeted, or false if there isn't one.
This is only effective on physical GTA elements, namely:
- Players
- Vehicles
- Objects
Example
This example blows up any vehicle a player targets (aims at).
function playerTargetCheck ( ) local target for i, thePlayer in ipairs ( getElementsByType("player") ) do -- iterate over all players target = getPlayerTarget ( thePlayer ) -- get the target of the current player if ( target ) then -- if there was a target if ( getElementType ( target ) == "vehicle" ) then -- and the target is a vehicle blowVehicle ( target ) -- blow it up end end end end setTimer ( playerTargetCheck, 1000, 0 ) -- call the check function every second
Note: A more efficient way to do this would be to use the onPlayerTarget event.
See Also
- 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