GetPlayerCameraTargetActor

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 12:57, 1 May 2015
Ralfie (Talk | contribs)
(Sorry, a better format.)
← Previous diff
Revision as of 14:06, 11 May 2015
MP2 (Talk | contribs)
(Fixed example)
Next diff →
Line 13: Line 13:
{{Example|Actors perform a 'hands up' animation when aimed at}} {{Example|Actors perform a 'hands up' animation when aimed at}}
<pawn> <pawn>
 +new bool:ActorHandsup[MAX_ACTORS];
 +
public OnPlayerConnect(playerid) public OnPlayerConnect(playerid)
{ {

Revision as of 14:06, 11 May 2015


GetPlayerCameraTargetActor was added in SA-MP 0.3.7 This function was added in SA-MP 0.3.7 and will not work in earlier versions!


Description:

Allows you to retrieve the ID of the actor the player is looking at (in any).


Image:32px-Circle-style-warning.png

Important
Note

This function is disabled by default to save bandwidth. Use EnablePlayerCameraTarget to enable it for each player.


Parameters:
(playerid)
playeridThe ID of the player to get the target actor of.


Return Values:

The ID of the actor the player is looking at.


Example Usage: Actors perform a 'hands up' animation when aimed at

new bool:ActorHandsup[MAX_ACTORS];
 
public OnPlayerConnect(playerid)
{
    EnablePlayerCameraTarget(playerid, 1);
    return 1;
}
 
public OnPlayerUpdate(playerid)
{
    // Find out what actor (if any) the player is LOOKING at
    new playerTargetActor = GetPlayerCameraTargetActor(playerid);
 
    // If they ARE looking at ANY actor
    if(playerTargetActor != INVALID_ACTOR_ID)
    {
        // Store the player's weapon so we can check if they are armed
        new playerWeapon = GetPlayerWeapon(playerid);
 
        // Get the player's keys so we can check if they are aiming
        new keys, updown, leftright;
        GetPlayerKeys(playerid, keys, updown, leftright);
 
        // If the actor hasn't put its hands up yet, AND the player is ARMED
        if(!ActorHandsup[playerTargetActor] && playerWeapon >= 22 && playerWeapon <= 42 && keys & KEY_AIM)
        {
            // Apply 'hands up' animation
            ApplyActorAnimation(playerTargetActor, "SHOP", "SHP_HandsUp_Scr",4.1,0,0,0,1,0);
 
            // Set 'ActorHandsup' to true, so the animation won't keep being reapplied
            ActorHandsup[playerTargetActor] = true;
        }
    }
    return 1;
}
Tip

Image:Light_bulb_icon.png

This function only tells you which actor (if any) the player is looking at. To find out if they are aiming at them, you need to use GetPlayerTargetActor.


Related Functions

The following functions may be useful, as they are related to this function in one way or another.