Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | None | 0 0
  1. local screenW, screenH = guiGetScreenSize()
  2. local resW, resH = 1360,768
  3. local x, y = (screenW/resW), (screenH/resH)
  4. font = dxCreateFont("helvetica.ttf", 20)
  5.  
  6. playerData = {
  7.     selectedElement = {}
  8. }
  9.  
  10. Interaction = {}
  11.  
  12.  
  13. Interaction.Show = function(element)
  14.     selectedElement = element
  15.     addEventHandler ("onClientRender", root, dxPainel_a)
  16. end
  17.  
  18.  
  19.     function dxPainel_a()
  20.         local ID = getElementData(selectedElement, "ID") or "N/A"
  21.  
  22.         local px, py, pz = getElementPosition(localPlayer)
  23.         local ex, ey, ez = getElementPosition(selectedElement)
  24.         if getDistanceBetweenPoints3D(px, py, pz, ex, ey, ez) > getElementRadius(selectedElement) * 2 then
  25.             removeEventHandler("onClientRender", root, dxPainel_a)
  26.             return
  27.         end
  28.  
  29.         dxDrawRectangle(x*804, y*352, x*133, y*193, tocolor(0, 0, 0, 148), false)
  30.         dxDrawRectangle(x*804, y*352, x*133, y*21, tocolor(81, 202, 21, 254), false)
  31.         dxDrawText("Painel policial - ("..ID..")", x*811, y*357, x*927, y*369, tocolor(255, 255, 255, 255), x*0.33, font, "left", "top", false, false, false, false, false)
  32.         if cursorPosition(x*829, y*388, x*81, y*23) then
  33.         dxDrawRectangle(x*829, y*388, x*81, y*23, tocolor(81, 202, 21, 214), false)
  34.         else
  35.         dxDrawRectangle(x*829, y*388, x*81, y*23, tocolor(0, 0, 0, 214), false)
  36.         end
  37.     if cursorPosition(x*829, y*426, x*81, y*23) then
  38.         dxDrawRectangle(x*829, y*426, x*81, y*23, tocolor(81, 202, 21, 214), false)
  39.     else
  40.         dxDrawRectangle(x*829, y*426, x*81, y*23, tocolor(0, 0, 0, 214), false)
  41.     end
  42.     if cursorPosition(x*829, y*426+38, x*81, y*23) then
  43.         dxDrawRectangle(x*829, y*426+38, x*81, y*23, tocolor(81, 202, 21, 214), false)
  44. else
  45.         dxDrawRectangle(x*829, y*426+38, x*81, y*23, tocolor(0, 0, 0, 214), false)
  46.     end
  47.     if cursorPosition(x*829, y*426+38*2, x*81, y*23) then
  48.         dxDrawRectangle(x*829, y*426+38*2, x*81, y*23, tocolor(81, 202, 21, 214), false)
  49. else
  50.         dxDrawRectangle(x*829, y*426+38*2, x*81, y*23, tocolor(0, 0, 0, 214), false)
  51.     end
  52.         dxDrawText("Algemar", x*848, y*394, x*964, y*406, tocolor(255, 255, 255, 255), x*0.35, font, "left", "top", false, false, false, false, false)
  53.         dxDrawText("Carregar", x*848, y*431, x*964, y*443, tocolor(255, 255, 255, 255), x*0.35, font, "left", "top", false, false, false, false, false)
  54.         dxDrawText("Revistar", x*848, y*431+38, x*964, y*443, tocolor(255, 255, 255, 255), x*0.35, font, "left", "top", false, false, false, false, false)
  55.         dxDrawText("Fechar", x*848, y*431+38*2, x*964, y*443, tocolor(255, 255, 255, 255), x*0.35, font, "left", "top", false, false, false, false, false)
  56.     end
  57.  
  58.  
  59. addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
  60.     if button == "right" and state == "down" then
  61.         if isElement(clickedElement) then
  62.             if clickedElement ~= localPlayer then
  63.                 if  getElementType(clickedElement) == "player" then
  64.                     selectedElement = clickedElement
  65.                     playerData.selectedElement[localPlayer] = clickedElement
  66.                     if isEventHandlerAdded("onClientRender", getRootElement(), dxPainel_a) then  
  67.                        
  68.                         removeEventHandler("onClientRender", root, dxPainel_a)
  69.                     else                    
  70.                         Interaction.Show(clickedElement)
  71.                     end
  72.                 end
  73.             end
  74.         end
  75.     end
  76. end)
  77.  
  78. function botoesDx (_,state)
  79.     if button == "left" and state == "down" then
  80.         if isEventHandlerAdded("onClientRender", root, dxPainel_a) then  
  81.             if cursorPosition(x*848, y*431+38*2, x*964, y*443) then -- fechar
  82.                 removeEventHandler("onClientRender", root, dxPainel_a)
  83.                 effectOn = false
  84.             elseif cursorPosition(x*829, y*388, x*81, y*23) then -- algemar
  85.                 triggerServerEvent("algemar_A", localPlayer, selectedElement)
  86.             end
  87.         end
  88.     end
  89. end
  90. addEventHandler("onClientClick", root, botoesDx)
  91.  
  92. function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
  93.     if
  94.         type( sEventName ) == 'string' and
  95.         isElement( pElementAttachedTo ) and
  96.         type( func ) == 'function'
  97.     then
  98.         local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
  99.         if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
  100.             for i, v in ipairs( aAttachedFunctions ) do
  101.                 if v == func then
  102.                     return true
  103.                 end
  104.             end
  105.         end
  106.     end
  107.  
  108.     return false
  109. end
  110.  
  111. function cursorPosition(x, y, w, h)
  112.     if (not isCursorShowing()) then
  113.         return false
  114.     end
  115.     local mx, my = getCursorPosition()
  116.     local fullx, fully = guiGetScreenSize()
  117.     cursorx, cursory = mx*fullx, my*fully
  118.     if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
  119.         return true
  120.     else
  121.         return false
  122.     end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement