Get the location from selected player




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!


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
        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, 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.


When you TriggerClientEvent use source instead of -1


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