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.

Get NetHandle Ped position ?

Discussion in 'Scripting Help' started by Leonardo_Gonzalez, May 17, 2017.

  1. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    Hi,

    i'd like to know how i can convert NetHandle to ped or get ped position (NetHandle) ?
    getEntityFromHandle doesn't work at this time.

    Thanks for your help and sorry for my bad english.
     
  2. TheSup

    TheSup Active Member

    Messages:
    79
    Likes Received:
    10
    Joined:
    Apr 18, 2017
  3. Bonus

    Bonus Member

    Messages:
    13
    Likes Received:
    0
    Joined:
    May 3, 2017
    getEntityFromHandle should work o_O
    How do you get the NetHandle?
    How do you use getEntityFromHandle?
     
  4. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    "
    getEntityFromHandle

    [​IMG] Note: This feature is currently not in the API, or is currently not accurate on the wiki due to upcoming API changes. New API functions and changes will be released with the next update. "

    I have already tried with
    API.getEntityPosition(ped)
    but when the ped move (with the native TASK_GO_TO_ENTITY), the position doesn't change :/

    Thanks for your answers
     
  5. Bonus

    Bonus Member

    Messages:
    13
    Likes Received:
    0
    Joined:
    May 3, 2017
    Ignore the note, getEntityFromHandle is working.
    doormanager is using it ...

    The position doesn't change? Maybe a GTA:Network bug?
     
  6. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    I don't find getEntityFromHandle in doormanager,
    Yes the position doesn't change but the ped moves :/
     
  7. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Hi,
    How are you refering to the Ped object?
    Show us the code. It's hard to help without the code.

    You wold need a method similar to this:

    Code:
        public void PedPosition(NetHandle ped)
        {
            Vector3 pos = API.getEntityPosition(ped);
            API.consoleOutput(pos.ToString());
        }
    But we need to know how do you refer to the entity. How does the script know which ped it should call the native on?
     
  8. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    Code:
    foreach(Client player2 in nearC)
                    {
                        if(API.getEntitySyncedData(p, "enPartie")==API.getEntitySyncedData(player2, "enPartie") && API.getEntitySyncedData(player2, "estMort")==0)
                        {
                            API.sendNativeToPlayer(player2, 0xA9DA48FAB8A76C12, p, joueurProche, 1.5, 10.0); // TASK_GO_TO_ENTITY 0x6F6FC7E6
                        }
                    }
    In this code, "joueurProche" is the player closest to the ped (The code that checks this must be false too because the ped position doesn't change).
    I have a timer for each ped "p" and each player "player2". I send the native to all the players.

    I want the ped attack the player when it's close, with this code (after the previous code) :

    Code:
    pos = API.getEntityPosition(joueurProche);
                    zpos = API.getEntityPosition(p);
                    //API.consoleOutput("Distance1 : " + pos.X);
                    //API.consoleOutput("Distance2 : " + zpos.X);
                    if(pos.DistanceTo(zpos)<=1.0)
                    {
                        Attack(p,joueurProche);
                    }
    But "zpos" doesn't change. It is always the position where the ped spawn (But the ped moves).

    Thanks for your help and sorry for my bad english
     
  9. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    How does this code know the "p" variable? You have only defined player2 as Client inside nearC. Then you try to receive the entitysynceddata for the ped, but ped doesn't seem to be defined in this loop. Do you have it defined before this code?
     
  10. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    yes, i have this before :

    Code:
    List<NetHandle> peds = API.getAllPeds();
            foreach(NetHandle p in peds)
            {
     
  11. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    What if you try to change the native that moves the ped to:

    Code:
    API.sendNativeToPlayer(player2,Hash.TASK_FOLLOW_NAV_MESH_TO_COORD, p, joueurProche.position.X, joueurProche.position.Y, joueurProche.position.Z, 2, -2, -1);
    After position Z you have speed (2), timeout (-2) and stopping range (-1).
    Check if the position updates.
     
  12. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    With this native, the ped doesn't moves at all
     
  13. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Try like this:
    Code:
    API.sendNativeToPlayer(player2,Hash.TASK_FOLLOW_NAV_MESH_TO_COORD, p, joueurProche.position.X, joueurProche.position.Y, joueurProche.position.Z, 1.0, 60, 0);
    Can you confirm that joueurProche is a Client object?
     
  14. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    Code:
    List<Client> nearC = API.getAllPlayers();
                float dist = 9999;
                Client joueurProche = nearC[0];
                string nom = " ";
                Vector3 pos = new Vector3();
                Vector3 zpos = API.getEntityPosition(p);
                foreach(Client player in nearC)
                {
                    if(API.getEntitySyncedData(p, "enPartie")==API.getEntitySyncedData(player, "enPartie") && API.getEntitySyncedData(player, "estMort")==0)
                    {
                        pos=API.getEntityPosition(player);
                        if(pos.DistanceTo(zpos)<dist)
                        {
                            dist=pos.DistanceTo(zpos);
                            joueurProche=player;
                            nom=player.name;
                        }
                    }
                }
     
  15. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Okay, let's do it differently. I think it may be a GTA:N limitation and maybe Ped position is not synced once it moves.
    But we need to confirm that. Can you make a command that finds the nearest Ped (the one that moves) and check his position at the time command is launched?

    Inside this method just do this:
    Code:
        [Command("pedpos")]
        public void FindClosestPedPos(Client player)
        {
         NetHandle ped = // Insert the closest ped here //
    
            Vector3 pos = API.getEntityPosition(ped);
            player.sendChatMessage(pos.ToString());
         }
    Do it with the previous native.
     
  16. Leonardo_Gonzalez

    Leonardo_Gonzalez Member

    Messages:
    45
    Likes Received:
    0
    Joined:
    Apr 5, 2017
    Yes, i think the position is not synced too, but i don't really know how to sync positions :/
     

Share This Page