OneTallor

Untitled

Aug 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. -- // Afk System
  2. function Timer()
  3.     sec = sec + 1
  4.     setElementData(getLocalPlayer(),"Timer",sec)
  5. end
  6.  
  7. function secondsToTimeDesc( seconds )
  8.     if seconds then
  9.         local results = {}
  10.         local sec = ( seconds %60 )
  11.         local min = math.floor ( ( seconds % 3600 ) /60 )
  12.         local hou = math.floor ( ( seconds % 86400 ) /3600 )
  13.         local day = math.floor ( seconds /86400 )
  14.  
  15.        
  16.         if day > 0 and day < 10 then table.insert( results, day .. ( day == 1 and " day" or " days" ) )
  17.         elseif day > 0  then table.insert( results, day .. ( day == 1 and "" or "" ) ) end
  18.            
  19.         if hou >= 0 and hou < 10 then table.insert( results, "0"..hou .. ( hou == 1 and "" or "" ) )
  20.         elseif hou > 0  then table.insert( results, hou .. ( hou == 1 and "" or "" ) ) end
  21.        
  22.         if min >= 0 and min < 10 then table.insert( results, "0"..min .. ( min == 1 and "" or "" ) )
  23.         elseif min > 0  then table.insert( results, min .. ( hou == 1 and "" or "" ) ) end
  24.        
  25.         if sec >= 0 and sec < 10 then table.insert( results, "0"..sec .. ( sec == 1 and "" or "" ) )
  26.         elseif sec > 0  then table.insert( results, sec .. ( sec == 1 and "" or "" ) ) end
  27.        
  28.         return string.reverse ( table.concat ( results, " : " ):reverse():gsub(" : ", " : ", 1 ) )
  29.     end
  30.     return ""
  31. end
  32.  
  33. addEventHandler( "onClientRestore", getRootElement(),
  34.     function ()
  35.         setElementData (getLocalPlayer(),"p:afk",false)
  36.         sec = 0
  37.         if isTimer (StartTimer) then
  38.             killTimer(StartTimer)
  39.         end
  40.     end
  41. )
  42.  
  43. addEventHandler( "onClientMinimize", getRootElement(),
  44.     function ()
  45.         setElementData (getLocalPlayer(),"p:afk",true)
  46.         if getElementData (getLocalPlayer(),"p:afk") then  
  47.             StartTimer = setTimer(Timer,1000,0)
  48.         end
  49.     end
  50. )
  51. addEventHandler( "onClientResourceStart", getResourceRootElement(),
  52.     function ()
  53.         if getElementData (getLocalPlayer(),"p:afk") then  
  54.             StartTimer = setTimer(Timer,1000,0)
  55.         else
  56.             sec = 0
  57.             if isTimer (StartTimer) then
  58.                 killTimer(StartTimer)
  59.             end
  60.         end
  61.     end
  62. )
  63.  
  64. function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI )
  65.     if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then
  66.         return false
  67.     end
  68.  
  69.     local function clamp( val, lower, upper )
  70.         if ( lower > upper ) then lower, upper = upper, lower end
  71.         return math.max( lower, math.min( upper, val ) )
  72.     end
  73.  
  74.     radius = type( radius ) == "number" and radius or 50
  75.     width = type( width ) == "number" and width or 5
  76.     angleAmount = type( angleAmount ) == "number" and angleAmount or 1
  77.     startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 )
  78.     stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 )
  79.     color = color or tocolor( 255, 255, 255, 200 )
  80.     postGUI = type( postGUI ) == "boolean" and postGUI or false
  81.  
  82.     if ( stopAngle < startAngle ) then
  83.         local tempAngle = stopAngle
  84.         stopAngle = startAngle
  85.         startAngle = tempAngle
  86.     end
  87.  
  88.     for i = startAngle, stopAngle, angleAmount do
  89.         local startX = math.cos( math.rad( i ) ) * ( radius - width )
  90.         local startY = math.sin( math.rad( i ) ) * ( radius - width )
  91.         local endX = math.cos( math.rad( i ) ) * ( radius + width )
  92.         local endY = math.sin( math.rad( i ) ) * ( radius + width )
  93.  
  94.         dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI )
  95.     end
  96.  
  97.     return true
  98. end
Add Comment
Please, Sign In to add comment