Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. ```lua
  2. local playerInfo = {}
  3.  
  4. --Create a new index into player info about the player.
  5. function PopulatePlayerInfo(index)
  6.     if NetworkIsPlayerActive(id) and GetPlayerPed(i) ~= PlayerPedId() then
  7.         local serverId = GetPlayerServerId(i)
  8.         local player = GetPlayerFromServerId(serverId)
  9.         playerInfo[i] = {
  10.             pid = i,
  11.             sid = serverId,
  12.             ped = GetPlayerPed(player),
  13.             blip = -1
  14.         }
  15.     end
  16. end
  17.  
  18. Citizen.CreateThread(function()
  19.     local slots = GetConvarInt('sv_maxclients', 32)
  20.     while true do
  21.         for i = 0, slots do
  22.  
  23.             -- Wew, we found a new player.
  24.             if playerInfo == nil then
  25.                 PopulatePlayerInfo(i)
  26.             end
  27.  
  28.             -- If the server ID differs, then the slot got reassigned probably.
  29.             if playerInfo[i].sid != GetPlayerServerId(i) then
  30.                 PopulatePlayerInfo(i)
  31.             end
  32.         end
  33.  
  34.         -- Do update thingies.
  35.         UpdateRadar()
  36.         Citizen.Wait(1000)
  37.     end
  38. end)
  39.  
  40. function UpdateRadar()
  41.     if RadarEnabled then
  42.         for i=1, #playerInfo, 1 do
  43.             local player = playerInfo[i]
  44.            
  45.             -- Get the distance between player and target.
  46.             local playerCoords = GetEntityCoords(PlayerPedId())
  47.             local targetCoords = GetEntityCoords(player.ped)
  48.             local distance = Abs(#(playerCoords - targetCoords))
  49.  
  50.             if distance < 200 then
  51.                 -- We don't have a blip yet, create one.
  52.                 if player.blip == -1 then
  53.                     local blipId = createBlip(serverId);
  54.                     player.blip = blipId
  55.                     playerInfo[i] = player
  56.                 else
  57.                     SetBlipCoords(player.blip, targetCoords)
  58.                 end
  59.             else
  60.                 -- Out of reach, remove the blip.
  61.                 RemoveBlip(player.blip)
  62.                 player.blip = -1
  63.                 playerInfo[i] = player
  64.             end
  65.         end
  66.     end  
  67.  
  68.     Citizen.Wait(100)
  69. end
  70. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement