Get the location from selected player

Hello,

I am trying to make a command (/getloc <player_id>) that will set a GPS marker at the player’ location on MY map.

Right now I tried multiple things, searched around the forums, but did not get it working.

Only got my own location, or got the location of another player but the marker was set on his map (not mine).

What I tried, simplified:

local ped = GetPlayerPed(GetPlayerFromServerId(playerid))
local pos = GetEntityCoords(ped, true)

SetNewWaypoint(pos.x, pos.y)

Any help would be awesome!

Regards.

1 Like
RegisterCommand("getloc", function(source, args, rawCommand)
    playerid = tonumber(args[1]) -- define playerid as the first argument
    local ped = GetPlayerPed(playerid) -- get the ped of the playerid
    local pos = GetEntityCoords(ped, true) -- get the coords of the ped
    Citizen.CreateThread(function()
        SetNewWaypoint(pos.x, pos.y) -- set the waypoint to the x and y position of the ped
        TriggerEvent('chatMessage', '', {255, 255, 255}, 'Waypoint has been set to player ID ' .. playerid)
    end)
end, false) -- set this to false to allow anyone

Note that this will only set the waypoint statically, and it will not follow the player. (and it may not work cause I can’t check lol)

how would i sent the waypoint to only one player?
when I have a client script, that runs trough a console command, it gives the waypoint to all players.

1 Like

When you TriggerClientEvent use source instead of -1

and for source the player id of the player that needs to recieve it?

1 Like

Where would I put this?

This doesnt work, it just sets a random waypoint not a waypoint to the players location :frowning:

Try this…

RegisterCommand("getloc", function(source, args, rawCommand)
    local player = GetPlayerFromServerId(args[1]) 
    local ped = GetPlayerPed(player) 
    local pos = GetEntityCoords(ped, true) 
    SetNewWaypoint(pos.x, pos.y)
    TriggerEvent('chatMessage', '', {255, 255, 255}, 'Waypoint has been set to player ID ' .. args[1])
end)

Hey Ill try this out and let you know thanks for updating it. Your awesome!

This also doesnt work now the waypoint doesnt get set at all.

This has to be put in a client script, not quite sure if you’re doing that. Works fine on my end.

Have you tested it on another player I have dropped it into client side, set the waypoint for a second and the way point is on me not the player whos Id I have specified.

Maybe send me a script with it in it? that you have working?

Use this inside registercommand, this must show a blip player in map:

         playerCoords = GetEntityCoords(GetPlayerPed(args[1]), true)
	 coordsX= playerCoords.x
	 coordsY= playerCoords.y
	 coordsZ= playerCoords.z
markBlip=AddBlipForCoord(coordsX,coordsY,coordsZ)
--add type of marker that you want
markerType=128
while true do
 Citizen.Wait(0)
    SetBlipSprite(markBlip, markBlipType)
end

Hope this works, regards.

I will test if this work and let you know. But my guess since you never got an answer that it worked xD

1 Like

Bit late to the party, but I’ve tried this, doesnt seem to work. It will always set a marker to the own player. Iam also not sure if I got the correct ID’s. Reading them from Vmenu, and will be in the order people joined. so /getloc 1 (anything lower than 10 tested with 2 players in the server) will set a waypoint to the own pet