Infra_

Untitled

May 28th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. -- Example usage:
  2. addEventHandler("onClientResourceStart", root, function()
  3.     create3DText("Test", 705.83, -159.25, 32.01, "arial", 1.0, 255, 255, 255, 255, 200, true)
  4.     create3DText("Test String but below the other one", 705.83, -159.25, 25.01, "bankgothic", 2.0, 255, 255, 255, 255, 200, true)
  5.     -- Arguments:       text,                               X,     Y,       Z,      font,    size,  r,   g,   b,   a,   d,  testlos
  6. end)
  7.  
  8.  
  9.  
  10. local texts = {}
  11. function create3DText(string, x, y, z, font, fontsize, r, g, b, a, distance, testlos)
  12.     local text      =   {}
  13.     text.string     =   string
  14.     text.x          =   x
  15.     text.y          =   y
  16.     text.z          =   z
  17.     text.font       =   font or "arial"
  18.     text.fontsize   =   fontsize or 1.0
  19.     text.r          =   r or 255
  20.     text.g          =   g or 255
  21.     text.b          =   b or 255
  22.     text.a          =   a or 255
  23.     text.distance   =   distance or 150
  24.     text.testlos    =   (type(testlos) == "nil" and false or testlos)
  25.     table.insert(texts, text)
  26. end
  27.  
  28. addEventHandler("onClientRender", root, function()
  29.     for i, value in ipairs(texts) do
  30.         local self = texts[i]
  31.         local x, y, z = getElementPosition(getLocalPlayer())
  32.         local distance = getDistanceBetweenPoints3D(self.x, self.y, self.z, x, y, z)
  33.         if distance <= self.distance then
  34.             local cx, cy, cz, clx, cly, clz = getCameraMatrix()
  35.             if not self.testlos or (self.testlos and isLineOfSightClear(cx, cy, cz, self.x, self.y, self.z, true, false, true, true, false, false, true)) then
  36.                 local scale = self.fontsize - ((distance / self.distance) * self.fontsize)
  37.                 local sx, sy = getScreenFromWorldPosition(self.x, self.y, self.z, dxGetTextWidth(self.string, scale, self.font, true), false)
  38.                 if sx and sy then
  39.                     dxDrawText(self.string, sx, sy, _, _, tocolor(self.r, self.g, self.b, self.a), scale, self.font, "center", "center", false, false, false, true)
  40.                 end
  41.             end
  42.         end
  43.     end
  44. end)
Advertisement
Add Comment
Please, Sign In to add comment