GetPedTarget: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{Server client function}} This function is used to get the element a ped is currently targeting. ==Syntax== <syntaxhighlight lang="lua"> element getPedTarget ( ped thePed ) </syntaxhighlight> ===Re...) |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[ped]]:getTarget}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePed:''' The [[ped]] whose target you want to retrieve. | *'''thePed:''' The [[ped]] whose target you want to retrieve. | ||
Line 16: | Line 17: | ||
This is only effective on physical GTA elements, namely: | This is only effective on physical GTA elements, namely: | ||
* Players | * Players | ||
* Peds | |||
* Vehicles | * Vehicles | ||
* Objects | * Objects | ||
==Example== | ==Example== | ||
<section name="Server" class="server" show="true"> | |||
This example blows up any vehicle a player targets (aims at). | This example blows up any vehicle a player targets (aims at). | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 36: | Line 39: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
''Note: A more efficient way to do this would be to use the [[onPlayerTarget]] event.'' | ''Note: A more efficient way to do this would be to use the [[onPlayerTarget]] event.'' | ||
</section> | |||
==See Also== | ==See Also== | ||
{{ | {{Ped_functions}} |
Latest revision as of 07:08, 8 May 2017
This function is used to get the element a ped is currently targeting.
Syntax
element getPedTarget ( ped thePed )
OOP Syntax Help! I don't understand this!
- Method: ped:getTarget(...)
Required Arguments
- thePed: The ped 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
- Peds
- Vehicles
- Objects
Example
Click to collapse [-]
ServerThis 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 = getPedTarget ( 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
- addPedClothes
- getPedClothes
- removePedClothes
- createPed
- getPedAmmoInClip
- getPedArmor
- getPedFightingStyle
- getPedOccupiedVehicle
- getPedOccupiedVehicleSeat
- getPedStat
- getPedTarget
- getPedTotalAmmo
- getPedWalkingStyle
- getPedWeapon
- getPedWeaponSlot
- getPedContactElement
- getValidPedModels
- isPedChoking
- isPedDead
- isPedDoingGangDriveby
- isPedDucked
- isPedHeadless
- isPedInVehicle
- isPedOnFire
- isPedOnGround
- isPedWearingJetpack
- killPed
- removePedFromVehicle
- setPedAnimation
- setPedAnimationProgress
- setPedAnimationSpeed
- setPedArmor
- setPedDoingGangDriveby
- setPedFightingStyle
- setPedHeadless
- setPedOnFire
- setPedStat
- setPedWalkingStyle
- setPedWeaponSlot
- warpPedIntoVehicle