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.
Hey, there you have a solution for your problem: Code: [Command("pos")] public void Position(Client player) { Vector3 pos = API.getEntityPosition(player); API.sendChatMessageToPlayer(player, "X: " + pos.X + " Y: " + pos.Y + " Z: " + pos.Z); } Some useful threads: https://wiki.gtanet.work/index.php?title=getEntityPosition https://wiki.gtanet.work/index.php?title=setEntityPosition
" getEntityFromHandle 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
Ignore the note, getEntityFromHandle is working. doormanager is using it ... The position doesn't change? Maybe a GTA:Network bug?
I don't find getEntityFromHandle in doormanager, Yes the position doesn't change but the ped moves :/
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?
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
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?
yes, i have this before : Code: List<NetHandle> peds = API.getAllPeds(); foreach(NetHandle p in peds) {
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.
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?
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; } } }
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.