Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1.  
  2. local sX, sY = guiGetScreenSize()
  3. --{"element neve", x, y}
  4. local changeSizeUse = false
  5. local dxFont = dxCreateFont("font.ttf",17)
  6.  
  7. _getCursorPosition = getCursorPosition
  8. function getCursorPosition()
  9.     cX, cY = _getCursorPosition()
  10.     cX, cY = cX*sX, cY*sY
  11.     return cX, cY
  12. end
  13.  
  14. function dobozbaVan(cx, cy, x, y, w, h)
  15.     if cx > x and cx < x+w and cy > y and cy < y+h then
  16.         return true
  17.     else
  18.         return false
  19.     end
  20. end
  21.  
  22. local counter = 0
  23. local starttick
  24. local currenttick
  25.  
  26. local showfps = false
  27.  
  28. function math.round(number, decimals, method)
  29.     decimals = decimals or 0
  30.     local factor = 10 ^ decimals
  31.     if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
  32.     else return tonumber(("%."..decimals.."f"):format(number)) end
  33. end
  34.  
  35.  
  36. addEventHandler ("onClientRender",root,
  37.     function()
  38.         if not starttick then
  39.             starttick = getTickCount ()
  40.         end
  41.         counter = counter + 1
  42.         currenttick = getTickCount ()
  43.         if currenttick - starttick >= 1000 then
  44.             setElementData (localPlayer, "FPS", counter)
  45.             counter = 0
  46.             starttick = false
  47.         end
  48.     end
  49. )
  50.  
  51. fpstable = {}
  52. function averageFPS()
  53.     avgseconds = 10
  54.     for i = 0, avgseconds do
  55.         if i+1 <= avgseconds then
  56.             fpstable[i+1] = fpstable[i]
  57.         end
  58.         fpstable[0] = getElementData (localPlayer, "FPS")
  59.     end
  60.     totalframes = 0
  61.     for k, v in pairs(fpstable) do
  62.         if v ~= false then
  63.             totalframes = totalframes + v
  64.         end
  65.     end
  66.     avgfps = math.round(totalframes / avgseconds, 0)
  67.     setElementData (localPlayer, "avgfps", avgfps)
  68. end
  69.  
  70. setTimer (averageFPS, 1000, 0)
  71.  
  72. local stat = dxGetStatus ( )
  73. local szoveg = "#00A1FFVideókártya: #ffffff" .. stat["VideoCardName"] .."\n#00A1FFRam: #ffffff".. stat["VideoMemoryFreeForMTA"].."/".. stat["VideoCardRAM"]
  74. local szovegs = stat["VideoCardName"] .."\nVRAM ".. stat["VideoMemoryFreeForMTA"].."/".. stat["VideoCardRAM"]
  75. local hudElements = {{"showFPS", 10, 180, 310, 100}}
  76. addEventHandler("onClientRender", getRootElement(), function()
  77.     if showfps then
  78.     for i, k in ipairs(hudElements) do
  79.         local x, y, w, h, m, r, ru = getElementData(localPlayer, k[1] .. "X") or k[2], getElementData(localPlayer, k[1] .. "Y") or k[3], getElementData(localPlayer, k[1] .. "W") or k[4], getElementData(localPlayer, k[1] .. "H") or k[5], getElementData(localPlayer,k[1] .. "Moving") or false, getElementData(localPlayer, k[1] .. "Resize") or false, getElementData(localPlayer, k[1] .. "ResizeUse") or false
  80.         setElementData(localPlayer, k[1] .. "H", nil)]]
  81.         if k[1] == "showFPS" then
  82. getElementData(localPlayer,"FPS"),x,y,w,h,tocolor(0,0,0,255),1,dxFont,"left","top",true,true,true,true,true)
  83.             local fps = getElementData(localPlayer,"FPS")
  84.             if fps <= 100 then
  85.                 fpscolor = "#ffffff"
  86.             elseif fps < 100 and fps <= 30 then
  87.                 fpscolor = "#FFA700"
  88.             elseif fps < 30 then
  89.                 fpscolor = "#D75656"
  90.             end
  91.            
  92.             dxDrawText(szoveg .. fpscolor .." \n#00A1FFFPS: #FFFFFF" .. getElementData(localPlayer,"FPS"),x+1,y+1,w,h,tocolor(0,0,0,255),0.62,dxFont,"left","top",true,true,true,true,true)
  93.             if m then
  94.                 local cX, cY = getCursorPosition()
  95.  
  96.                 setElementData(localPlayer, k[1] .. "X", cX-defX)
  97.                 setElementData(localPlayer, k[1] .. "Y", cY-defY)
  98.             end
  99.         else
  100.             if m then
  101.                 local cX, cY = getCursorPosition()
  102.                 setElementData(localPlayer, k[1] .. "X", cX-defX)
  103.                 setElementData(localPlayer, k[1] .. "Y", cY-defY)
  104.             end
  105.         end
  106.     end
  107.     end
  108. end)
  109.  
  110. addEventHandler("onClientClick", getRootElement(), function(button, state, aX, aY, wX, wY, wZ, element)
  111.     if showfps then
  112.     if button == "left" then
  113.         if state == "down" then
  114.             for i, k in ipairs(hudElements) do
  115.                 local x, y, w, h, r = getElementData(localPlayer, k[1] .. "X") or k[2], getElementData(localPlayer, k[1] .. "Y") or k[3], getElementData(localPlayer, k[1] .. "W") or k[4], getElementData(localPlayer, k[1] .. "H") or k[5], getElementData(localPlayer, k[1] .. "Resize") or false
  116.                 local cX, cY = getCursorPosition()
  117.                 if dobozbaVan(cX, cY, x, y, w, h) then
  118.                     setElementData(localPlayer, k[1] .. "Moving", true)
  119.                     defX, defY = cX-x, cY-y
  120.                 end
  121.             end
  122.         elseif state == "up" then
  123.             for i, k in ipairs(hudElements) do
  124.                 local m, r = getElementData(localPlayer,k[1] .. "Moving") or false, getElementData(localPlayer, k[1] .. "Resize") or false
  125.                 if m then
  126.                     setElementData(localPlayer, k[1].. "Moving", false)
  127.                 end
  128.             end
  129.         end
  130.     end
  131.     end
  132. end)
  133.  
  134. function showFPSed()
  135.     if not showfps then
  136.         showfps = true
  137.     else
  138.         showfps = false
  139.     end
  140. end
  141. addCommandHandler("showfps",showFPSed)
  142.  
  143. addEventHandler("onClientResourceStart", resourceRoot, function()
  144.     local asd = jsonGET("fps_pos",false)
  145.     if asd[1] and asd[2] and asd[3] then
  146.         for v,k in ipairs(hudElements) do
  147.             if k[1] == "showFPS" then
  148.                 defX = tonumber(asd[1])
  149.                 defY = tonumber(asd[2])
  150.                 setElementData(localPlayer,k[1].. "X",defX)
  151.                 setElementData(localPlayer,k[1].. "Y",defY)
  152.                 setElementData(localPlayer,k[1].. "Moving",false)
  153.             --  showfps = asd[3]
  154.             end
  155.         end
  156.     end
  157. end)
  158.  
  159. function saveInventoryPosition()
  160.     for v,k in ipairs(hudElements) do
  161.         if k[1] == "showFPS" then
  162.             local x,y = getElementData(localPlayer, k[1] .. "X"), getElementData(localPlayer, k[1] .. "Y")
  163.             jsonSAVE("fps_pos", {x, y}, false)
  164.         end
  165.     end
  166. end
  167.  
  168. setTimer(function()
  169. saveInventoryPosition()
  170. end,1000,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement