1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.


Discussion in 'Snippets' started by Vektor42O, Feb 15, 2017.

  1. Vektor42O

    Vektor42O Active Member

    Likes Received:
    Jan 24, 2017
    I hope this will work. This code works only on client side.
    API.onUpdate.connect(function() {
        if(API.isControlPressed(25))//Is Player aiming
            var aimPos = API.getPlayerAimingPoint(API.getLocalPlayer());     //getting aiming position in 3d world
            var camPos = API.getGameplayCamPos();                            //getting camera position in 3d world
            aimPos = new Vector3( 
                                );    //Set aimPos 12 times far away using camPos, because getPlayerAimingPoint does not always hit objects
            var rayCast = API.createRaycast(camPos, aimPos, 12, API.getLocalPlayer()); //create the raycast between camPos and aimPos, with detecting peds only, (ignoring yours just in case)
            if (rayCast.didHitEntity)//Is Raycast hits a (gta:n) entity
                var hitPlayer = rayCast.hitEntity; //extract the player object
                API.sendChatMessage("You are aiming at " + API.getPlayerName(hitPlayer) + " right now!");
    This is just an example. You should not use this code on 120Hz tickrate. It's ok in every 2 secs.

    Last edited: Feb 28, 2017
    Ariana and Lukeifer like this.

Share This Page