Server sided player coords

I want to get the players coords but after following this
it gave me vector(0, 0, 0) any fix for this?

There is nothing to fix, as that native states, it returns a vector3

local retval --[[ vector3 ]] =
	GetEntityCoords(
		entity --[[ Entity ]]
	)

A vector3 holds 3 types of data in a 3d space, so e.g. this vector3’s data is the x, y, and z coords. So, to reference it, it would be something like this.

local coords = GetEntityCoords(PlayerPedId(), false)
print("X Coord: " .. tostring(coords.x))

I think he means there is an issue as it returns 0,0,0 as the vector and not the actual coords of the ped.

yes exactly

no it returns the vectors 0, 0, 0 not the actual values

This has been reported as a bug in the past. Please try to document a step by step reproduction so we can figure out exactly what is causing this issue, as it doesn’t occur all the time.

Oh I see, my mistake lol. Can you provide us with the code and what entity you are passing, have you tried printing the entity to determine if it’s not 0 or using DoesEntityExist - FiveM Natives @ Cfx.re Docs

here is my code:

local src = source
local ped = GetPlayerPed(src)
print(DoesEntityExist(ped))
local playerCoords = GetEntityCoords(ped)
print(playerCoords)

and so the problem is that it doesn’t get the players ped…
because print(DoesEntityExist(ped)) came back as false

so… just found out that you can only get player coords server sided when onesync is enabled

:frowning:

How [quote=“Tazio, post:9, topic:1179685”]
so… just found out that you can only get player coords server sided when onesync is enabled
[/quote]

Why are you trying to get them server sided and I believe onesync is free for 32 slots.

So currently im working on a report system and when you click a certain button it redirects you to the latest report from the user that is reported

So use tables and send them over to your client, compare the player license from the /report and the one in the table, if they match, grab their coords and set a waypoint to those x and y coords.

1 Like

ur a smart guy thanks for the tip

No worries, something like that would be rather simple, if you understand Lua syntax and basic programming.

Even if you understand basic programming the concept can escape you if you’re in a tunnel or reading the manual incorrectly (I’ve done it several times).

Rubber Duck Debugging ftw!

It’s a good way to protect events from being triggered in the wrong location. And you should never trust what the client tells you. The more things server side the better.

Yes I am aware of the that, however there is no point in getting the coords on the sv, if he needs to set a waypoint which needs to be done on the client. No point in implementing data validation for those two lines.

i still need to get the coordinations from the report from the server side so it would be better to have it all server sided

I disagree there is plenty of reasons for validating player coords. but if you dont see the need for yourself that’s fine. My examples aren’t about setting waypoints but rather validating that the user is actually at the place where they say they are. This is important for validating if an event has been triggered in its actual location and not by some lua injector.

1 Like