Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.91 KB | None | 0 0
  1. local LabelID = {}
  2. LabelAll = 0
  3.  
  4. function create3DTextLabel(player, text, color, x, y, z, dis, dimens, font, size) --def 150
  5.     if not text then return false end
  6.     if not color then color = tocolor(255, 255, 255, 255) end
  7.     if not x or x == "x" then x = getElementPosition(localPlayer) end
  8.     if not y or y == "x" then _, y = getElementPosition(localPlayer) end
  9.     if not z or z == "x" then _, _, z = getElementPosition(localPlayer) end
  10.     if not dis or not tonumber(dis) then dis = 150 end
  11.     if not dimens or not tonumber(dimens) then dimens = -1 end
  12.     if not font then font = "default-bold" end
  13.     if not size or not tonumber(size) or tonumber(size) <= 0 then size = 1 end
  14.    
  15.     --LabelAll = id
  16.     LabelAll = LabelAll + 1      
  17.    
  18.     color = string.format("%x", color)
  19.     local alpha = string.sub(color, 1, 2)
  20.     color = "0x"..color
  21.    
  22.     LabelID[LabelAll] = {}
  23.     LabelID[LabelAll]["PosX"] = tonumber(x)
  24.     LabelID[LabelAll]["PosY"] = tonumber(y)
  25.     LabelID[LabelAll]["PosZ"] = tonumber(z)
  26.     LabelID[LabelAll]["Text"] = text
  27.     LabelID[LabelAll]["Dist"] = tonumber(dis)
  28.     LabelID[LabelAll]["Colr"] = tonumber(color)
  29.     LabelID[LabelAll]["Alph"] = tostring(alpha)
  30.     LabelID[LabelAll]["Enbl"] = true
  31.     LabelID[LabelAll]["Dimn"] = tonumber(dimens)
  32.     LabelID[LabelAll]["BDim"] = false
  33.     LabelID[LabelAll]["Attc"] = false
  34.     LabelID[LabelAll]["AttX"] = 0
  35.     LabelID[LabelAll]["AttY"] = 0
  36.     LabelID[LabelAll]["AttZ"] = 0
  37.     LabelID[LabelAll]["Font"] = font
  38.     LabelID[LabelAll]["Size"] = tonumber(size)
  39.    
  40.     if LabelID[LabelAll]["Dimn"] and LabelID[LabelAll]["Dimn"] >= 0 then LabelID[LabelAll]["BDim"] = true end
  41.    
  42.     showLabel(player, LabelAll)    
  43.    
  44.     return LabelAll
  45. end
  46. function delete3DTextLabel(id)
  47.     if not LabelID[id] then return false end
  48.     LabelID[id]["Enbl"] = false
  49. end
  50. function update3DTextLabel(id, text, color, x, y, z, dist, dimens, font, size)
  51.     if not LabelID[id] then return false end
  52.     if not text then return false end
  53.     if not color then color = LabelID[id]["Colr"] end
  54.     if not x or not tonumber(x) then x = LabelID[id]["PosX"] end
  55.     if not y or not tonumber(y) then y = LabelID[id]["PosY"] end
  56.     if not z or not tonumber(z) then z = LabelID[id]["PosZ"] end
  57.     if not dist or not tonumber(dist) then dist = LabelID[id]["Dist"] end
  58.     if not dimens or not tonumber(dimens) then dimens = LabelID[LabelAll]["Dimn"] end
  59.     if not font then font = LabelID[id]["Font"] end
  60.     if not size or not tonumber(size) or tonumber(size) <= 0 then size = LabelID[LabelAll]["Size"] end
  61.    
  62.     color = string.format("%x", color)
  63.     local alpha = string.sub(color, 1, 2)
  64.     color = "0x"..color
  65.    
  66.     LabelID[id]["Text"] = text
  67.     LabelID[id]["Colr"] = tonumber(color)
  68.     LabelID[id]["Alph"] = tostring(alpha)
  69.     LabelID[id]["PosX"] = x
  70.     LabelID[id]["PosY"] = y
  71.     LabelID[id]["PosZ"] = z
  72.     LabelID[id]["Dist"] = tonumber(dist)
  73.     LabelID[id]["Dimn"] = tonumber(dimens)
  74.     LabelID[id]["BDim"] = false
  75.     LabelID[id]["Font"] = font
  76.     LabelID[id]["Size"] = tonumber(size)
  77.     if LabelID[id]["Dimn"] and LabelID[id]["Dimn"] >= 0 then LabelID[id]["BDim"] = true end
  78. end
  79.  
  80. function attach3DTextLabelToElement(id, element, x, y, z, dimens)
  81.     if not LabelID[id] then return false end
  82.     if not isElement(element) then return false end
  83.     if not x or not tonumber(x) then x = 0 end
  84.     if not y or not tonumber(y) then y = 0 end
  85.     if not z or not tonumber(z) then z = 0 end
  86.     if not dimens or not tonumber(dimens) then dimens = -1 end
  87.     LabelID[id]["Attc"] = element
  88.     LabelID[id]["AttX"] = tonumber(x)
  89.     LabelID[id]["AttY"] = tonumber(y)
  90.     LabelID[id]["AttZ"] = tonumber(z)
  91.     LabelID[id]["Dimn"] = tonumber(dimens)
  92.     LabelID[id]["BDim"] = false
  93.     if LabelID[id]["Dimn"] and LabelID[id]["Dimn"] >= 0 then LabelID[id]["BDim"] = true end
  94. end
  95.  
  96. function detach3DTextLabel(id)
  97.     if not LabelID[id] then return false end
  98.     LabelID[id]["Attc"] = false
  99. end
  100.    
  101. function labelFunction(player, id, x, y, z, text, dis, color, alpha, font, size)
  102.     if not LabelID[id] then return nil end
  103.  
  104.     local NewX,NewY,NewZ = getElementPosition(localPlayer)
  105.     local distance = getDistanceBetweenPoints3D(x,y,z,NewX,NewY,NewZ)
  106.     if distance <= dis then
  107.         local ScX,ScY = getScreenFromWorldPosition(x, y, z+0.95, 0.06)
  108.         if not ScX then return end
  109.         local sz = math.min(0.3*(dis/distance)*1.4*size,size)
  110.         dxDrawText(text:gsub("#%x%x%x%x%x%x", ""), ScX+1, ScY-30+1, ScX+1, ScY-30+1, tonumber("0x"..alpha.."000000"), sz, font, "center", "bottom", false, false, false)
  111.         dxDrawText(text:gsub("#%x%x%x%x%x%x", ""), ScX-1, ScY-30+1, ScX-1, ScY-30+1, tonumber("0x"..alpha.."000000"), sz, font, "center", "bottom", false, false, false)
  112.         dxDrawText(text:gsub("#%x%x%x%x%x%x", ""), ScX+1, ScY-30-1, ScX+1, ScY-30-1, tonumber("0x"..alpha.."000000"), sz, font, "center", "bottom", false, false, false)
  113.         dxDrawText(text:gsub("#%x%x%x%x%x%x", ""), ScX-1, ScY-30-1, ScX-1, ScY-30-1, tonumber("0x"..alpha.."000000"), sz, font, "center", "bottom", false, false, false)
  114.         dxDrawText(text, ScX, ScY-30, ScX, ScY-30, color, sz, font, "center", "bottom", false, false, false, true)
  115.  
  116.         local health = getElementHealth(player)
  117.         if health > 100 then health = 100 end
  118.         dxDrawImage(ScX-(36*sz), ScY-27, 72*sz, 9*sz, 'pane.png', 0, 0, 0, tocolor(0, 0, 0, 255))
  119.         dxDrawImage(ScX-(35*sz), ScY-26, 70*sz*(health/100), 7*sz, 'pane.png', 0, 0, 0, tocolor(160, 0, 0, 255))
  120.  
  121.         local armo = getPedArmor(player)
  122.         if armo > 100 then armo = 100 end
  123.         if armo > 0 then
  124.             dxDrawImage(ScX-(36*sz), ScY-(27-((9*sz)+1)), 72*sz, 9*sz, 'pane.png', 0, 0, 0, tocolor(0, 0, 0, 255))
  125.             dxDrawImage(ScX-(35*sz), ScY-(26-((9*sz)+1)), 70*sz*(armo/100), 7*sz, 'pane.png', 0, 0, 0, tocolor(160, 160, 160, 255))
  126.         end
  127.     end
  128. end
  129.  
  130. function showLabel(player, id)
  131.     if not LabelID[id] then return nil end
  132.     addEventHandler("onClientRender",getRootElement(),
  133.         function()
  134.             if LabelID[id]["BDim"] then if getElementDimension(localPlayer) ~= LabelID[id]["Dimn"] then return 1; end end
  135.             if not LabelID[id]["Enbl"] then cancelEvent() return 1; end
  136.             if LabelID[id]["Attc"] ~= false then
  137.                 if not isElement(LabelID[id]["Attc"]) then LabelID[id]["Attc"] = false return 1; end
  138.                 local nx, ny, nz = getElementPosition(LabelID[id]["Attc"])
  139.                 LabelID[id]["PosX"] = nx+LabelID[id]["AttX"]
  140.                 LabelID[id]["PosY"] = ny+LabelID[id]["AttY"]
  141.                 LabelID[id]["PosZ"] = nz+LabelID[id]["AttZ"]
  142.             end
  143.             labelFunction(player, id, LabelID[id]["PosX"], LabelID[id]["PosY"], LabelID[id]["PosZ"], LabelID[id]["Text"], LabelID[id]["Dist"], LabelID[id]["Colr"], LabelID[id]["Alph"], LabelID[id]["Font"], LabelID[id]["Size"])
  144.         end)
  145. end
  146.  
  147. --[[addEventHandler("onClientResourceStart", root,
  148.     function()
  149.         label = create3DTextLabel("Lost", 0xFFFFFF00, 0, 0, 10, 700, 0)
  150.         labels = create3DTextLabel("test", 0xFFFFF000, 0, 0, 15, 700, 0)
  151.         labelz = create3DTextLabel("Fest", 0xFFFFF000, 0, 0, 20, 700, 0)
  152.         attach3DTextLabelToElement(label, localPlayer or getPedOccupiedVehicle(localPlayer))
  153.         setTimer(function()
  154.             local vx, vy, vz = getElementPosition(localPlayer or getPedOccupiedVehicle(localPlayer))
  155.             update3DTextLabel(label, "#FF0000X: #FFFFFF"..string.format("%.4f", vx).."\n#FF0000Y: #FFFFFF"..string.format("%.4f", vy).."\n#FF0000Z: #FFFFFF"..string.format("%.4f", vz))
  156.         end, 50, 1000)
  157.         setTimer(function()
  158.             detach3DTextLabel(label)
  159.         end, 52*1000, 1)
  160.         end)]]
  161.  
  162. local clabel = {}
  163. addEventHandler("onClientPlayerJoin", root, function()
  164.  
  165.     setPlayerNametagShowing(source, false)
  166.  
  167.     local r, g, b = getPlayerNametagColor(source)
  168.     outputChatBox(getPlayerName(source).." #FFFFFFприсоединился к нам на сервер.", r, g, b, true)
  169.  
  170.     if source ~= localPlayer then
  171.         local r, g, b = getPlayerNametagColor(source)
  172.         clabel[source] = create3DTextLabel(source, string.format("#%2x%2x%2x", r, g, b)..getPlayerName(source), tocolor(255, 255, 255, 255), 0, 0, 0, 100, -1, "default-bold", 1)
  173.         attach3DTextLabelToElement(clabel[source], source, 0, 0, 0, 0)
  174.     else
  175.         for _, v in ipairs(getElementsByType("player")) do
  176.             if v == localPlayer then return false end
  177.             local r, g, b = getPlayerNametagColor(v)
  178.             clabel[v] = create3DTextLabel(v, string.format("#%2x%2x%2x", r, g, b)..getPlayerName(v), tocolor(255, 255, 255, 255), 0, 0, 0, 100, -1, "default-bold", 1)
  179.             attach3DTextLabelToElement(clabel[v], v, 0, 0, 0, 0)
  180.         end
  181.     end
  182. end)
  183.  
  184. addEventHandler("onClientResourceStart", root, function(res)
  185.     if res ~= getThisResource() then return false end
  186.     for _, v in ipairs(getElementsByType("player")) do
  187.         setPlayerNametagShowing(v, false)
  188.         if v == localPlayer then return false end
  189.         local r, g, b = getPlayerNametagColor(v)
  190.         clabel[v] = create3DTextLabel(v, string.format("#%2x%2x%2x", r, g, b)..getPlayerName(v), tocolor(255, 255, 255, 255), 0, 0, 0, 100, -1, "default-bold", 1)
  191.         attach3DTextLabelToElement(clabel[v], v, 0, 0, 0, 0)
  192.     end
  193. end)
  194. addEventHandler("onClientResourceStop", root, function(res)
  195.     if res ~= getThisResource() then return false end
  196.     for _, v in ipairs(getElementsByType("player")) do
  197.         setPlayerNametagShowing(v, true)
  198.     end
  199. end)
  200.  
  201. addEventHandler("onClientPlayerChangeNick", root, function(old, new)  
  202.     local r, g, b = getPlayerNametagColor(source)
  203.     outputChatBox(old.." #FFFFFFпоменял свой ник на "..string.format("#%2x%2x%2x", r, g, b)..new.."#FFFFFF.", r, g, b, true)
  204.  
  205.     for _, v in ipairs(getElementsByType("player")) do
  206.         if v == localPlayer then return false end
  207.         clabel[v] = update3DTextLabel(v, string.format("#%2x%2x%2x", r, g, b)..getPlayerName(v), tocolor(255, 255, 255, 255), 0, 0, 0, 100, -1, "default-bold", 1)
  208.     end
  209. end)
  210.  
  211. addEventHandler("onClientPlayerQuit", root, function(reas)
  212.  
  213.     local r, g, b = getPlayerNametagColor(source)
  214.     local res = "#9933FFИстекло время ожидания"
  215.     if reas == "Quit" then res = "#00AA00Выход" end
  216.     if reas == "Banned" then res = "#FF0000Забанен" end
  217.     if reas == "Bad Connection" then res = "#FF9900Кикнут" end
  218.     if reas == "Kicked" then res = "##5555FFПотеря соединения" end
  219.  
  220.     outputChatBox(getPlayerName(source).." #FFFFFFпокинул сервер ["..res.."#FFFFFF].", r, g, b, true)
  221.  
  222.     if source ~= localPlayer then delete3DTextLabel(clabel[source]) end
  223. end)
  224.  
  225. --[[local x, y, z = getElementPosition(localPlayer)
  226. create3DTextLabel(localPlayer, getPlayerName(localPlayer), tocolor(255, 255, 255, 255), x, y, z, 100, -1, "default-bold", 1)]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement