Advertisement
ProToTN

MTA getNearestGarage Script

Jan 21st, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. function getNearestGarageFromElement (element)
  2.   nearestID = -1
  3.   nearestDistance = 999999999999
  4.   local ex,ey,ez = getElementPosition (element)
  5.   for i=0,49 do
  6.     local x,y,z = getGaragePosition (i)
  7.     if (getDistanceBetweenPoints3D (ex,ey,ez,x,y,z) < nearestDistance) then
  8.       nearestID = i
  9.       nearestDistance = getDistanceBetweenPoints3D (ex,ey,ez,x,y,z)
  10.     end
  11.   end
  12.   local _nearestID = nearestID
  13.   nearestID = nil
  14.   return _nearestID
  15. end
  16.  
  17. addCommandHandler ("findgarage",
  18. function(command)
  19.   local garageID = getNearestGarageFromElement (getLocalPlayer())
  20.   if (garageID ~= -1) then
  21.     local x,y,z = getGaragePosition (garageID)
  22.     local garageBlip = createBlip (x,y,z,41)
  23.     outputChatBox(garageID)
  24.     setTimer (
  25.       function (garageBlip)
  26.         destroyElement (garageBlip)
  27.       end
  28.     ,10000,1,garageBlip)
  29.   end
  30. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement