RyanUSNS

SO Coords v1

Sep 7th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. local picking, testMarker, zDifference
  2. local markerInfo = {}
  3.  
  4. function pickPosition()
  5.     if (not picking or not isCursorShowing()) then
  6.         return false
  7.     end
  8.     local dumpx, dumpy, worldX, worldY, worldZ = getCursorPosition()
  9.     local px, py, pz = getCameraMatrix()
  10.     local hit, x, y, z, elementHit = processLineOfSight(px, py, pz, worldX, worldY, worldZ)
  11.     if (not hit) then
  12.         return false
  13.     end
  14.     z = z + zDifference
  15.     setElementPosition(testMarker, x, y, z)
  16.     local text = "X: " .. x .. ", Y: " .. y .. ", Z: " .. z
  17.     dxDrawText(text, 0, 0, 0, 0) -- debugging only
  18.     markerInfo = {}
  19.     markerInfo = {x, y, z}
  20. end
  21.  
  22. function increaseZ()
  23.     if (not picking) then
  24.         return false
  25.     end
  26.     zDifference = zDifference + 0.1
  27. end
  28.  
  29. function decreaseZ()
  30.     if (not picking) then
  31.         return false
  32.     end
  33.     zDifference = zDifference - 0.1
  34. end
  35.  
  36. function spawnMarker()
  37.     if (not picking or not isCursorShowing()) then
  38.         return false
  39.     end
  40.     local x, y, z = markerInfo[1], markerInfo[2], markerInfo[3]
  41.     local zone, city = getZoneName(x, y, z), getZoneName(x, y, z, true)
  42.     outputChatBox(x .. " " .. x .. " " .. z)
  43.     outputChatBox(zone .. ", " .. city)
  44.     toggleListening()
  45. end
  46.  
  47. function toggleListening()
  48.     picking = not picking
  49.     showCursor(picking)
  50.     if (picking) then
  51.         testMarker = createMarker(0, 0, 0, "cylinder", 2, 255, 167, 0)
  52.         removeEventHandler("onClientRender", root, pickPosition)
  53.         addEventHandler("onClientRender", root, pickPosition)
  54.         picking = true
  55.         zDifference = 0
  56.         bindKey("mouse1", "down", spawnMarker)
  57.         bindKey("pgup", "down", increaseZ)
  58.         bindKey("pgdn", "down", decreaseZ)
  59.         bindKey("num_8", "down", increaseZ)
  60.         bindKey("num_2", "down", decreaseZ)
  61.         return false
  62.     end
  63.     markerInfo = {}
  64.     destroyElement(testMarker)
  65.     testMarker = nil
  66.     unbindKey("pgup", "down", increaseZ)
  67.     unbindKey("pgdn", "down", decreaseZ)
  68.     unbindKey("num_8", "down", increaseZ)
  69.     unbindKey("num_2", "down", decreaseZ)
  70.     unbindKey("mouse1", "down", spawnMarker)
  71. end
  72. addCommandHandler("tc", toggleListening)
Advertisement
Add Comment
Please, Sign In to add comment