Advertisement
Enjl

nullifier.lua

Apr 21st, 2019
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. --nullifier.lua by Enjl
  2. --makes it so a range of priorities is not drawn in certain locations, tied to a BGO ID
  3. --Ver 1.0
  4.  
  5. local nullifier = {}
  6.  
  7. local registeredRanges = {}
  8.  
  9. --CHANGE THIS to change which BGO becomes a nullifier
  10. nullifier.id = 1
  11.  
  12. local tableinsert = table.insert
  13.  
  14. local cb = Graphics.CaptureBuffer(800, 600)
  15.  
  16. --CALL THIS to add a range of priorities which the nullifier should skip over
  17. function nullifier.addRange(min, max)
  18. if min > max then
  19. max, min = min, max
  20. end
  21. tableinsert(registeredRanges, {capturePriority = min, drawPriority = max})
  22. end
  23.  
  24. function nullifier.onInitAPI()
  25. registerEvent(nullifier, "onCameraDraw")
  26. registerEvent(nullifier, "onStart")
  27. end
  28.  
  29. function nullifier.onStart()
  30. if #BGO.get(nullifier.id) == 0 then
  31. unregisterEvent(nullifier, "onCameraDraw")
  32. end
  33. end
  34.  
  35. local function insertVertices(t, x1, y1, x2, y2)
  36. tableinsert(t, x1)
  37. tableinsert(t, y1)
  38. tableinsert(t, x2)
  39. tableinsert(t, y1)
  40. tableinsert(t, x1)
  41. tableinsert(t, y2)
  42. tableinsert(t, x2)
  43. tableinsert(t, y1)
  44. tableinsert(t, x1)
  45. tableinsert(t, y2)
  46. tableinsert(t, x2)
  47. tableinsert(t, y2)
  48. end
  49.  
  50. function nullifier.onCameraDraw(camIdx)
  51. local verts = {}
  52. local tex = {}
  53.  
  54. local cam = Camera.get()[camIdx]
  55.  
  56. local cx = cam.x
  57. local cy = cam.y
  58. local cw = cam.width
  59. local ch = cam.height
  60.  
  61. for k,v in ipairs(BGO.getIntersecting(cx, cy, cx + cw, cy + ch)) do
  62. if v.id == nullifier.id and not v.isHidden then
  63. local x = v.x - cx
  64. local y = v.y - cy
  65. local xw = x + v.width
  66. local yh = y + v.height
  67. insertVertices(verts, x,y,xw,yh)
  68. insertVertices(tex, x/cw,y/ch,xw/cw,yh/ch)
  69. end
  70. end
  71.  
  72. if #verts > 0 then
  73. for k,v in ipairs(registeredRanges) do
  74. cb:captureAt(v.capturePriority)
  75. Graphics.glDraw{
  76. vertexCoords = verts,
  77. textureCoords = tex,
  78. texture = cb,
  79. priority = v.drawPriority,
  80. primitive = Graphics.GL_TRIANGLES
  81. }
  82. end
  83. end
  84. end
  85.  
  86. return nullifier
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement