GetEntityCoords Not Working

Hello,

I’m a bit puzzled why this doesn’t work as I expected. I use a similar eventhandler for another sound that works.

So what it does is GetPlayerPed(-1) occurs in a client script, passes it to a server event which then sends that target out to all clients. This client script below then checks the position of the player and the target player and compares them to decide if a sound should play etc…

Now, this works if the player who initiates the initial client event is the client running this eventhandler (that is the player and the coordinates are the same). However, if the player running the client isn’t who originally ran it the coordinates are 0,0,0. This made me believe the variable ‘target’ is not the player id… but it is.

Now using print to see in the console when running it myself TARGET ID and YOUR ID are the same - eg 1234. If another player runs it the target ID passed is 5678 as an example. I print this on the player who runs it and they confirm this is the same value. So why is GetEntityCoords(target) returning 0,0,0 if the value of the player is correct?

RegisterNetEvent('Client:TaserDraw')
AddEventHandler('Client:TaserDraw', function(target)
    local coords = GetEntityCoords(GetPlayerPed(-1))
    local coords2 = GetEntityCoords(target)
	print('TARGET ID: ' .. target .. ' | YOUR ID: ' .. GetPlayerPed(-1))
	print('coords X: '..coords.x .. ' Y: '.. coords.y ..' Z: ' .. coords.z)
	print('coords2 X: '..coords2.x .. ' Y: '.. coords2.y ..' Z: ' .. coords2.z)
    local dist  = Vdist(coords.x, coords.y, coords.z, coords2.x, coords2.y, coords2.z)
    local soundVolume = 0.0
    print(dist)
    if(dist <= 5) then
        soundVolume = (1-(dist/5))*0.2
        SendNUIMessage({
            transactionType     = 'taserDraw',
            transactionVolume   = soundVolume
        })
    end
end)

This in essence prints in console;

For when it works…

But this doesn’t work

Why does my own value work in GetEntityCoords, but not that of another player… but it works for them?

1 Like

Would be better to send other clients your player source

Then call GetPlayerFromServerId(source) and use the output of that in GetPlayerPed and then you can get the coords of the other playerped

1 Like

Not sure why I didn’t think of that. Works! :slight_smile:

1 Like