GetPedTarget: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(One intermediate revision by one other user 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

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 [-]
Server

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 = 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